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

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

public class Phrase {

  /** Description */
  private String text;

  /** Description */
  private List<Token> tokens = new ArrayList<>();

  /** Description */
  private PhraseType type;

  /**
   * [Phrase description]
   * @param  str [description]
   * @return [description]
   */
  public Phrase(String str) {
    text = str;
    type = PhraseType.get(str);
    tokens = Token.tokenize(str);
  }

  /**
   * [getText description]
   * @return [description]
   */
  public String getText() {
    return text;
  }

  /**
   * [getTokens description]
   * @return [description]
   */
  public List<Token> getTokens() {
    return new ArrayList<Token>(tokens);
  }

  /**
   * [getType description]
   * @return [description]
   */
  public PhraseType getType() {
    return type;
  }

  /**
   * [extract description]
   * @param  input [description]
   * @return [description]
   */
  public static List<Phrase> extract(String input) {
    List<String> phr = LangUtils.splitByPuntaction(input);
    for (int i = 0; i < phr.size(); i++) {
      phr.set(i, LangUtils.removeDuplicatedSpaces(phr.get(i)));
      phr.set(i, LangUtils.expandVerbs(phr.get(i)));
    }

    List<Phrase> phrases = new ArrayList<>(phr.size());
    for (int i = 0; i < phr.size(); i++) {
      Phrase p = new Phrase(phr.get(i));
      phrases.add(p);
    }
    return phrases;
  }

  /**
   * [equals description]
   * @param  object [description]
   * @return [description]
   */
  @Override
  public boolean equals(Object object) {
    if(!(object instanceof Phrase)) {
      return false;
    }
    Phrase t = (Phrase)object;
    return t.text.equals(this.text);
  }

  /**
   * [toString description]
   * @return [description]
   */
  @Override
  public String toString() {
    return "{text:" + text + ", type:" + type + ", tokens:" + tokens + "}";
  }
}

@@ -59,16 +59,21 @@
 va.util.
+Array
 List;%0Aim
@@ -91,105 +91,373 @@
 til.
-ArrayList;%0A%0Apublic class Phrase %7B%0A%0A  /** Description */%0A  private String text;%0A%0A  /** Description
+List;%0A%0A/**%0A* This class represents a phrase.%0A* A phrase has a type (question, answer...) and two different representations:%0A* as String ad as token list.%0A*/%0Apublic class Phrase %7B%0A%0A  /**%0A  * Original string representation of the phrase, provided in input by the user.%0A  */%0A  private String text;%0A%0A  /**%0A  * Tokens extracted from the original phrase.%0A  * @see Token%0A 
  */%0A
@@ -516,20 +516,53 @@
  /**
- Description
+%0A  * Sentence typology.%0A  * @see PhraseType%0A 
  */%0A
@@ -601,33 +601,29 @@
 *%0A  
- 
 * 
-%5BPhrase description%5D%0A 
+Class constructor.%0A
   * 
@@ -633,55 +633,42 @@
 ram 
- 
 str 
-%5Bdescription%5D%0A   * @return %5Bdescription%5D%0A 
+The phrase to be represented.%0A
   */
@@ -797,61 +797,70 @@
 *%0A  
- 
 * 
-%5BgetText description%5D%0A   * @return %5Bdescription%5D%0A 
+Returns the original phrase, provided in input by the user.%0A
   */
@@ -922,63 +922,53 @@
 *%0A  
- 
 * 
-%5BgetTokens description%5D%0A   * @return %5Bdescription%5D%0A 
+Returns the tokens of the original phrase.%0A
   */
@@ -1061,61 +1061,53 @@
 *%0A  
- 
 * 
-%5BgetType description%5D%0A   * @return %5Bdescription%5D%0A 
+Returns phrase type (answer, question...).%0A
   */
@@ -1173,34 +1173,78 @@
 *%0A  
- 
 * 
-%5Bextract description%5D%0A 
+Returns a list containing all the phrases tokenized from the inout.%0A
   * 
@@ -1254,57 +1254,52 @@
 ram 
- 
 input 
-%5Bdescription%5D%0A   * @return %5Bdescription%5D%0A 
+input text to be splitted in phrases.%0A
   */
@@ -1783,94 +1783,231 @@
 *%0A  
- 
 * 
-%5Bequals description%5D
+Compares this Phrase to the specified object. The result is true if and
 %0A  
- 
 * 
-@param  object %5Bdescription%5D%0A   * @return %5Bdescription%5D%0A 
+only if the argument is not null and is a Phrase object that has the same%0A  * text.%0A  * @param object The object to compare this Phrase against.%0A
   */
@@ -2066,16 +2066,17 @@
 %7B%0A    if
+ 
 (!(objec
@@ -2095,16 +2095,34 @@
  Phrase)
+ %7C%7C object == null
 ) %7B%0A    
@@ -2228,62 +2228,58 @@
 *%0A  
- 
 * 
-%5BtoString description%5D%0A   * @return %5Bdescription%5D%0A 
+Returns a String representation of this Phrase.%0A
   */

fix Phrase class codestyle