java - Using Stanford NLP lib in C# , While trying to get sentiment (positive/negative) it always returns -1! Any idea why? -


i trying check if statement positive or negative using stanford core nlp.

i found few references online in java , able convert/code in missing pieces c#.

while trying sentiment score - -1 return value.

i think because not able convert

 tree tree = sentence.get(sentimentcoreannotations.annotatedtree.class); 

to .net equivalent.

java.lang.class treeclass = new edu.stanford.nlp.trees.treecoreannotations.treeannotation().getclass();        tree tree = (tree)sentence.get(treeclass); 

here complete code:

var jarroot = @"d:\core nlp files\stanford-corenlp-full-2015-04-20\stanford-corenlp-full-2015-04-20\stanford-corenlp-3.5.2-models";          // text processing         var text = txtinp.text;          // annotation pipeline configuration         var props = new java.util.properties();          props.setproperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");         props.setproperty("sutime.binders", "0");         props.setproperty("ner.usesutime", "false");          // should change current directory, d:\core nlp files\stanford-corenlp-full-2015-04-20\stanford-corenlp-full-2015-04-20 find model files automatically         var curdir = environment.currentdirectory;         directory.setcurrentdirectory(jarroot);         var pipeline = new stanfordcorenlp(props);         directory.setcurrentdirectory(curdir);          // annotation         var annotation = new edu.stanford.nlp.pipeline.annotation(text);         pipeline.annotate(annotation);          // result - pretty print         using (var stream = new bytearrayoutputstream())         {             pipeline.prettyprint(annotation, new printwriter(stream));          //analyze statement positive or negative   int mainsentiment = 0; int longest = 0; string[] sentimenttext = { "very negative","negative", "neutral", "positive", "very positive"};  numberformat nf = new decimalformat("0.0000");  //for (coremap sentence : document.get(coreannotations.sentencesannotation.class))   var sentences = annotation.get(new coreannotations.sentencesannotation().getclass()) arraylist;     foreach(coremap sentence in sentences )   {       java.lang.class treeclass = new edu.stanford.nlp.trees.treecoreannotations.treeannotation().getclass();        tree tree = (tree)sentence.get(treeclass);                   **int sentiment = rnncoreannotations.getpredictedclass(tree);**      string parttext = sentence.tostring();    label1.text = "sentence: '" + parttext + "' rather " + sentimenttext[sentiment];      if (parttext.length > longest)    {         mainsentiment = sentiment;         longest = parttext.length;     }    }  if (mainsentiment == 2 || mainsentiment > 4 || mainsentiment < 0) { label1.text = ("overall sort of neutral review"); } else if (mainsentiment > 2) {     label1.text = ("overall happy"); } else {     label1.text = ("bottom line. displeased"); }   stream.close();         }     } 

any ideas why maybe getting -1 return value sentiment?

here's updated code:-

tree tree = (tree)sentence.get(typeof(edu.stanford.nlp.trees.treecoreannotations.treeannotation));                  int sentiment = rnncoreannotations.getpredictedclass(tree); 

value of tree - {(root (s (np (nn matrix)) (vp (vbz is) (np (dt a) (jj good) (nn movie)))))}

still getting return value -1 while trying determine sentiment.

the c# equivalent "class" field "typeof" operator:

tree tree = sentence.get(typeof(sentimentcoreannotations.annotatedtree)); 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -