简体   繁体   English

在Stanford CoreNLP Java中的句子(字符串)上创建TreeAnnotation解析器

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

I want to use TreeAnnotation.class of Stanford CoreNLP . 我想用斯坦福CoreNLPTreeAnnotation.class。 I have the code how to do it. 我有代码该怎么做。

My issue is different.

I have my own sentences that are String . 我有我自己String 句子 I converted those sentences into List Class . 我将这些句子转换为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. 在进行转换时,我几乎设置了所有注释,例如Token,BeginPosition,EndPosition等,但是我知道如何在自己的类型转换语句中设置TreeAnnotation.class

If anybody knows how to create/set TreeAnnotation Parser using custom List<CoreMap> sentences . 如果有人知道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 ? 如何在不将 类型强制转换为List的 情况下直接在String语句上构建TreeAnnotation Parser It will be more helpful for me. 这对我会更有帮助。 Any help ? 有什么帮助吗?

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM