我使用斯坦福核心NLP API;我的代码如下:如何制作快速的斯坦福核心NLP API?
public class StanfordCoreNLPTool {
public static StanfordCoreNLPTool instance;
private Annotation annotation = new Annotation();
private Properties props = new Properties();
private PrintWriter out = new PrintWriter(System.out);;
private StanfordCoreNLPTool(){}
public void startPipeLine(String question){
props = new Properties();
props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse,mention,
dcoref, sentiment");
annotation = new Annotation(question);
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
// run all the selected Annotators on this text
pipeline.annotate(annotation);
pipeline.prettyPrint(annotation, out);
}
public static StanfordCoreNLPTool getInstance() {
if(instance == null){
synchronized (StanfordCoreNLPTool.class){
if(instance == null){
instance = new StanfordCoreNLPTool();
}
}
}
return instance;
}
}
它工作正常,但它需要很多时间;考虑我们在问答系统中使用它,所以对于每个新输入,必须运行pipeAnnotation。 正如你所知道的,每次应该提取一些规则,训练一些数据以产生一个带有NLP标签(如POS,NER和...)的句子。
首先,我想与RMI和EJB来解决问题,但是失败了,因为,无论任何JAVA架构中,对于每一个新的句子,pipeAnnotation应该从从头开始学。 看看这篇日志被印在了我的IntelliJ控制台:
读POS恶搞从 埃杜/斯坦福/ NLP /模型/ POS-恶搞/英left3words /英left3words-distsim.tagger 模型。 ..完成[6.1秒]。从 EDU /斯坦福/ NLP /模型/ NER/english.all.3class.distsim.crf.ser.gz
加载分类器... DONE [8.0秒]。从 EDU /斯坦福/ NLP /模型/ NER/english.muc.7class.distsim.crf.ser.gz
加载分类... 做过[8.7秒]。从 EDU /斯坦福/ NLP /模型/ NER/english.conll.4class.distsim.crf.ser.gz ... DONE [5.0秒]
加载分类器。
信息:阅读25条规则[主] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP - 添加注释解析 [主] INFO edu.stanford.nlp.parser.common.ParserGrammar - 装载 从串行分析器文件 edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz ...完成[4.1 秒]。
请帮我找到一个解决方案,使程序更快。
制作节目快似乎并不具有任何与RMI或EJB。 – EJP
我的意思是,为pipeannotation制作一个独立的程序,另一个程序通过远程方法调用获取nlp标签。 –