首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何获得依赖解析输出与在线演示完全相同?

如何获得依赖解析输出与在线演示完全相同?
EN

Stack Overflow用户
提问于 2015-01-09 17:19:27
回答 1查看 3.9K关注 0票数 5

如何以编程方式使用stanford获得与在线演示中相同的依赖解析?

我正在使用corenlp包来获得下面句子的依赖解析。

在德克萨斯州的第二名医护人员检测出埃博拉病毒呈阳性,当局说。

我尝试使用下面的代码以编程方式获得解析

代码语言:javascript
复制
            Properties props = new Properties();
            props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
            StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

            String text = "Second healthcare worker in Texas tests positive for Ebola , authorities say ."; // Add your text here!
            Annotation document = new Annotation(text);
            pipeline.annotate(document);
            String[] myStringArray = {"SentencesAnnotation"};
            List<CoreMap> sentences = document.get(SentencesAnnotation.class);
            for(CoreMap sentence: sentences) {
                SemanticGraph dependencies = sentence.get(BasicDependenciesAnnotation.class);
                IndexedWord root = dependencies.getFirstRoot();
                System.out.printf("root(ROOT-0, %s-%d)%n", root.word(), root.index());
                for (SemanticGraphEdge e : dependencies.edgeIterable()) {
                    System.out.printf ("%s(%s-%d, %s-%d)%n", e.getRelation().toString(), e.getGovernor().word(), e.getGovernor().index(), e.getDependent().word(), e.getDependent().index());
                }
            }

    }

我使用Stanfordcorenlp3.5.0包获得以下输出。

代码语言:javascript
复制
root(ROOT-0, worker-3)
amod(worker-3, Second-1)
nn(worker-3, healthcare-2)
prep(worker-3, in-4)
amod(worker-3, positive-7)
dep(worker-3, say-12)
pobj(in-4, tests-6)
nn(tests-6, Texas-5)
prep(positive-7, for-8)
pobj(for-8, ebola-9)
nsubj(say-12, authorities-11)

但是在线演示给出了一个不同的答案,标记为根,并且在解析中的单词之间还有其他关系,比如ccomp。

代码语言:javascript
复制
amod(worker-3, Second-1)
nn(worker-3, healthcare-2)
nsubj(tests-6, worker-3)
prep(worker-3, in-4)
pobj(in-4, Texas-5)
ccomp(say-12, tests-6)
acomp(tests-6, positive-7)
prep(positive-7, for-8)
pobj(for-8, Ebola-9)
nsubj(say-12, authorities-11)
root(ROOT-0, say-12)

如何解决我的输出与在线演示匹配?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-10 22:42:04

产生不同输出的原因是,如果使用解析器演示,则使用独立的解析器发行版,代码使用整个CoreNLP发行版。虽然它们都使用相同的解析器和相同的模型,但CoreNLP的默认配置在运行解析器之前运行一个词性部分标记器,并且解析器合并了词性信息,在某些情况下可能导致不同的结果。

为了获得相同的结果,您可以通过更改注解器列表来禁用POS标签:

代码语言:javascript
复制
props.put("annotators", "tokenize, ssplit, parse, lemma, ner, dcoref");

但是,请注意,引理、ner和dcoref注解器都需要POS标记,因此您必须更改注解器的顺序。

还有一个CoreNLP演示,它总是产生与您的代码相同的输出。

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27865825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档