Tree Tagger for Java (tt4j)

973 Views Asked by At

I am creating a Twitter Sentiment Analysis tool in Java. I am using the Twitter4J API to search tweets via the hashtag feature in twitter and then provide sentiment analysis on these tweets. Through research, I have found that the best solution to doing this will be using a POS and TreeTagger for Java.

At the moment, I am using the examples provided to see how the code works, although I am encountering some problems.

This is the code

import org.annolab.tt4j.*;
import static java.util.Arrays.asList;

public class Example {
    public static void main(String[] args) throws Exception {
            // Point TT4J to the TreeTagger installation directory. The executable is expected
            // in the "bin" subdirectory - in this example at "/opt/treetagger/bin/tree-tagger"
            System.setProperty("treetagger.home", "/opt/treetagger");
            TreeTaggerWrapper tt = new TreeTaggerWrapper<String>();
            try {
                    tt.setModel("/opt/treetagger/models/english.par:iso8859-1");
                    tt.setHandler(new TokenHandler<String>() {
                            public void token(String token, String pos, String lemma) {
                                    System.out.println(token + "\t" + pos + "\t" + lemma);
                            }
                    });
                    tt.process(asList(new String[] { "This", "is", "a", "test", "." }));
            }
            finally {
                    tt.destroy();
            }
    }

}

At the moment, when this is run, I receive an error which says

TreeTaggerWrapper cannot be resolved to a type
TokenHandler cannot be resolved to a type

I will be grateful for any help given

Thank you

0

There are 0 best solutions below