Example usage for edu.stanford.nlp.coref.data Mention getRelation

List of usage examples for edu.stanford.nlp.coref.data Mention getRelation

Introduction

In this page you can find the example usage for edu.stanford.nlp.coref.data Mention getRelation.

Prototype

public String getRelation() 

Source Link

Usage

From source file:sentimentanalysis.SentimentAnalysis.java

private static ArrayList<String> getAttributes(String twitter) throws IOException, ClassNotFoundException {
    ArrayList<String> attributes = new ArrayList<String>();
    String[] sentences = SentenceDetect(twitter);
    Properties props = new Properties();
    props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,parse,mention,coref");
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

    for (String sentence : sentences) {
        Annotation document = new Annotation(sentence);
        pipeline.annotate(document);//w  w w.  j a v a  2  s .  c o m
        for (CoreMap sent : document.get(CoreAnnotations.SentencesAnnotation.class)) {
            for (Mention m : sent.get(CorefCoreAnnotations.CorefMentionsAnnotation.class)) {

                if (m.getRelation() == "verbArg") {
                    ArrayList<String[]> POSResult = POSTag(m.toString());
                    PreProcess preprocessor = new PreProcess();
                    String TokenizedWord[] = preprocessor.tokenize(m.toString());
                    String[] ArrayOfTag = POSResult.get(0);
                    for (int i = 0; i < ArrayOfTag.length; i++) {
                        if (ArrayOfTag[i].length() > 2) {
                            if (ArrayOfTag[i].substring(0, 2).equals("JJ") && (i + 1) < ArrayOfTag.length) {
                                if (ArrayOfTag[i + 1].length() > 1) {
                                    if (ArrayOfTag[i + 1].substring(0, 2).equals("NN")) {
                                        String attr = TokenizedWord[i] + " " + TokenizedWord[i + 1];
                                        attributes.add(attr);
                                    }
                                }
                            }
                            if (ArrayOfTag[i].equals("NNS") && !TokenizedWord[i].toLowerCase().contains("https")
                                    && !TokenizedWord[i].contains("http")) {
                                String attr = TokenizedWord[i];
                                attributes.add(attr);
                            }
                        }
                    }
                }
            }
        }
    }
    return attributes;
}