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.List;
import java.util.OptionalDouble;

/**
 * Finding Sentiment's score.
 *
 */

public class TokenScorer {
  private static DictionaryLoader dict = DictionaryLoader.getInstance();

  /**
   * Calculate the score of the Token.
   *
   * @param token [description]
   *
   * @return a double value of the given token.
   */
  public static double calculateScore(Token token) {
    POS pos = token.getMeanings().stream()
        .sorted(comparing(Meaning::getFrequency).reversed())
        .findFirst()
        .get().getPOS();
    return (pos == POS.ADJ || pos == POS.V || pos == POS.ADV || pos == POS.N)
        ? dict.getScore(token.getLemma()) : 0.0;
  }

  /**
   * Calculate the score of the input token's list.
   *
   * @param tokenList the token list.
   *
   * @return a double in range -1.0 and 1.0(Saddest to Happiest, 0.0 is a neutral score).
   */
  public static double calculateScore(List<Token> tokenList) {
    OptionalDouble score = tokenList.stream()
        .mapToDouble(TokenScorer::calculateScore)
        .filter(x -> x != 0.0)
        .average();
    return score.isPresent() ? score.getAsDouble() : 0.0;
  }
}

@@ -301,37 +301,137 @@
 %0A * 
-Finding Sentiment's score.%0A *
+Calculates the Sentiment of a Sentence.%0A * Provides methods to calcolate the sentiment score from a single Token or a Token List.
 %0A */
@@ -557,37 +557,93 @@
 late
+s
  the s
-core of the Token.%0A   *
+entiment value for a given Token.%0A   * This value ranges between -1.0 and 1.0.
 %0A   
@@ -655,32 +655,39 @@
 ram 
-t
+T
 oken 
-%5Bdescription%5D%0A   *
+The Token to be analysed.
 %0A   
@@ -694,25 +694,25 @@
 * @return a 
-d
+D
 ouble value 
@@ -710,19 +710,54 @@
 le value
- of
+, representing the sentiment index for
  the giv
@@ -763,15 +763,100 @@
 ven 
-t
+T
 oken.%0A
+   * This index ranges between -1.00 (sad) and 1.00 (happy), 0.00 is a netural score%0A
    *
@@ -1216,50 +1216,98 @@
 late
+s
  the s
-core of the input token's list.%0A   *
+entiment value for a given Token List.%0A   * This value ranges between -1.0 and 1.0.
 %0A   
@@ -1329,28 +1329,38 @@
 ist 
-the t
+The T
 oken 
-list.%0A   *
+List to be analysed.
 %0A   
@@ -1375,36 +1375,131 @@
 n a 
-d
+D
 ouble 
-in range
+value, representing the sentiment index for the given Token List.%0A   * This index ranges between
  -1.0
+0 (sad)
  and 1.0
 (Sad
@@ -1498,41 +1498,31 @@
  1.0
-(Saddest to Happiest
+0 (happy)
 , 0.0
+0
  is a ne
 utra
@@ -1517,18 +1517,18 @@
  is a ne
-u
 t
+u
 ral scor
@@ -1528,18 +1528,16 @@
 al score
-).
 %0A   */%0A 

improve TokenScorer javadoc