Ejemplo n.º 1
0
  public double calculateSentiment(String tweet) {
    if (filters != null) {
      tweet = filters.apply(tweet);
    }

    List<LexicalToken> lexicalTokens = LexicalParser.lexicallyParseTweet(tweet, phraseTree);
    for (int i = 0; i < lexicalTokens.size(); i++) {
      LexicalToken token = lexicalTokens.get(i);
      String phrase = token.getPhrase();

      if (lexicon.hasToken(phrase)) {
        token.setLexicalValue(lexicon.getTokenPolarity(phrase));

      } else if (ClassifierOptions.isNegation(phrase)) {
        propagateNegation(lexicalTokens, i);

      } else if (ClassifierOptions.isIntensifier(phrase)) {
        intensifyNext(lexicalTokens, i, ClassifierOptions.getIntensifierValue(phrase));
      }
    }
    return lexicalTokens.stream().mapToDouble(LexicalToken::getSentimentValue).sum();
  }
Ejemplo n.º 2
0
 public Classifier(PriorPolarityLexicon lexicon, Filters filters) {
   this.lexicon = lexicon;
   this.filters = filters;
   this.phraseTree = new TokenTrie(lexicon.getSubjectiveWords());
 }