package com.github.bot.curiosone.core.analysis;

import static java.util.Comparator.comparing;

import com.github.bot.curiosone.core.nlp.Meaning;
import com.github.bot.curiosone.core.nlp.POS;
import com.github.bot.curiosone.core.nlp.Token;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

/**
 * Finding Sentiment's score.
 *
 * @author Cosmo Pugliese && Francesco Natale
 */

public class TokenScorer {

  /**
   * HashSet containing tokens' score.
   */
  private static HashSet<Double> scoreSet = new HashSet<>();

  /**
   * Load SentiWordNet's dictionary.
   */
  private static Map<String, Double> dictionary = DictionaryLoader.loadDict();

  /**
   * Calculate the score of the Token.
   *
   * @param t is the Token add t's sentiment's score to scoreSet.
   */
  public static void calculateScore(Token t) {
    if (t.getMeanings().stream()
        .sorted(comparing(Meaning::getFrequency).reversed())
        .findFirst()
        .get().getPOS() == POS.ADJ

        || t.getMeanings().stream()
            .sorted(comparing(Meaning::getFrequency).reversed())
            .findFirst()
            .get().getPOS() == POS.V

        || t.getMeanings().stream()
            .sorted(comparing(Meaning::getFrequency).reversed())
            .findFirst()
            .get().getPOS() == POS.ADV

        || t.getMeanings().stream()
            .sorted(comparing(Meaning::getFrequency).reversed())
            .findFirst()
            .get().getPOS() == POS.N) {
      if (dictionary.containsKey(t.getLemma())) {
        scoreSet.add(dictionary.get(t.getLemma()));
      }
    }
  }

  /**
   * Calculate the score of the input token's list.
   *
   * @param tokenList the token list.
   */
  public static void calculateScore(List<Token> tokenList) {
    for (Token x : tokenList) {
      calculateScore(x);
    }
  }

  /**
   * Calculate the score of the token analyzed until this method call.
   *
   * @return  the score of analyzed tokens.
   */
  public static Double getScore() {
    HashSet<Double> temp = new HashSet<>(scoreSet);
    scoreSet = new HashSet<>();
    return temp.stream().reduce(0.0, Double::sum) / temp.size();
  }

}

@@ -540,102 +540,42 @@
 %0A%0A  
-/**%0A   * Load SentiWordNet's dictionary.%0A   */%0A  private static Map%3CString, Double%3E dictionary
+private static DictionaryLoader dl
  = D
@@ -594,16 +594,19 @@
 der.
-loadDict
+getInstance
 ();%0A
@@ -779,20 +779,24 @@
 ) %7B%0A    
-if (
+POS p = 
 t.getMea
@@ -921,563 +921,74 @@
 OS()
- == POS.ADJ%0A%0A        %7C%7C t.getMeanings().stream()%0A            .sorted(comparing(Meaning::getFrequency).reversed())%0A            .findFirst()%0A            .get().getPOS() == POS.V%0A%0A        %7C%7C t.getMeanings().stream()%0A            .sorted(comparing(Meaning::getFrequency).reversed())%0A            .findFirst()%0A            .get().getPOS() == POS.ADV%0A%0A        %7C%7C t.getMeanings().stream()%0A            .sorted(comparing(Meaning::getFrequency).reversed())%0A            .findFirst()%0A            .get().getPOS() == POS.N) %7B%0A      if (dictionary.containsKey(t.getLemma())
+;%0A    if (p == POS.ADJ %7C%7C p == POS.V %7C%7C p == POS.ADV %7C%7C p == POS.N
 ) %7B%0A
@@ -1013,21 +1013,18 @@
 dd(d
-ictionary.get
+l.getScore
 (t.g
@@ -1040,16 +1040,8 @@
 ));%0A
-      %7D%0A
     

improve calculateScore method