如何使用NLP Java提取主题动词对象?每句话

我想为每个句子找到一个主语,动词和宾语,然后将其传递给自然语言生成库 simpleNLG 以构成一个句子。

>

我尝试了多个库,例如 Cornlp,opennlp,Standford解析器。但是我找不到它们。

现在在最坏的情况下,我将不得不编写一整套if-else来从每个句子中找到主语,动词和宾语,这对于simpleNLG并不总是准确的

喜欢

  • NN,nsub等用于主语,VB,VBZ用于动词。

我尝试了词法分析器

LexicalizedParser lp = **new LexicalizedParser("englishPCFG.ser.gz");**
String[] sent = { "This","is","an","easy","sentence","." };
Tree parse = (Tree) lp.apply(Arrays.asList(sent));
parse.pennPrint();
System.out.println();
TreePrint tp = new TreePrint("penn,typedDependenciesCollapsed");
tp.print(parse);

提供此输出,

nsubj(use-2,I-1)
root(ROOT-0,use-2)
det(parser-4,a-3)
dobj(use-2,parser-4)

我想要这样的东西

subject = I
verb = use
det = a
object = parser

是否有更简单的方法可以在JAVA中找到它?还是应该使用if-else?请帮助我。

fenchong520 回答:如何使用NLP Java提取主题动词对象?每句话

您可以使用openie注释器获取三元组。您可以在命令行上运行此命令,也可以使用这些注释器构建管道。

命令:

java -Xmx10g edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,ner,depparse,natlog,openie -file example.txt

Java:

Properties props = new Properties();
props.setProperty("annotators","tokenize,openie");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
Annotation result = pipeline.process("..."); 

输入:

Joe ate some pizza.

输出:

Extracted the following Open IE triples:
1.0     Joe     ate     pizza

此处有更多详细信息:https://stanfordnlp.github.io/CoreNLP/openie.html

本文链接:https://www.f2er.com/2477929.html

大家都在问