我想要一个温暖的(已加载的)解析器来解析输入,而不是每次我想解析输入时创建一个新实例。
我想要一个功能类似于 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/