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

import com.github.bot.curiosone.core.nlp.Phrase;
import com.github.bot.curiosone.core.nlp.Sentence;

import java.io.IOException;
import java.util.Optional;

/**
 * Manages the Brain of the Curiosone.
 * Contains utility methods to conversate, compute and/or randomly generate an answer to a given
 * sentence.
 */
public class Brain {

  /**
   * Private Constructor.
   */
  private Brain() {}

  /**
   * Answers to a conversational message.
   * @param phrase the message to generate the response to
   * @return an Optional instance, containing the response, if the message needs a conversational
   *         answer.
   */
  public static Optional<BrainResponse> conversate(Phrase phrase) {
    Optional<BrainResponse> answ = Conversation.getAnswer(phrase);
    return answ.isPresent() ? answ : BadWords.getAnswer(phrase);
  }

  /**
   * Generates a random response.
   * @param  phrase the message to generate the response to
   * @return a BrainResponse instance, representing the random response.
   */
  public static BrainResponse random(Phrase phrase) {
    return RandomAnswer.getAnswer(phrase);
  }

  /**
   * Answers to a sentence.
   * This method is able to undestrad whether the Curiosone is responding to an affirmation or a
   * question.
   * @param  sentence the sentence to generate the response to
   * @param  scope the scope of the conversation
   * @return an Optional instance, containing the response for the input sentence
   */
  public static Optional<BrainResponse> compute(Sentence sentence, String scope) {
    return sentence.isQuestion()
        ? Question.getAnswer(sentence, scope) : Affirmation.getAnswer(sentence, scope);
  }
}

@@ -344,25 +344,163 @@
 iven%0A * 
-sentence.
+Sentence.%0A * @see  com.github.bot.curiosone.core.nlp.Phrase The Phrase Class%0A * @see  com.github.bot.curiosone.core.nlp.Sentence The Sentence Class
 %0A */%0Apub
@@ -638,22 +638,36 @@
  @param 
+ 
 phrase
+%0A   *        
  the mes
@@ -704,32 +704,33 @@
 to%0A   * @return 
+ 
 an Optional inst
@@ -815,15 +815,299 @@
     
+ 
 answer.
+ The response is encapsulated in a BrainResponse instance.%0A   * @see  com.github.bot.curiosone.core.nlp.Phrase The Phrase Class%0A   * @see  %3Ca href=%22https://goo.gl/sWfXyh%22%3EThe Optional Class%3C/a%3E%0A   * @see  com.github.bot.curiosone.core.extraction.BrainResponse The BrainResponse Class
 %0A   
@@ -1373,16 +1373,29 @@
   phrase
+%0A   *        
  the mes
@@ -1440,16 +1440,17 @@
 @return 
+ 
 a BrainR
@@ -1486,24 +1486,36 @@
 g the random
+ly generated
  response.%0A 
@@ -1509,24 +1509,183 @@
 d response.%0A
+   * @see  com.github.bot.curiosone.core.nlp.Phrase The Phrase Class%0A   * @see  com.github.bot.curiosone.core.extraction.BrainResponse The BrainResponse Class%0A
    */%0A  publ
@@ -1947,16 +1947,29 @@
 sentence
+%0A   *        
  the sen
@@ -2020,16 +2020,29 @@
 m  scope
+%0A   *        
  the sco
@@ -2077,16 +2077,17 @@
 @return 
+ 
 an Optio
@@ -2138,24 +2138,249 @@
 e input 
-sentence
+Sentence%0A   * @see  com.github.bot.curiosone.core.nlp.Phrase The Phrase Class%0A   * @see  %3Ca href=%22https://goo.gl/sWfXyh%22%3EThe Optional Class%3C/a%3E%0A   * @see  com.github.bot.curiosone.core.extraction.BrainResponse The BrainResponse Class
 %0A   */%0A 

improve Brain javadoc