gpt4 book ai didi

stanford-nlp - 使用 CoreNLP 提取多词命名实体

转载 作者:行者123 更新时间:2023-12-03 23:58:13 25 4
gpt4 key购买 nike

我正在使用 CoreNLP 进行命名实体提取,但遇到了一些问题。
问题在于,每当命名实体由多个标记组成时,例如“Han Solo”,注释器不会将“Han Solo”作为单个命名实体返回,而是作为两个单独的实体返回,“Han”“Solo” .

是否可以将命名实体作为一个 token ?我知道我可以在这个程度上使用带有classifyWithInlineXML的CRFClassifier,但是我的解决方案要求我使用CoreNLP,因为我还需要知道单词编号。

以下是我到目前为止的代码:

    Properties props = new Properties();
props.put("annotators", "tokenize,ssplit,pos,lemma,ner,parse");
props.setProperty("ner.model", "edu/stanford/nlp/models/ner/english.conll.4class.distsim.crf.ser.gz");
pipeline = new StanfordCoreNLP(props);
Annotation document = new Annotation(text);
pipeline.annotate(document);
List<CoreMap> sentences = document.get(SentencesAnnotation.class);
for (CoreMap sentence : sentences) {
for (CoreLabel token : sentence.get(TokensAnnotation.class)) {
System.out.println(token.get(NamedEntityTagAnnotation.class));
}
}

Help me Obi-Wan Kenobi. You're my only hope.

最佳答案

PrintWriter writer = null;
try {
String inputLine = "Several possible plans emerged from the talks, held at the Federal Reserve Bank of New York" + " and led by Timothy R. Geithner, the president of the New York Fed, and Treasury Secretary Henry M. Paulson Jr.";

String serializedClassifier = "english.all.3class.distsim.crf.ser.gz";
AbstractSequenceClassifier<CoreLabel> classifier = CRFClassifier.getClassifierNoExceptions(serializedClassifier);

writer = new PrintWriter(new File("output.xml"));
writer.println("<Sentences>");
writer.flush();
String output ="<Sentence>"+classifier.classifyToString(inputLine, "xml", true)+"</Sentence>";
writer.println(output);
writer.flush();
writer.println("</Sentences>");
writer.flush();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} finally {
writer.close();
}

我能够想出这个解决方案。我正在将输出写入 XML 文件“output.xml”。从获得的输出中,您可以将 xml 中具有“PERSON”或“ORGANIZATION”或“LOCATION”属性的连续节点合并为一个实体。默认情况下,此格式会生成字数。

这是 xml 输出的快照。
<wi num="11" entity="ORGANIZATION">Federal</wi>
<wi num="12" entity="ORGANIZATION">Reserve</wi>
<wi num="13" entity="ORGANIZATION">Bank</wi>
<wi num="14" entity="ORGANIZATION">of</wi>
<wi num="15" entity="ORGANIZATION">New</wi>
<wi num="16" entity="ORGANIZATION">Yorkand</wi>

从上面的输出中你可以看到连续的单词被识别为“ORGANIZATION”。所以这些词可以组合成一个实体。

关于stanford-nlp - 使用 CoreNLP 提取多词命名实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22281889/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com