Skip to content

Commit

Permalink
Use the EmptyIndex fields in the DependencyGraph proto to build a Sem…
Browse files Browse the repository at this point in the history
…anticGraph with the fake nodes used in UD
  • Loading branch information
AngledLuffa committed Oct 14, 2023
1 parent 5fa193a commit ede0543
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2390,7 +2390,6 @@ private static SemanticGraph fromProto(CoreNLPProtos.DependencyGraph proto, List
max = in.getIndex() > max ? in.getIndex() : max;
}
// map from index, emptyIndex, copy -> IndexedWord
// TODO: still need to add the empty index to the proto, then use it here to build the graph
ThreeDimensionalMap<Integer, Integer, Integer, IndexedWord> nodes = new ThreeDimensionalMap<>();
// map from index, emptyIndex -> CoreLabel
TwoDimensionalMap<Integer, Integer, CoreLabel> originalLabels = TwoDimensionalMap.hashMap();
Expand All @@ -2416,8 +2415,7 @@ private static SemanticGraph fromProto(CoreNLPProtos.DependencyGraph proto, List
if (document.isPresent()) {
token = document.get().get(SentencesAnnotation.class).get(in.getSentenceIndex()).get(TokensAnnotation.class).get(in.getIndex() - 1); // token index starts at 1!
} else {
// TODO: index based on emptyIndex as well
token = originalLabels.get(in.getIndex(), 0);
token = originalLabels.get(in.getIndex(), in.getEmptyIndex());
if (token == null) {
throw new NullPointerException("Could not find the token for index " + in.getIndex());
}
Expand Down Expand Up @@ -2449,12 +2447,11 @@ private static SemanticGraph fromProto(CoreNLPProtos.DependencyGraph proto, List

// add all edges to the actual graph
for(CoreNLPProtos.DependencyGraph.Edge ie: proto.getEdgeList()){
// TODO: source and target should index on emptyIndex as well
IndexedWord source = nodes.get(ie.getSource(), 0, ie.getSourceCopy());
IndexedWord source = nodes.get(ie.getSource(), ie.getSourceEmpty(), ie.getSourceCopy());
if (source == null) {
throw new AssertionError("Source of a dependency was null! Edge: " + ie);
}
IndexedWord target = nodes.get(ie.getTarget(), 0, ie.getTargetCopy());
IndexedWord target = nodes.get(ie.getTarget(), ie.getTargetEmpty(), ie.getTargetCopy());
if (target == null) {
throw new AssertionError("Target of a dependency was null! Edge: " + ie);
}
Expand Down

0 comments on commit ede0543

Please sign in to comment.