max = in.getIndex() > max ? in.getIndex() : max;
}
TwoDimensionalMap<Integer, Integer, IndexedWord> nodes = TwoDimensionalMap.hashMap();
for(CoreNLPProtos.DependencyGraph.Node in: proto.getNodeList()){
CoreLabel token = sentence.get(in.getIndex() - 1); // index starts at 1!
IndexedWord word;
if (in.hasCopyAnnotation() && in.getCopyAnnotation() > 0) {
// TODO: if we make a copy wrapper CoreLabel, use it here instead
word = new IndexedWord(new CoreLabel(token));
word.set(CopyAnnotation.class, in.getCopyAnnotation());
} else {
word = new IndexedWord(token);
}
// for backwards compatibility - new annotations should have
// these fields set, but annotations older than August 2014 might not
if (word.docID() == null && docid != null) {
word.setDocID(docid);
}
if (word.sentIndex() < 0 && in.getSentenceIndex() >= 0) {
word.setSentIndex(in.getSentenceIndex());
}
if (word.index() < 0 && in.getIndex() >= 0) {
word.setIndex(in.getIndex());
}
assert in.getIndex() == word.index();
nodes.put(in.getIndex(), in.getCopyAnnotation(), word);
graph.addVertex(word);
}
// add all edges to the actual graph
for(CoreNLPProtos.DependencyGraph.Edge ie: proto.getEdgeList()){
IndexedWord source = nodes.get(ie.getSource(), ie.getSourceCopy());
assert(source != null);
IndexedWord target = nodes.get(ie.getTarget(), ie.getTargetCopy());
assert(target != null);
synchronized (globalLock) {
// this is not thread-safe: there are static fields in GrammaticalRelation
assert ie.hasDep();
GrammaticalRelation rel = GrammaticalRelation.valueOf(ie.getDep(), fromProto(ie.getLanguage()));