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

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Represents a Phrase.
 * Provides methods to create a Phrase and get its information.
 */
public class Phrase {

  /**
   * Stores the text content of this Phrase.
   */
  private String text;

  /**
   * Wether the text ends with a question mark.
   */
  private boolean question;

  /**
   * Lists the tokens extracted from this Phrase.
   */
  private List<Token> tokens = new ArrayList<>();

  /**
   * Constructs a Phrase, using the String provided by the user.
   * @param str The phrase to be created
   */
  public Phrase(String str) {
    text = str;
    tokens = Token.tokenize(str);
    question = str.charAt(str.length() - 1) == '?';
  }

  /**
   * Returns {@code true} if the content is a question, {@code false} otherwise.
   */
  public boolean isQuestion() {
    return question;
  }

  /**
   * Gets the text content of this Phrase.
   */
  public String getText() {
    return text;
  }

  /**
   * Returns the list of tokens extracted from this Phrase.
   */
  public List<Token> getTokens() {
    return new ArrayList<Token>(tokens);
  }

  /**
   * Returns a String representation of this Phrase in the form [text, tokens].
   */
  @Override
  public String toString() {
    return "[" + text + ", " + tokens + "]";
  }

  /**
   * Checks whether this Phrase equals to the given Object.
   * @param other the other Phrase to be compared against
   * @return {@code true} if this Phrase equals the other Phrase;
   *         {@code false} otherwise
   */
  @Override
  public boolean equals(Object other) {
    if (other == this) {
      return true;
    }
    if (other == null || other.getClass() != this.getClass()) {
      return false;
    }
    Phrase that = (Phrase) other;
    return this.text.equals(that.text) && this.tokens.equals(that.tokens);
  }

  /**
   * Returns the HashCode for this Phrase.
   * The HashCode depends on the HashCode of the content and its tokens.
   */
  @Override
  public int hashCode() {
    return Objects.hash(text, tokens);
  }

  /**
   * Extracts phrases from an input text, splitting it by punctuation.
   * @param input the text to be splitted in phrases
   * @return a List containing all the phrases of the given text.
   */
  public static List<Phrase> extract(String input) {
    List<String> splitted = LangUtils.splitByPuntaction(input);
    List<Phrase> phrases = new ArrayList<>(splitted.size());
    splitted.forEach(s -> phrases.add(new Phrase(s)));
    return phrases;
  }
}

@@ -143,16 +143,139 @@
 Phrase.%0A
+ * A Phrase is a text that can be splitted in different Tokens.%0A * A Phrase can be interpreted as a question or an answer.%0A
  * Provi
@@ -296,17 +296,19 @@
  create 
-a
+the
  Phrase 
@@ -332,16 +332,81 @@
 mation.%0A
+ * @see  com.github.bot.curiosone.core.nlp.Token The Token Class%0A
  */%0Apubl
@@ -642,32 +642,99 @@
 om this Phrase.%0A
+   * @see  com.github.bot.curiosone.core.nlp.Token The Token Class%0A
    */%0A  private 
@@ -857,19 +857,33 @@
  @param 
+ 
 str
+%0A   *        
  The phr
@@ -1054,23 +1054,24 @@
 **%0A   * 
-R
+@r
 eturn
-s
+ 
  %7B@code 
@@ -1210,12 +1210,16 @@
   * 
-Gets
+@return 
  the
@@ -1311,31 +1311,32 @@
 %0A  /**%0A   * 
-R
+@r
 eturn
-s
+ 
  the list of
@@ -1469,23 +1469,24 @@
 **%0A   * 
-R
+@r
 eturn
-s
+ 
  a Strin
@@ -1720,21 +1720,35 @@
  @param 
+ 
 other
+%0A   *        
  the oth
@@ -1793,16 +1793,17 @@
 @return 
+ 
 %7B@code t
@@ -1847,24 +1847,25 @@
 Phrase;%0A   *
+ 
          %7B@c
@@ -2212,14 +2212,17 @@
   * 
-Return
+Calculate
 s th
@@ -2322,16 +2322,58 @@
 tokens.%0A
+   * @return  the HashCode of this Phrase%0A
    */%0A  
@@ -2541,21 +2541,35 @@
  @param 
+ 
 input
+%0A   *        
  the tex
@@ -2609,16 +2609,17 @@
 @return 
+ 
 a List c

improve Phrase javadoc