首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >核心-nlp的SUTime Timex3值与图形用户界面输出不同

核心-nlp的SUTime Timex3值与图形用户界面输出不同
EN

Stack Overflow用户
提问于 2017-03-08 20:48:21
回答 1查看 215关注 0票数 0

我试着使用核心nlp中的'SUTime‘函数。如果我尝试使用在线演示中的'sampleInput‘

代码语言:javascript
复制
From next month, we will have meeting on every friday, from 3:00 pm to 4:00 pm.” 

其结果为(参考日期: 2017-1-1):

代码语言:javascript
复制
<TIMEX3 range="(2017-02-01,2017-02-28,P1M)" tid="t1" type="DATE" value="2017-02">next month</TIMEX3>

但是,当我尝试通过SUTime应用程序接口运行相同的输入时,结果是(特别是:'Temporal‘)

代码语言:javascript
复制
<Token text="next month" Temporal Value="THIS P1M OFFSET P1M" Timex="null" Timex type="DATE" Start offset="5" End Offset="15" />

代码如下:

代码语言:javascript
复制
List<CoreMap> timexAnnsAll = document.get(TimeAnnotations.TimexAnnotations.class);
                for (CoreMap cm : timexAnnsAll) {
                    try {
                        List<CoreLabel> tokens = cm.get(CoreAnnotations.TokensAnnotation.class);

                        Temporal temporal = cm.get(TimeExpression.Annotation.class).getTemporal();


                        System.out.println("Token text : " + cm.toString());
                        System.out.println("Temporal Value : " + temporal.toString());
                        System.out.println("Timex : " + temporal.getTimexValue());
                        System.out.println("Timex type : " + temporal.getTimexType().name());
EN

回答 1

Stack Overflow用户

发布于 2017-03-10 15:53:29

问题是您没有设置文档日期。

代码语言:javascript
复制
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("From next month, we will have meeting on every friday, from 3:00 pm to 4:00 pm.");
    document.set(CoreAnnotations.DocDateAnnotation.class, "2017-03-01");
    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);
        System.out.println(entityMention.get(TimeAnnotations.TimexAnnotation.class));
      }
    }
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42671822

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档