iNikkz
iNikkz

Reputation: 3819

Create TreeAnnotation Parser on sentence (String) in Stanford CoreNLP Java

I want to use TreeAnnotation.class of Stanford CoreNLP. I have the code how to do it.

My issue is different.

I have my own sentences that are String. I converted those sentences into List Class. At the time of casting, I set almost all annotations like, Token, BeginPosition, EndPosition etc but I don't know how to set TreeAnnotation.class on my own type casted sentences.

If anybody knows how to create/set TreeAnnotation Parser using custom List<CoreMap> sentences.

OR

How can I directly build TreeAnnotation Parser on String sentences without doing type casting them into List ? It will be more helpful for me. Any help ?

Upvotes: 0

Views: 367

Answers (1)

Gha93
Gha93

Reputation: 155

If you have the parse tree of the sentence you can do it like that:

Annotation sentence = new Annotation ("your sentence");
sentence.set(CoreAnnotations.TokensAnnotation.class, sentenceTokens);// the token list
String t = "(S (NP ... ))";// your tree
TreeReader r = new PennTreeReader(new StringReader(t));
Tree tree = r.readTree();
sentence.set(TreeCoreAnnotations.TreeAnnotation.class, tree);

Upvotes: 1

Related Questions