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

import com.github.bot.curiosone.core.nlp.tokenizer.PosT;
import com.github.bot.curiosone.core.nlp.tokenizer.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.getPos() == PosT.ADJ || t.getPos() == PosT.V || t.getPos() == PosT.ADV
        || t.getPos() == PosT.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();
  }
  
}

@@ -42,16 +42,63 @@
 lysis;%0A%0A
+import static java.util.Comparator.comparing;%0A%0A
 import c
@@ -134,22 +134,15 @@
 nlp.
-tokenizer.PosT
+Meaning
 ;%0Aim
@@ -184,17 +184,53 @@
 nlp.
-tokenizer
+POS;%0Aimport com.github.bot.curiosone.core.nlp
 .Tok
@@ -420,19 +420,17 @@
 corer %7B%0A
-  
 %0A
+
   /**%0A  
@@ -708,25 +708,24 @@
  Token.%0A   *
- 
 %0A   * @param
@@ -849,76 +849,476 @@
 .get
-Pos
+Meanings().stream()%0A        .sorted(comparing(Meaning::getFrequency).reversed())%0A        .findFirst()%0A        .get().getPOS
 () == P
-osT
+OS
 .ADJ
- %7C%7C t.getPos() == PosT.V %7C%7C t.getPos
+%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
 () == P
-osT
+OS
 .ADV%0A
+%0A
     
@@ -1333,21 +1333,152 @@
 .get
-Pos
+Meanings().stream()%0A            .sorted(comparing(Meaning::getFrequency).reversed())%0A            .findFirst()%0A            .get().getPOS
 () == P
-osT
+OS
 .N) 
@@ -1591,35 +1591,33 @@
     %7D%0A    %7D%0A  %7D%0A
-  
 %0A
+
   /**%0A   * Calcu
@@ -1658,25 +1658,24 @@
 s list.%0A   *
- 
 %0A   * @param
@@ -1835,19 +1835,17 @@
   %7D%0A  %7D%0A
-  
 %0A
+
   /**%0A  
@@ -1917,17 +1917,16 @@
 ll.%0A   *
- 
 %0A   * @r
@@ -2157,13 +2157,11 @@
 ();%0A  %7D%0A
-  
 %0A%7D%0A

fix compiling errors