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;

/**
 * Description.
 */
public class Brain {
  /**
   * Private Constructor.
   */
  private Brain() {}

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

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

  /**
   * Response to something.
   * @param  sentence the sentence to generate the response to
   * @param  scope the scope of the conversation
   */
  public static Optional<BrainResponse> compute(Sentence sentence, String scope) {
    if (sentence.isQuestion()) {
      return Question.getAnswer(sentence, scope);
    }
    return Affirmation.getAnswer(sentence, scope);
  }
}

@@ -212,19 +212,163 @@
 %0A * 
-Description
+Manages the brain of the Curiosone.%0A * This class contains utility methods to conversate, compute and/or randomly generate an answer to%0A * a given sentence
 .%0A *
@@ -390,16 +390,17 @@
 Brain %7B%0A
+%0A
   /**%0A  
@@ -458,32 +458,31 @@
 %0A  /**%0A   * 
-Response
+Answers
  to a conver
@@ -503,33 +503,32 @@
 ge.%0A   * @param 
- 
 phrase the messa
@@ -563,32 +563,65 @@
 to%0A   * @return 
+an Optional instance, containing 
 the response if 
@@ -616,16 +616,17 @@
 response
+,
  if the 
@@ -655,16 +655,29 @@
 sational
+%0A   *        
  answer.
@@ -822,20 +822,23 @@
 e);%0A    
-if (
+return 
 answ.isP
@@ -849,47 +849,17 @@
 nt()
-) %7B%0A      return answ;%0A    %7D%0A    return
+ ? answ :
  Bad
@@ -907,16 +907,17 @@
 Generate
+s
  a rando
@@ -1001,19 +1001,65 @@
 @return 
-the
+a BrainResponse instance, representing the random
  respons
@@ -1184,29 +1184,29 @@
   * 
-Response to something
+Answers to a sentence
 .%0A  
@@ -1315,16 +1315,98 @@
 rsation%0A
+   * @return an Optional instance, containing the response for the input sentence%0A
    */%0A  
@@ -1494,12 +1494,15 @@
     
-if (
+return 
 sent
@@ -1522,24 +1522,18 @@
 on()
-) %7B
 %0A      
-return
+  ?
  Que
@@ -1568,26 +1568,10 @@
 ope)
-;%0A    %7D%0A    return
+ :
  Aff

improve Brain javadoc and code