Skip to content

Instantly share code, notes, and snippets.

@jjfiv
Created July 7, 2015 18:59
Show Gist options
  • Select an option

  • Save jjfiv/e4ee61458039a5e97fea to your computer and use it in GitHub Desktop.

Select an option

Save jjfiv/e4ee61458039a5e97fea to your computer and use it in GitHub Desktop.
Limit Stanford NLP to a duration.
@SuppressWarnings("deprecated")
public static boolean annotateTimed(Annotation ann) {
// Don't time the initial classifier setup.
nlp.get();
Thread annotateThread = new Thread(() -> {
nlp.get().annotate(ann);
});
annotateThread.start();
// Spend at most 4 seconds annotating any document; after this it might as well be hanging!
try {
annotateThread.join(MaxAnnotationTime);
} catch (InterruptedException e) {
}
if (!annotateThread.isAlive()) {
// Excellent, it finished.
return true;
}
// Yes, I know.
annotateThread.stop();
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment