@@ -554,26 +554,29 @@ public CoreMap convertCoNLLUSentenceToCoreMap(CoNLLUDocument doc, CoNLLUSentence
554554 boolean hasEnhanced = false ;
555555 // build SemanticGraphEdges for a basic graph
556556 List <SemanticGraphEdge > graphEdges = new ArrayList <>();
557+ List <IndexedWord > graphRoots = new ArrayList <>();
557558 for (int i = 0 ; i < lines .size (); i ++) {
558559 List <String > fields = Arrays .asList (lines .get (i ).split ("\t " ));
559560 // track whether any of these lines signify there is an enhanced graph
560561 hasEnhanced = hasEnhanced || !fields .get (CoNLLU_EnhancedField ).equals ("_" );
561- // skip the ROOT node
562- if (fields .get (CoNLLU_GovField ).equals ("0" ))
563- continue ;
564562 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+ }
568571 }
569572 // build SemanticGraph
570- SemanticGraph depParse = SemanticGraphFactory .makeFromEdges (graphEdges );
573+ SemanticGraph depParse = SemanticGraphFactory .makeFromEdges (graphEdges , graphRoots );
571574 // add dependency graph
572575 sentenceCoreMap .set (SemanticGraphCoreAnnotations .BasicDependenciesAnnotation .class , depParse );
573576
574577 if (hasEnhanced ) {
575578 List <SemanticGraphEdge > enhancedEdges = new ArrayList <>();
576- List <IndexedWord > roots = new ArrayList <>();
579+ List <IndexedWord > enhancedRoots = new ArrayList <>();
577580
578581 List <String > allLines = new ArrayList <>();
579582 allLines .addAll (lines );
@@ -585,16 +588,15 @@ public CoreMap convertCoNLLUSentenceToCoreMap(CoNLLUDocument doc, CoNLLUSentence
585588 for (String arc : arcs ) {
586589 String [] arcPieces = arc .split (":" , 2 );
587590 if (arcPieces [0 ].equals ("0" )) {
588- roots .add (dependent );
591+ enhancedRoots .add (dependent );
589592 } else {
590593 IndexedWord gov = graphNodes .get (arcPieces [0 ]);
591594 GrammaticalRelation reln = GrammaticalRelation .valueOf (arcPieces [1 ]);
592595 enhancedEdges .add (new SemanticGraphEdge (gov , dependent , reln , 1.0 , false ));
593596 }
594597 }
595598 }
596- SemanticGraph enhancedParse = SemanticGraphFactory .makeFromEdges (enhancedEdges );
597- enhancedParse .setRoots (roots );
599+ SemanticGraph enhancedParse = SemanticGraphFactory .makeFromEdges (enhancedEdges , enhancedRoots );
598600 sentenceCoreMap .set (SemanticGraphCoreAnnotations .EnhancedDependenciesAnnotation .class , enhancedParse );
599601 }
600602
0 commit comments