Stanford nlp 多线程(无法访问全局变量,如ann)
我正在尝试多线程注释,但对访问ann表示不满Stanford nlp 多线程(无法访问全局变量,如ann),stanford-nlp,Stanford Nlp,我正在尝试多线程注释,但对访问ann表示不满 从运行()。你知道吗 Properties props = new Properties(); props.setProperty("annotators", "tokenize,ssplit,parse"); StanfordCoreNLP pipeline = new StanfordCoreNLP(props); Annotation ann = new Annotation("your sentence here"); for (int i
从
运行()
。你知道吗
Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,parse");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
Annotation ann = new Annotation("your sentence here");
for (int i = 0; i < 100; ++i) {
new Thread() {
@Override public void run() {
pipeline.annotate(ann);
Tree tree = ann.get(SentencesAnnotation.class).get(0).get(TreeAnnotation.class);
}
}.start();
}
Properties=newproperties();
props.setProperty(“注释器”、“标记化、ssplit、解析”);
StanfordCoreNLP管道=新的StanfordCoreNLP(道具);
Annotation ann=新注释(“此处的句子”);
对于(int i=0;i<100;++i){
新线程(){
@重写公共无效运行(){
管道注释(ann);
Tree-Tree=ann.get(SentencesAnnotation.class).get(0).get(TreeAnnotation.class);
}
}.start();
}
这似乎是一个java问题,如果不是,而且这是一个关于斯坦福nlp的问题,我可能错了
如果您发布了代码中的确切错误,这会有所帮助。我想是关于
由于闭包和作用域在java中的工作方式,这些变量必须(有效地取决于java版本)是最终的。
把线路改成
final Annotation ann = new Annotation("your sentence here");
帮忙