0

I am trying multithreaded annotation, but complaining with accessing ann
from run(). Do you have any idea?

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();
}
Michał Turczyn
  • 32,028
  • 14
  • 47
  • 69
1 2
  • 1
  • 3

1 Answers1

0

This seems to be a java question, if it is not and it's specifically a question about stanford-nlp, I might be wrong.

It would help if you posted the exact error you are getting with your code. I guess it is about accessing a local variable from an anonymous inner class.

Due to how closure and scoping work in java such variables have to be (effectively depending on java version) final. Does changing the line to

final Annotation ann = new Annotation("your sentence here");

help?

Tyrius
  • 23
  • 7