2017-02-24 46 views
0

如果我使用TokenizerAnnotator,WordsToSentencesAnnotator,POSTaggerAnnotator和sutime創建AnnotationPipeline,則會將TimexAnnotations附加到生成的註釋中。使用StanfordCoreNLP管道的日期

但是,如果我創建了一個StanfordCoreNLP管道的「註釋」屬性設置爲「記號化,SSPLIT,POS,引理,淨入學率」,我沒有得到TimexAnnotations即使有關個人令牌是NER標記爲DATE。

爲什麼會有這種差異?

回答

0

當我運行此命令:

java -Xmx8g edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,ner -file data-example.txt -outputFormat text 

我得到的日期TIMEX註釋。 ner註釋器應該默認應用SUTime。

+0

祕密註釋器當然應用了SUTime,因爲這些代幣具有NamedEntityTag = DATE。但是從pipeline.annotate返回的Annotation沒有TimexAnnotations。 –

+0

爲了明確起見,這段代碼打印出null: Properties props = new Properties(); propssetProperty(「annotators」,「tokenize,ssplit,pos,lemma,ner」); AnnotationPipeline pipeline = new StanfordCoreNLP(道具); 註釋註釋=新註釋(「日期爲2017年4月1日」); pipeline.annotate(annotation); System.out.println(annotation.get(TimeAnnotations.TimexAnnotations.class)); –

0

當我們運行註釋時,我們從文檔中提取所有實體提及,並且我們認爲DATE是實體提及。這裏是一些示例代碼。如果您只是想提取時間表達式並且希望填充TimexAnnotations.class字段,我已經添加了一些註釋掉的選項。

package edu.stanford.nlp.examples; 

import edu.stanford.nlp.ling.*; 
import edu.stanford.nlp.util.*; 
import edu.stanford.nlp.time.TimeAnnotations; 

import edu.stanford.nlp.pipeline.*; 

import java.util.*; 

public class SUTimeExample { 

    public static void main(String[] args) { 
    Annotation document = 
     new Annotation("The date is 1 April 2017"); 
    Properties props = new Properties(); 
    //props.setProperty("customAnnotatorClass.time", "edu.stanford.nlp.time.TimeAnnotator"); 
    //props.setProperty("annotators", "tokenize,ssplit,pos,lemma,time"); 
    props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,entitymentions"); 
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 
    pipeline.annotate(document); 
    for (CoreMap entityMention : document.get(CoreAnnotations.MentionsAnnotation.class)) { 
     if (entityMention.get(CoreAnnotations.EntityTypeAnnotation.class).equals("DATE")) 
     System.out.println(entityMention); 
    } 
    } 
}