首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NLP -我能找出“它”是谁吗?

NLP -我能找出“它”是谁吗?
EN

Stack Overflow用户
提问于 2014-04-28 19:02:30
回答 3查看 113关注 0票数 0

我正在使用Stanford Parser从文本中逐句获取依赖关系,如下所示:

代码语言:javascript
复制
    Reader reader = new StringReader("The room was not nice. It was bright, but cold.");
    TreebankLanguagePack tlp = new PennTreebankLanguagePack();
    GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();

    // the dependencies of the entire text
    List<TypedDependency> textDependencies = new ArrayList<TypedDependency>();
    // get the dependencies of each sentence and add it to the list
    for (List<HasWord> sentence : new DocumentPreprocessor(reader)) {
        Tree parse = lp.apply(sentence);
        GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);
        textDependencies.addAll(gs.typedDependenciesCCprocessed());
    }

运行上面的代码后,名为textDependencies的列表将包含以下依赖项:

代码语言:javascript
复制
    det(room-2, The-1)
    nsubj(nice-5, room-2)
    cop(nice-5, was-3)
    neg(nice-5, not-4)
    root(ROOT-0, nice-5)
    nsubj(warm-3, It-1)
    nsubj(noisy-6, It-1)
    cop(warm-3, was-2)
    root(ROOT-0, warm-3)
    conj_but(warm-3, noisy-6)

有没有办法找出谁是“它”,得到一些东西,表明它实际上是房间?

EN

回答 3

Stack Overflow用户

发布于 2014-04-28 20:27:27

你想要的是共指消解。斯坦福大学CoreNLP does that already。我找不到以编程方式完成的演示,但如果您正在运行预编译的可执行文件,则需要将dcoref添加到注释器列表中,如下所示:

代码语言:javascript
复制
java -cp <all jars> edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,ner,parse,dcoref -file input.txt
票数 1
EN

Stack Overflow用户

发布于 2014-05-08 17:47:46

下面是斯坦福CoreNLP共指解析的Java代码示例(根据mbatchkarov的建议):

代码语言:javascript
复制
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import edu.stanford.nlp.dcoref.CorefChain;
import edu.stanford.nlp.dcoref.CorefChain.CorefMention;
import edu.stanford.nlp.dcoref.CorefCoreAnnotations.CorefChainAnnotation;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;

public class StanfordExample {

protected StanfordCoreNLP pipeline;

public StanfordExample() {

    Properties props;
    props = new Properties();
    props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");

    this.pipeline = new StanfordCoreNLP(props);
}

public void getCoref(String documentText)
{
    Annotation document = new Annotation(documentText);
    this.pipeline.annotate(document);
    Map<Integer, CorefChain> sentences = document.get(CorefChainAnnotation.class);
    for(CorefChain chain : sentences.values()) 
    {
        List<CorefMention> mentionsInTextualOrder = chain.getMentionsInTextualOrder();
        for (CorefMention corefMention : mentionsInTextualOrder)
        {
            System.out.println(corefMention.toString());
        }
    }
}


public static void main(String[] args) {
    String text = "The room was not nice. It was bright, but cold.";
    StanfordExample slem = new StanfordExample();
    slem.getCoref(text);
}

}
票数 0
EN

Stack Overflow用户

发布于 2014-07-15 15:40:08

在下载的CoreNLP中使用StanfordCoreNlpDemo.java

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

https://stackoverflow.com/questions/23339388

复制
相关文章

相似问题

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