如何提取与 CoreEntityMention (WikiDictAnnotator) 匹配的维基百科实体

How to extract Wikipedia entity matched to CoreEntityMention (WikiDictAnnotator)

我 运行 CoreNLP 处理一些文本,并将找到的实体与维基百科实体进行匹配。我想重建句子,为找到的实体提供 link 和其他有用信息。

CoreEntityMention 有一个 entity() 方法,但它只是 returns 一个字符串。

Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,entitylink");

// set up pipeline
pipeline = new StanfordCoreNLP(props);
String doc = "text goes here";
pipeline.annotate(doc);

// Iterate the sentences
for (CoreSentence sentence : doc.sentences()) {
      Go through all mentions
      for (CoreEntityMention em : sentence.entityMentions()) {
          System.out.println(em.sentence());
          // Here I would like to extract the Wikipedia entity information
          System.out.println(em.entity());
      }
    }

您只需添加维基百科页面 url。

所以 Neil_Armstrong 映射到 https://en.wikipedia.org/wiki/Neil_Armstrong