我正在尝试通过这段代码通过CoreNLP使用斯坦福NLP的SUTime:
AnnotationPipeline pipeline = new AnnotationPipeline();
pipeline.addAnnotator(new TimeAnnotator("sutime", props));
Annotation annotation = new Annotation("The interesting date is 4 days from today and it is 20th july of this year, another date is 18th Feb 1997");
annotation.set(CoreAnnotations.DocDateAnnotation.class, "2013-07-14");
pipeline.annotate(annotation);
List<CoreMap> timexAnnsAll = annotation.get(TimeAnnotations.TimexAnnotations.class);然而,它最终抛出了这个异常:
Reading TokensRegex rules from edu/stanford/nlp/models/sutime/defs.sutime.txt
Reading TokensRegex rules from edu/stanford/nlp/models/sutime/english.sutime.txt
Reading TokensRegex rules from edu/stanford/nlp/models/sutime/english.holidays.sutime.txt
Exception in thread "main" java.lang.NullPointerException
at edu.stanford.nlp.ie.NumberNormalizer.findNumbers(NumberNormalizer.java:423)
at edu.stanford.nlp.ie.NumberNormalizer.findAndMergeNumbers(NumberNormalizer.java:721)
at edu.stanford.nlp.time.TimeExpressionExtractorImpl.extractTimeExpressions(TimeExpressionExtractorImpl.java:184)
at edu.stanford.nlp.time.TimeExpressionExtractorImpl.extractTimeExpressions(TimeExpressionExtractorImpl.java:178)
at edu.stanford.nlp.time.TimeExpressionExtractorImpl.extractTimeExpressionCoreMaps(TimeExpressionExtractorImpl.java:116)
at edu.stanford.nlp.time.TimeAnnotator.annotateSingleSentence(TimeAnnotator.java:240)
at edu.stanford.nlp.time.TimeAnnotator.annotate(TimeAnnotator.java:226)
at edu.stanford.nlp.pipeline.AnnotationPipeline.annotate(AnnotationPipeline.java:68)
at dd.stanford.main(stanford.java:74)我使用的是maven的3.5.2版本。有人知道为什么会有这样的例外吗?提前谢谢。
发布于 2015-12-13 18:57:47
这是崩溃,因为你没有标记化文本。
将您的代码更改为:
AnnotationPipeline pipeline = new AnnotationPipeline();
pipeline.addAnnotator(new TokenizerAnnotator(false));
pipeline.addAnnotator(new TimeAnnotator("sutime", props));https://stackoverflow.com/questions/33944612
复制相似问题