我试图根据http://nlp.stanford.edu/downloads/corenlp.shtml中的说明在Stanford CoreNLP中添加新的注释器。

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

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

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


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

最佳答案

如果愿意,可以有我的。有趣的东西始于// 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;
}

09-20 08:18