我正在使用斯坦福CoreNLP分析器來運行某些文本,並且還有日期短語,例如'10月的第二個星期一'和'過去的一年'。該庫會將每個標記適當地標記爲一個DATE命名實體,但是有沒有一種方法來以編程方式獲取這個整個日期短語?這不僅僅是日期,ORGANIZATION命名的實體也會這樣做(例如,「國際奧委會」可以是在給定文本示例中標識的)。是否有可能獲得一組包含短語的特定命名實體標記
String content = "Thanksgiving, or Thanksgiving Day (Canadian French: Jour de"
+ " l'Action de grâce), occurring on the second Monday in October, is"
+ " an annual Canadian holiday which celebrates the harvest and other"
+ " blessings of the past year.";
Properties p = new Properties();
p.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse");
StanfordCoreNLP pipeline = new StanfordCoreNLP(p);
Annotation document = new Annotation(content);
pipeline.annotate(document);
for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) {
for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) {
String word = token.get(CoreAnnotations.TextAnnotation.class);
String ne = token.get(CoreAnnotations.NamedEntityTagAnnotation.class);
if (ne.equals("DATE")) {
System.out.println("DATE: " + word);
}
}
}
其中,斯坦福註釋和分級加載後,會產生輸出:
DATE: Thanksgiving
DATE: Thanksgiving
DATE: the
DATE: second
DATE: Monday
DATE: in
DATE: October
DATE: the
DATE: past
DATE: year
我覺得圖書館必須要承認的短語和使用它們的命名實體標記,所以問題是數據會以某種方式保存並通過api獲取?
感謝, 凱文