【发布时间】:2016-11-16 18:26:29
【问题描述】:
我正在尝试使用斯坦福核心 NLP 进行命名实体识别。
一些命名实体包含多个标记,例如,Person:“Bill Smith”。我不知道使用什么 API 调用来确定何时应将“Bill”和“Smith”视为一个实体,以及何时应将它们视为两个不同的实体。
是否有一些像样的文档可以解释这一点?
这是我当前的代码:
InputStream is = getClass().getResourceAsStream(MODEL_NAME);
if (MODEL_NAME.endsWith(".gz")) {
is = new GZIPInputStream(is);
}
is = new BufferedInputStream(is);
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
AbstractSequenceClassifier<CoreLabel> classifier = CRFClassifier.getClassifier(is);
is.close();
String text = "Hello, Bill Smith, how are you?";
List<List<CoreLabel>> sentences = classifier.classify(text);
for (List<CoreLabel> sentence: sentences) {
for (CoreLabel word: sentence) {
String type = word.get(CoreAnnotations.AnswerAnnotation.class);
System.out.println(word + " is of type " + type);
}
}
另外,我不清楚为什么“PERSON”注释会以 AnswerAnnotation 的形式返回,而不是 CoreAnnotations.EntityClassAnnotation、EntityTypeAnnotation 或其他。
【问题讨论】:
标签: stanford-nlp