Give the following sentence:
My dog also likes eating sausage.
The online demo produces the following relations:
nmod:poss(dog-2, My-1)
nsubj(likes-4, dog-2)
advmod(likes-4, also-3)
root(ROOT-0, likes-4)
xcomp(likes-4, eating-5)
dobj(eating-5, sausage-6)
However, my code, which also uses the universal dependencies (UD), produces something different:
nmod:poss(dog-2, My-1)
nsubj(likes-4, dog-2)
advmod(likes-4, also-3)
root(ROOT-0, likes-4)
amod(sausage-6, eating-5)
dobj(likes-4, sausage-6)
punct(likes-4, .-7)
Here's my code:
String sentence = "My dog also likes eating sausage.";
MaxentTagger tagger = new MaxentTagger("edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger");
DependencyParser parser = DependencyParser.loadFromModelFile("edu/stanford/nlp/models/parser/nndep/english_UD.gz");
DocumentPreprocessor preprocessor = new DocumentPreprocessor(new StringReader(sentence));
for (List<HasWord> s: preprocessor) {
List<TaggedWord> taggedWords = tagger.tagSentence(s);
GrammaticalStructure gs = parser.predict(taggedWords);
for (TypedDependency d: gs.typedDependencies()) {
System.out.println(d);
}
}
Using typedDependenciesCCprocessed
, typedDependenciesCollapsed
, andtypedDependenciesCollapsedTree
will yield the same result.
How do I get the exact same relations as the demo's?
The online demo is using the constituency parser and converting it to dependencies. The code you linked is using the neural net dependency parser. These are expected to be somewhat different. To get the output of the demo, you should run the Stanford Parser: http://nlp.stanford.edu/software/lex-parser.shtml. From CoreNLP, this means running with annotators tokenize,ssplit,parse
.