@@ -516,20 +516,35 @@ public CoreMap convertCoNLLUSentenceToCoreMap(CoNLLUDocument doc, CoNLLUSentence
516516 emptyLabels .add (cl );
517517 }
518518
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
520532 List <SemanticGraphEdge > graphEdges = new ArrayList <>();
521533 for (int i = 0 ; i < lines .size (); i ++) {
522534 List <String > fields = Arrays .asList (lines .get (i ).split ("\t " ));
523535 // skip the ROOT node
524536 if (fields .get (CoNLLU_GovField ).equals ("0" ))
525537 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 ));
528540 GrammaticalRelation reln = GrammaticalRelation .valueOf (fields .get (CoNLLU_RelnField ));
529541 graphEdges .add (new SemanticGraphEdge (gov , dependent , reln , 1.0 , false ));
530542 }
531543 // build SemanticGraph
532544 SemanticGraph depParse = SemanticGraphFactory .makeFromEdges (graphEdges );
545+
546+ // TODO: here we build the enhanced graph, if it exists
547+
533548 // build sentence CoreMap with full text
534549 Annotation sentenceCoreMap = new Annotation (doc .docText .substring (sentenceCharBegin ).trim ());
535550 // add tokens
0 commit comments