【问题标题】:Dates when using StanfordCoreNLP pipeline使用 StanfordCoreNLP 管道的日期
【发布时间】:2017-02-24 15:45:47
【问题描述】:

如果我使用 TokenizerAnnotator、WordsToSentencesAnnotator、POSTaggerAnnotator 和 sutime 创建 AnnotationPipeline,我会在生成的注释上附加 TimexAnnotations。

但是,如果我创建了一个将“注释器”属性设置为“tokenize、ssplit、pos、lemma、ner”的 StanfordCoreNLP 管道,即使相关的单个标记被 NER 标记为 DATE,我也不会得到 TimexAnnotations。

为什么会有这种差异?

【问题讨论】:

    标签: java nlp stanford-nlp


    【解决方案1】:

    当我运行这个命令时:

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

    我得到了 DATE 的 TIMEX 注释。 ner 注释器应该默认应用 SUTime。

    【讨论】:

    • ner 注释器肯定在应用 SUTime,因为标记具有 NamedEntityTag=DATE。但是从 pipeline.annotate 返回的 Annotation 没有 TimexAnnotations。
    • 明确地说,这段代码打印空:Properties props = new Properties(); props.setProperty("注释器", "tokenize, ssplit, pos, lemma, ner"); AnnotationPipeline pipeline = new StanfordCoreNLP(props); Annotation annotation = new Annotation("日期为 2017 年 4 月 1 日");管道.注释(注释); System.out.println(annotation.get(TimeAnnotations.TimexAnnotations.class));
    【解决方案2】:

    当我们运行注释时,我们从文档中提取所有实体提及,并且我们认为 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);
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-17
      • 1970-01-01
      • 2019-05-24
      • 1970-01-01
      • 2017-04-15
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多