コード例 #1
0
ファイル: Multiplexor.java プロジェクト: summyfeb12/introtoai
  /**
   * Returns the response to a non-internal input, using a Responder.
   *
   * @param input the "non-internal" (possibly multi-sentence, non-substituted) input
   * @param userid the userid for whom the response will be generated
   * @param botid the botid from which to get the response
   * @param responder the Responder who cares about this response
   */
  public static synchronized String getResponse(
      String input, String userid, String botid, Responder responder) {
    // Get the specified bot object.
    Bot bot = Bots.getBot(botid);

    // Split sentences (after performing substitutions and responder pre-processing).
    ArrayList sentenceList =
        bot.sentenceSplit(bot.applyInputSubstitutions(responder.preprocess(input, HOST_NAME)));

    // Get an iterator on the replies.
    Iterator replies = getReplies(sentenceList, userid, botid).iterator();

    // Start by assuming an empty response.
    String response = EMPTY_STRING;

    // Get an iterator over the input sentences.
    Iterator sentences = sentenceList.iterator();

    // For each input sentence...
    while (sentences.hasNext()) {
      // ...ask the responder to append the reply to the response, and accumulate the result.
      response = responder.append((String) sentences.next(), (String) replies.next(), response);
    }

    // Log the response.
    responder.log(input, response, HOST_NAME, userid, botid);

    // Finally, ask the responder to postprocess the response, and return the result.
    response = responder.postprocess(response);

    // Return the response (may be just EMPTY_STRING!)
    return response;
  }