Skip to content

Commit

Permalink
Move the EmptyIndex into the CoreLabel, as that may be the easiest wa…
Browse files Browse the repository at this point in the history
…y to pass it from Python to Java in the Semgrex interface
  • Loading branch information
AngledLuffa committed Oct 13, 2023
1 parent 4e37213 commit 7c53fb4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
30 changes: 30 additions & 0 deletions src/edu/stanford/nlp/ling/CoreLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
12 changes: 6 additions & 6 deletions src/edu/stanford/nlp/ling/IndexedWord.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 7c53fb4

Please sign in to comment.