當我們運行註釋時,我們從文檔中提取所有實體提及,並且我們認爲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);
}
}
}
祕密註釋器當然應用了SUTime,因爲這些代幣具有NamedEntityTag = DATE。但是從pipeline.annotate返回的Annotation沒有TimexAnnotations。 –
爲了明確起見,這段代碼打印出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)); –