@@ -516,20 +516,35 @@ public CoreMap convertCoNLLUSentenceToCoreMap(CoNLLUDocument doc, CoNLLUSentence
516
516
emptyLabels .add (cl );
517
517
}
518
518
519
- // build SemanticGraphEdges
519
+ // first, prebuild the IndexedWords that will make up the basic graph
520
+ // (and possibly the enhanced graph)
521
+ Map <String , IndexedWord > graphNodes = new HashMap <>();
522
+ for (CoreLabel label : coreLabels ) {
523
+ String index = Integer .toString (label .index ());
524
+ graphNodes .put (index , new IndexedWord (label ));
525
+ }
526
+ for (CoreLabel empty : emptyLabels ) {
527
+ String index = empty .index () + "." + empty .get (CoreAnnotations .EmptyIndexAnnotation .class );
528
+ graphNodes .put (index , new IndexedWord (empty ));
529
+ }
530
+
531
+ // build SemanticGraphEdges for a basic graph
520
532
List <SemanticGraphEdge > graphEdges = new ArrayList <>();
521
533
for (int i = 0 ; i < lines .size (); i ++) {
522
534
List <String > fields = Arrays .asList (lines .get (i ).split ("\t " ));
523
535
// skip the ROOT node
524
536
if (fields .get (CoNLLU_GovField ).equals ("0" ))
525
537
continue ;
526
- IndexedWord dependent = new IndexedWord ( coreLabels .get (i ));
527
- IndexedWord gov = new IndexedWord ( coreLabels .get (Integer . parseInt ( fields .get (CoNLLU_GovField )) - 1 ));
538
+ IndexedWord dependent = graphNodes . get ( fields .get (CoNLLU_IndexField ));
539
+ IndexedWord gov = graphNodes .get (fields .get (CoNLLU_GovField ));
528
540
GrammaticalRelation reln = GrammaticalRelation .valueOf (fields .get (CoNLLU_RelnField ));
529
541
graphEdges .add (new SemanticGraphEdge (gov , dependent , reln , 1.0 , false ));
530
542
}
531
543
// build SemanticGraph
532
544
SemanticGraph depParse = SemanticGraphFactory .makeFromEdges (graphEdges );
545
+
546
+ // TODO: here we build the enhanced graph, if it exists
547
+
533
548
// build sentence CoreMap with full text
534
549
Annotation sentenceCoreMap = new Annotation (doc .docText .substring (sentenceCharBegin ).trim ());
535
550
// add tokens
0 commit comments