@@ -554,26 +554,29 @@ public CoreMap convertCoNLLUSentenceToCoreMap(CoNLLUDocument doc, CoNLLUSentence
554
554
boolean hasEnhanced = false ;
555
555
// build SemanticGraphEdges for a basic graph
556
556
List <SemanticGraphEdge > graphEdges = new ArrayList <>();
557
+ List <IndexedWord > graphRoots = new ArrayList <>();
557
558
for (int i = 0 ; i < lines .size (); i ++) {
558
559
List <String > fields = Arrays .asList (lines .get (i ).split ("\t " ));
559
560
// track whether any of these lines signify there is an enhanced graph
560
561
hasEnhanced = hasEnhanced || !fields .get (CoNLLU_EnhancedField ).equals ("_" );
561
- // skip the ROOT node
562
- if (fields .get (CoNLLU_GovField ).equals ("0" ))
563
- continue ;
564
562
IndexedWord dependent = graphNodes .get (fields .get (CoNLLU_IndexField ));
565
- IndexedWord gov = graphNodes .get (fields .get (CoNLLU_GovField ));
566
- GrammaticalRelation reln = GrammaticalRelation .valueOf (fields .get (CoNLLU_RelnField ));
567
- graphEdges .add (new SemanticGraphEdge (gov , dependent , reln , 1.0 , false ));
563
+ if (fields .get (CoNLLU_GovField ).equals ("0" )) {
564
+ // no edges for the ROOT node
565
+ graphRoots .add (dependent );
566
+ } else {
567
+ IndexedWord gov = graphNodes .get (fields .get (CoNLLU_GovField ));
568
+ GrammaticalRelation reln = GrammaticalRelation .valueOf (fields .get (CoNLLU_RelnField ));
569
+ graphEdges .add (new SemanticGraphEdge (gov , dependent , reln , 1.0 , false ));
570
+ }
568
571
}
569
572
// build SemanticGraph
570
- SemanticGraph depParse = SemanticGraphFactory .makeFromEdges (graphEdges );
573
+ SemanticGraph depParse = SemanticGraphFactory .makeFromEdges (graphEdges , graphRoots );
571
574
// add dependency graph
572
575
sentenceCoreMap .set (SemanticGraphCoreAnnotations .BasicDependenciesAnnotation .class , depParse );
573
576
574
577
if (hasEnhanced ) {
575
578
List <SemanticGraphEdge > enhancedEdges = new ArrayList <>();
576
- List <IndexedWord > roots = new ArrayList <>();
579
+ List <IndexedWord > enhancedRoots = new ArrayList <>();
577
580
578
581
List <String > allLines = new ArrayList <>();
579
582
allLines .addAll (lines );
@@ -585,16 +588,15 @@ public CoreMap convertCoNLLUSentenceToCoreMap(CoNLLUDocument doc, CoNLLUSentence
585
588
for (String arc : arcs ) {
586
589
String [] arcPieces = arc .split (":" , 2 );
587
590
if (arcPieces [0 ].equals ("0" )) {
588
- roots .add (dependent );
591
+ enhancedRoots .add (dependent );
589
592
} else {
590
593
IndexedWord gov = graphNodes .get (arcPieces [0 ]);
591
594
GrammaticalRelation reln = GrammaticalRelation .valueOf (arcPieces [1 ]);
592
595
enhancedEdges .add (new SemanticGraphEdge (gov , dependent , reln , 1.0 , false ));
593
596
}
594
597
}
595
598
}
596
- SemanticGraph enhancedParse = SemanticGraphFactory .makeFromEdges (enhancedEdges );
597
- enhancedParse .setRoots (roots );
599
+ SemanticGraph enhancedParse = SemanticGraphFactory .makeFromEdges (enhancedEdges , enhancedRoots );
598
600
sentenceCoreMap .set (SemanticGraphCoreAnnotations .EnhancedDependenciesAnnotation .class , enhancedParse );
599
601
}
600
602
0 commit comments