From 7c53fb46d8c78d9a4c35964a792ff9f17d35eb85 Mon Sep 17 00:00:00 2001 From: John Bauer Date: Thu, 12 Oct 2023 21:38:08 -0700 Subject: [PATCH] Move the EmptyIndex into the CoreLabel, as that may be the easiest way to pass it from Python to Java in the Semgrex interface --- src/edu/stanford/nlp/ling/CoreLabel.java | 30 ++++++++++++++++++++++ src/edu/stanford/nlp/ling/IndexedWord.java | 12 ++++----- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/edu/stanford/nlp/ling/CoreLabel.java b/src/edu/stanford/nlp/ling/CoreLabel.java index bbad7791fa..4710c027ef 100644 --- a/src/edu/stanford/nlp/ling/CoreLabel.java +++ b/src/edu/stanford/nlp/ling/CoreLabel.java @@ -606,6 +606,36 @@ public void setIndex(int index) { set(CoreAnnotations.IndexAnnotation.class, index); } + /** + * Similar to a copy node in IndexedWord, but not exactly, + * as the word can have its own attributes. + * Fairly common in enhanced graphs in UD + */ + public int getEmptyIndex() { + Integer index = get(CoreAnnotations.EmptyIndexAnnotation.class); + if (index == null) { + return 0; + } + return index; + } + + /** + * Similar to a copy node in IndexedWord, but not exactly, + * as the word can have its own attributes. + * Fairly common in enhanced graphs in UD + */ + public void setEmptyIndex(int empty) { + set(CoreAnnotations.EmptyIndexAnnotation.class, empty); + } + + /** + * Keeping track of this can save us a little effort when serializing CoreLabels + */ + public boolean hasEmptyIndex() { + Integer index = get(CoreAnnotations.EmptyIndexAnnotation.class); + return index != null; + } + /** * {@inheritDoc} */ diff --git a/src/edu/stanford/nlp/ling/IndexedWord.java b/src/edu/stanford/nlp/ling/IndexedWord.java index 6f2fffa6b8..f71a22f4a8 100644 --- a/src/edu/stanford/nlp/ling/IndexedWord.java +++ b/src/edu/stanford/nlp/ling/IndexedWord.java @@ -347,15 +347,15 @@ public void setEndPosition(int endPos) { } public void setEmptyIndex(int empty) { - label.set(CoreAnnotations.EmptyIndexAnnotation.class, empty); + label.setEmptyIndex(empty); } public int getEmptyIndex() { - Integer index = label.get(CoreAnnotations.EmptyIndexAnnotation.class); - if (index == null) { - return 0; - } - return index; + return label.getEmptyIndex(); + } + + public boolean hasEmptyIndex() { + return label.hasEmptyIndex(); } public int copyCount() {