1

入力を解析するたびに新しいインスタンスを作成するのではなく、ウォーム (既にロードされている) パーサーで入力を解析する必要があります。

http://nlp.stanford.edu:8080/parser/と同様に機能するパーサーが必要です。stanford-corenlpMavenからインストールしました。StanfordCoreNlpDemoクラスを実行しました。

しかし、パーサーを自分のプログラムに埋め込む方法に行き詰まっています。プログラムでパーサーを作成する最小限の例を提供してください。

4

2 に答える 2

1

ただし、次の点に注意してください。

  • スタンフォード コア NLP != スタンフォード パーサー; 前者には、パーサーと他の NLP ツールが含まれています。

  • コア NLP は RAM を大量に消費します。

私は同じことを達成しようとしてきました。これは私がこれまでに Web サービスで得たものです。シングルトンでも同様のことができます。

    public class NLPServlet extends HttpServlet {
    private StanfordCoreNLP pipeline;
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        try {
            Properties props = new Properties();
            props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
            this.pipeline = new StanfordCoreNLP(props);
        } catch (Exception e) {
            System.err.println("Error " + e.getLocalizedMessage());
        }
    }
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        text="blah, blah, blah.";

        // create an empty Annotation just with the given text
        Annotation document = new Annotation(text);

        // run all Annotators on this text
        pipeline.annotate(document);

    }
}
于 2013-04-26T00:26:32.457 に答える
0

この方法で試すことができます

import java.io.IOException;
import java.util.List;
import java.util.Properties;

import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.semgraph.SemanticGraph;
import edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.trees.TreeCoreAnnotations;
import edu.stanford.nlp.util.ArrayCoreMap;
import edu.stanford.nlp.util.CoreMap;

public class getentity{
    public static void main(String[]args) throws IOException{
     Properties props = new Properties();
        props.setProperty("annotators", "tokenize, ssplit, parse,sentiment");
        StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

        Annotation annotation= new Annotation("project is good but management is bad, work-culture is good");
        pipeline.annotate(annotation);
        List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
        if (sentences != null && sentences.size() > 0) {

            ArrayCoreMap sentence = (ArrayCoreMap) sentences.get(0);
            Tree tree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class);
            for (CoreMap token : sentence.get(CoreAnnotations.TokensAnnotation.class)) {
                ArrayCoreMap aToken = (ArrayCoreMap) token;
                }
             SemanticGraph graph = sentence.get(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class);

            String k=graph.toString("plain");
            System.out.println(k);

  }
  }
}

この特定のコードでは、文内のすべてのエンティティを取得できます

于 2014-01-08T08:05:16.613 に答える