我正在使用OpenNLP,但它没有给我确切的名称,位置,组织实体。如何使用stanford解析器提取实体?
答案 0 :(得分:0)
我的代码可能会对您有所帮助。
这是我的代码
public class stanfrdIntro {
public static void main(String[] args) throws IOException, SAXException,
TikaException {
String serializedClassifier = "classifiers/english.all.3class.distsim.crf.ser.gz";
AbstractSequenceClassifier<CoreLabel> classifier = CRFClassifier
.getClassifierNoExceptions(serializedClassifier);
if (args.length > 1) {
String fileContents = IOUtils.slurpFile(args[1]);
List<List<CoreLabel>> out = classifier.classify(fileContents);
for (List<CoreLabel> sentence : out) {
for (CoreLabel word : sentence) {
System.out.print(word.word() + '/' +
word.get(CoreAnnotations.AnswerAnnotation.class) + ' ');
}
System.out.println();
}
out = classifier.classifyFile(args[1]);
for (List<CoreLabel> sentence : out) {
for (CoreLabel word : sentence) {
System.out.print(word.word() + '/' +
word.get(CoreAnnotations.AnswerAnnotation.class) + ' ');
}
System.out.println();
}
} else {
String s1 = "Good afternoon Rahul Kulhari, how are you today?";
String s2 =
"I go to school at Stanford University, which is located in California.";
stanfrdIntro si = new stanfrdIntro();
String s1 = si.contentEx();
s1 = s1.replaceAll("\\s+", " ");
System.out.println(s1);
String t=classifier.classifyWithInlineXML(s1);
System.out.println(Arrays.toString(getTagValues(t).toArray()));
XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression expr = xpath.compile("//PERSON/text()");
Object value = expr.evaluate(doc, XPathConstants.STRING);
System.out.println(t);
System.out.println(classifier.classifyToString(s1));
Set<String> s=classifier.;
for(String s13: s)
{
System.out.println(s13);
}
System.out.println(classifier.classifyWithInlineXML(s1));
System.out.println(classifier.classifyToString(s1, "xml", true));
int i=0;
for (List<CoreLabel> lcl : classifier.classify(s2)) {
for (CoreLabel cl : lcl) {
System.out.println(i++ + ":");
System.out.println(cl);
}
}
}
}
}