在斯坦福 CoreNLP 中添加新的注释器 [英] Adding a new annotator in Stanford CoreNLP

查看:29
本文介绍了在斯坦福 CoreNLP 中添加新的注释器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据 http://中的说明在斯坦福 CoreNLP 中添加一个新的注释器nlp.stanford.edu/downloads/corenlp.shtml.

"添加新的注释器StanfordCoreNLP 还可以通过反射添加新的注释器,而无需更改 StanfordCoreNLP.java 中的代码.要创建新的注释器,请扩展类 edu.stanford.nlp.pipeline.Annotator 并定义具有签名(字符串、属性)的构造函数.然后,将属性 customAnnotatorClass.FOO=BAR 添加到用于创建管道的属性.如果随后将 FOO 添加到注释器列表中,则将创建类 BAR,其中包含用于创建它的名称和传入的属性文件."

"Adding a new annotator StanfordCoreNLP also has the capacity to add a new annotator by reflection without altering the code in StanfordCoreNLP.java. To create a new annotator, extend the class edu.stanford.nlp.pipeline.Annotator and define a constructor with the signature (String, Properties). Then, add the property customAnnotatorClass.FOO=BAR to the properties used to create the pipeline. If FOO is then added to the list of annotators, the class BAR will be created, with the name used to create it and the properties file passed in. "

我为我的新注释器创建了一个新类,但我无法放置要传入的属性文件.我只将新的注释器放入管道中.

I have created a new class for my new annotator, but i cannot put the properties file that would pass in. I have only put the new annotator in the pipeline.

props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref, regexner, color");
props.setProperty("customAnnotatorClass.color", "myPackage.myPipeline");

有什么示例代码可以帮助我吗?

Is there any example code to help me?

推荐答案

如果你愿意,你可以拥有我的.有趣的事情从 //添加我们自己的注释器属性开始:

You can have mine, if you like. The interesting stuff starts at // adding our own annotator property:

/** Annotates a document with our customized pipeline.
 * @param text A text to process
 * @return The annotated text
 */
private Annotation annotateText(String text) {
    Annotation doc = new Annotation(text);

    StanfordCoreNLP pipeline;

    // creates a StanfordCoreNLP object, with POS tagging, lemmatization,
    // NER, parsing, and coreference resolution
    Properties props = new Properties();
    // alternative: wsj-bidirectional
    try {
        props.put(
                "pos.model",
                "edu/stanford/nlp/models/pos-tagger/wsj-bidirectional/wsj-0-18-bidirectional-distsim.tagger");
    } catch (Exception e) {
        e.printStackTrace();
    }
    // adding our own annotator property
    props.put("customAnnotatorClass.sdclassifier",
            "edu.kit.ipd.alicenlp.ivan.analyzers.StaticDynamicClassifier");

    // configure pipeline
    props.put(
                "annotators", 
                "tokenize, ssplit, pos, lemma, ner, parse, sdclassifier");
    pipeline = new StanfordCoreNLP(props);

    pipeline.annotate(doc);
    return doc;
}

这篇关于在斯坦福 CoreNLP 中添加新的注释器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆