【问题标题】:How to extract entity using stanford parser?如何使用斯坦福解析器提取实体?
【发布时间】:2013-08-09 05:15:55
【问题描述】:

我正在使用 OpenNLP,但它没有给我确切的名称、位置、组织实体。如何使用斯坦福解析器提取实体?

【问题讨论】:

    标签: parsing nlp opennlp


    【解决方案1】:

    我的代码可能会对你有所帮助。

    这是我的代码

    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);
     }
     }
     }
        }
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 2013-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多