Compile error in Java corenlp sentiment score program via py4j in Python
<p>I mainly use Python and new to Java. However I am trying to write a Java program and make it work in Python via Py4j Python package. Following program is what I adapted from an example. I encountered a compile error. Could you shed some light? I am pretty sure it is basic error. Thanks.  </p>

<pre><code>&gt; compile error: incompatible type: SimpleMatrix cannot be converted to String: return senti_scores.
&gt; intended input in Python: 
app = CoreNLPSentiScore()
app.findSentiment("I like this book")
intended output: matrix:    Type = dense , numRows = 5 , numCols = 1
0.016  
0.037  
0.132  
0.618  
0.196  

import java.util.List;
import java.util.Properties;
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.neural.rnn.RNNCoreAnnotations;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.sentiment.SentimentCoreAnnotations.SentimentAnnotatedTree;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.util.ArrayCoreMap;
import edu.stanford.nlp.util.CoreMap;
import py4j.GatewayServer;
import org.ejml.simple.SimpleMatrix;


public class CoreNLPSentiScore {
static StanfordCoreNLP pipeline;

    public static void init() {
        Properties props = new Properties();
        props.setProperty("annotators", "tokenize, ssplit, parse, sentiment");
        pipeline = new StanfordCoreNLP(props);

    }

    public static void main(String[] args) {
        CoreNLPSentiScore app = new CoreNLPSentiScore();
        // app is now the gateway.entry_point
        GatewayServer server = new GatewayServer(app);
        server.start();
    }

    //public static void main(String tweet) {
    //public static String findSentiment(String tweet) {
    public String findSentiment(String tweet) {
    //String SentiReturn = "2";
    //String[] SentiClass ={"very negative", "negative", "neutral", "positive", "very positive"};

    //Sentiment is an integer, ranging from 0 to 4. 
    //0 is very negative, 1 negative, 2 neutral, 3 positive and 4 very positive.
    //int sentiment = 2;
        SimpleMatrix senti_score = new SimpleMatrix();
        if (tweet != null &amp;&amp; tweet.length() &gt; 0) {
            Annotation annotation = pipeline.process(tweet);

            List&lt;CoreMap&gt; sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
            if (sentences != null &amp;&amp; sentences.size() &gt; 0) {

                ArrayCoreMap sentence = (ArrayCoreMap) sentences.get(0);                
                //Tree tree = sentence.get(SentimentAnnotatedTree.class);  
                Tree tree = sentence.get(SentimentAnnotatedTree.class);  
                senti_score = RNNCoreAnnotations.getPredictions(tree);             

                //SentiReturn = SentiClass[sentiment];
            }
        }
        //System.out.println(senti_score);
        return senti_score;
        //System.out.println(senti_score);
    }

}
</code></pre>

<p>Java is object oriented program but it is not like python where everything is considered as object. </p>

<p>In your program mentioned above. There is a method findsentiment is returning SimpleMatrix but in the method declaration it is String. </p>

<p>Solution - You can overide a method toString()  in your class SimpleMatrix and while returning  senti_score return senti_score.toString() </p>

java python corenlp py4j