Mar*_*rkB 13 named-entity-recognition stanford-nlp
我正在使用CoreNLP进行命名实体提取,并遇到了一些问题.问题在于,只要命名实体由多个标记组成,例如"Han Solo",注释器就不会将"Han Solo"作为单个命名实体返回,而是作为两个单独的实体,"Han""Solo" .
是否可以将命名实体作为一个令牌?我知道我可以在这个范围内使用带有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));
}
}
Run Code Online (Sandbox Code Playgroud)
帮助我Obi-Wan Kenobi.你是我唯一的希望.
小智 3
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();
}
Run Code Online (Sandbox Code Playgroud)
我能够想出这个解决方案。我正在将输出写入 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>
Run Code Online (Sandbox Code Playgroud)
从上面的输出中您可以看到连续的单词被识别为“ORGANIZATION”。所以这些词可以组合成一个实体。
| 归档时间: |
|
| 查看次数: |
3081 次 |
| 最近记录: |