stanford-nlp - 如何使用 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 吗?请帮帮我。
解决方案
您可以使用openie
注释器来获取三元组。您可以在命令行运行它或使用这些注释器构建管道。
命令:
java -Xmx10g edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,ner,depparse,natlog,openie -file example.txt
爪哇:
Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,depparse,natlog,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
推荐阅读
- inno-setup - 为什么我们在 Inno Setup 的 ExtractTemporaryFiles 函数中指定路径?
- c# - 使用 TcpListener C# 获取客户端的公共 IP 地址
- sql - 如何从 SQL 查询中排除一个特定日期?
- python - 在python中如何从一列中捕获一个值并显示在同一csv的另一列中
- python - 如何解决 NameError:名称“urllib2”未在 Python 3.7 中定义
- java - Java 本机内存使用量与使用的总虚拟内存不匹配
- flutter - 在 Flutter 中,如何让用户选择的下拉菜单选项指向特定的路由?
- python - python脚本绘制所选股票的图表
- java - 如何从(相同)arraylist 中获取两种不同类型的对象,然后将它们存储在数据库中的两个不同表中
- java - 当我旋转屏幕时,片段被销毁并返回给 Activity,它打开了那个片段。但他为什么要这样做?