java - 创建温暖的斯坦福自然语言处理解析器的最小示例

标签 java nlp stanford-nlp

我想要一个温暖的(已加载的)解析器来解析输入,而不是每次我想解析输入时创建一个新实例。

我想要一个功能类似于 http://nlp.stanford.edu:8080/parser/ 的解析器。我从 Maven 安装了 stanford-corenlp 。我执行了 StanfordCoreNlpDemo 类。

但是我不知道如何将解析器嵌入到我自己的程序中。请提供以编程方式创建解析器的最小示例。

最佳答案

但请记住:

  • 斯坦福核心 NLP!= 斯坦福解析器;前者包括解析器和其他 NLP 工具。

  • 核心 NLP 会占用大量 RAM!

我一直在努力实现同样的目标。这就是我到目前为止所得到的网络服务,您可以使用单例执行类似的操作。

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

    }
}

关于java - 创建温暖的斯坦福自然语言处理解析器的最小示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15411496/

相关文章:

python - 如何从句子中提取字符ngram? - Python

java - 让斯坦福 NLP 识别具有多个单词的命名实体

java - 如何为 stanford corenlp 获取文本的 xml 输出

java - 碰撞 - 识别物体何时停止碰撞

java - Maven项目编译错误: cannot find symbol (which is java. lang.String)

java - 为什么执行一组测试会得到与单独执行不同的结果?

machine-learning - Keras 中 lm_1b 的字符-词嵌入

python - 使用我自己的语料库在 Python NLTK 中进行类别分类

java - 在斯坦福解析器上设置非折叠依赖项

java - 如何停止链式方法调用?