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

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

/**
 * Represents a phrase.
 */
public class Phrase {
  /** The string representation of the phrase. */
  private String text;

  /** True if the phrase ends with a question mark. */
  private boolean question;

  /** The list of tokens extracted from the 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) == '?';
  }

  /**
   * Checks if this phrase is a question.
   *
   * @return {@code true} if this original string contains a question mark at
   *         the end.
   *         {@code false} otherwise
   */
  public boolean isQuestion() {
    return question;
  }

  /**
   * Gets the string representation of the phrase.
   *
   * @return the string representation of the phrase
   */
  public String getText() {
    return text;
  }

  /**
   * The list of tokens extracted from the phrase.
   *
   * @return the list of tokens extracted from the phrase
   */
  public List<Token> getTokens() {
    return new ArrayList<Token>(tokens);
  }

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

  /**
   * Compares this phrase to the specified object.
   *
   * @param  other the other phrase
   * @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 an integer hash code for this phrase.
   *
   * @return an integer hash code for this phrase
   */
  @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 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;
  }
}

@@ -135,22 +135,86 @@
 sents a 
-phrase
+Phrase.%0A * Provides methods to create a Phrase and get its information
 .%0A */%0Apu
@@ -237,54 +237,62 @@
 e %7B%0A
+%0A
   /**
- The string representation
+%0A   * Stores the text content
  of th
-e p
+is P
 hrase.
+%0A  
  */%0A
@@ -324,27 +324,29 @@
  /**
- True if the phrase
+%0A   * Wether the text
  end
@@ -368,16 +368,19 @@
 on mark.
+%0A  
  */%0A  pr
@@ -409,28 +409,31 @@
 ;%0A%0A  /**
- The list of
+%0A   * Lists the
  tokens 
@@ -449,25 +449,29 @@
  from th
-e p
+is P
 hrase.
+%0A  
  */%0A  pr
@@ -541,17 +541,17 @@
 ructs a 
-p
+P
 hrase, u
@@ -555,25 +555,25 @@
 , using the 
-s
+S
 tring provid
@@ -588,21 +588,16 @@
 e user.%0A
-   *%0A
    * @pa
@@ -787,62 +787,15 @@
   * 
-Checks if this phrase is a question.%0A   *%0A   * @r
+R
 eturn
+s
  %7B@c
@@ -813,89 +813,32 @@
 f th
-is original string contains a question mark at%0A   *         the end.%0A   *        
+e content is a question,
  %7B@c
@@ -849,32 +849,33 @@
 false%7D otherwise
+.
 %0A   */%0A  public 
@@ -947,102 +947,36 @@
 the 
-string representation of the phrase.%0A   *%0A   * @return the string representation
+text content
  of th
-e p
+is P
 hrase
+.
 %0A   
@@ -1043,71 +1043,15 @@
   * 
-The list of tokens extracted from the phrase.%0A   *%0A   * @r
+R
 eturn
+s
  the
@@ -1083,24 +1083,26 @@
  from th
-e p
+is P
 hrase
+.
 %0A   */%0A 
@@ -1206,67 +1206,9 @@
 s a 
-string representation of this phrase.%0A   *%0A   * @return a s
+S
 trin
@@ -1228,25 +1228,25 @@
 ion of this 
-p
+P
 hrase in the
@@ -1265,16 +1265,17 @@
  tokens%5D
+.
 %0A   */%0A 
@@ -1380,58 +1380,62 @@
  * C
-ompares
+hecks whether
  this 
-p
+P
 hrase 
-to the specified o
+equals to the given O
 bject.%0A
-   *%0A
    *
@@ -1442,17 +1442,16 @@
  @param 
- 
 other th
@@ -1458,22 +1458,45 @@
 e other 
-p
+P
 hrase
+ to be compared against
 %0A   * @r
@@ -1518,25 +1518,25 @@
 ue%7D if this 
-p
+P
 hrase equals
@@ -1546,17 +1546,17 @@
 e other 
-p
+P
 hrase;%0A 
@@ -1922,33 +1922,25 @@
 Returns 
-an integer hash c
+the HashC
 ode for 
@@ -1940,25 +1940,25 @@
 de for this 
-p
+P
 hrase.%0A   *%0A
@@ -1960,58 +1960,76 @@
    *
-%0A   * @return an integer hash c
+ The HashCode depends on the HashC
 ode 
-for this phrase
+of the content and its tokens.
 %0A   
@@ -2194,13 +2194,8 @@
 on.%0A
-   *%0A
    *
@@ -2256,16 +2256,38 @@
 @return 
+a List containing all 
 the phra
@@ -2307,16 +2307,17 @@
 ven text
+.
 %0A   */%0A 

improve Phrase javadoc