I am trying to get started with the Stanford NER tools tools in Mathematica, and am having difficulty translating the demo they provide into JLink. The relevant code in the demo is:
/* Usage: java -cp "stanford-ner.jar:." NERDemo */
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.ling.CoreAnnotations;
...
for (CoreLabel word : sentence) {
... w.word() ... word.get(CoreAnnotations.AnswerAnnotation.class) ...
So I tried:
InstallJava[ClassPath -> ".../stanford-ner.jar"];
answerAnnotation = LoadJavaClass["edu.stanford.nlp.ling.CoreAnnotations$AnswerAnnotation"]
JavaClass[edu.stanford.nlp.ling.CoreAnnotations$AnswerAnnotation,<>]
(...things that appear to be working correctly...)
w
« JavaObject[edu.stanford.nlp.ling.CoreLabel]»
w@word[] (* works *)
w@get[answerAnnotation] (* $Failed *)
Java::argx1: Method named get defined in class edu.stanford.nlp.ling.CoreLabel was called with an incorrect number or type of arguments. The argument was JavaClass[edu.stanford.nlp.ling.CoreAnnotations$AnswerAnnotation,<>].
The (inherited) method signature of get
is
get(java.lang.Class<? extends TypesafeMap.Key<VALUE>> key)
w@get
the following:JavaNew["edu.stanford.nlp.ling.CoreAnnotations$AnswerAnnotation"]@getClass[]
(untested). $\endgroup$