2013-11-09 22 views
0

我想根據http://nlp.stanford.edu/downloads/corenlp.shtml中的說明在斯坦福大學CoreNLP中添加一個新的註釋器。在斯坦福大學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"); 

有沒有任何示例代碼可以幫助我?

回答

2

如果你喜歡,你可以有我的。有趣的東西開始於// 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; 
} 
+0

你是如何創建你的註釋器? – Tariq

+0

您能否詳細介紹爲斯坦福大學CoreNLP創建自定義註釋器的過程/步驟?謝謝 – Tariq

+0

如果你四年前問過我,我可能會提供幫助。但我的代碼仍然在線。也許你想檢查一下:https://svn.ipd.kit.edu/trac/AliceNLP/browser/ivan/trunk/src/main/java/edu/kit/ipd/alicenlp/ivan/analyzers/StaticDynamicClassifier。 java的 –