Search code examples
dependenciesrootstanford-nlp

Stanford Core NLP Parse tree without a root


I'm using Stanford CoreNLP for getting dependency trees of sentences. The problem that I came accross is, for some of the sentences, the tree does not have a root node. Is this possible?

Here, there is a similar example in which the problem is detected to be with the print method (i.e. there is a root, but somehow it is not being printed).

However, in my case, the sentence does not have a root at all. Here is the test sentence that I have: "(Wendigo is) why we go to the cinema : to be fed through the eye , the heart , the mind ."

I'm printing the dependencies using the following code:

SemanticGraph dependencies = sentence.get(CollapsedCCProcessedDependenciesAnnotation.class);
out.println(dependencies.toString("plain"));

and here is the output:

nsubj(-RRB--4, Wendigo-2)
cop(-RRB--4, is-3)
advmod(go-7, why-5)
nsubj(go-7, we-6)
advcl(-RRB--4, go-7)
det(cinema-10, the-9)
prep_to(go-7, cinema-10)
aux(fed-14, to-12)
auxpass(fed-14, be-13)
parataxis(go-7, fed-14)
det(eye-17, the-16)
prep_through(fed-14, eye-17)
det(heart-20, the-19)
appos(eye-17, heart-20)
det(mind-23, the-22)
appos(heart-20, mind-23)

Once I try to print the root node manually, using the following code:

IndexedWord root = dependencies.getFirstRoot();
out.printf("ROOT(root-0, %s-%d)%n", root.word(), root.index());

I get the following error message:

Exception in thread "main" java.lang.RuntimeException: No roots in graph:
dep                 reln                gov                 
---                 ----                ---                 
Wendigo-2           nsubj               -RRB--4             
is-3                cop                 -RRB--4             
why-5               advmod              go-7                
we-6                nsubj               go-7                
go-7                advcl               -RRB--4             
the-9               det                 cinema-10           
cinema-10           prep_to             go-7                
to-12               aux                 fed-14              
be-13               auxpass             fed-14              
fed-14              parataxis           go-7                
the-16              det                 eye-17              
eye-17              prep_through        fed-14              
the-19              det                 heart-20            
heart-20            appos               eye-17              
the-22              det                 mind-23             
mind-23             appos               heart-20            

Find where this graph was created and make sure you're adding roots.

The questions are:

  1. Do every sentence has to have a root node in its dependency tree?
  2. Can a sentence have more than one root node? If yes, how is it going to be a tree then?

Thanks,


Solution

  • It looks like this was a bug caused by the parser wrongly generating an adjective phrase constituent which only contained the right parenthesis, which sent the dependencies haywire (the right parenthesis became a governor, but was then deleted as punctuation).

    Someone seems to have fixed this already. The current version (in github) gives the dependencies below. So, the new version that we're releasing this week (Apr 2015) should hopefully fix things for you....

    root(ROOT-0, is-3)
    nsubj(is-3, Wendigo-2)
    advmod(go-7, why-5)
    nsubj(go-7, we-6)
    advcl(is-3, go-7)
    case(cinema-10, to-8)
    det(cinema-10, the-9)
    nmod:to(go-7, cinema-10)
    mark(fed-14, to-12)
    auxpass(fed-14, be-13)
    parataxis(go-7, fed-14)
    case(eye-17, through-15)
    det(eye-17, the-16)
    nmod:through(fed-14, eye-17)
    det(heart-20, the-19)
    appos(eye-17, heart-20)
    det(mind-23, the-22)
    appos(heart-20, mind-23)