示例#1
0
  /**
   * Gets the match result from the Graphmaster.
   *
   * @param input
   * @param that
   * @param topic
   * @param userid
   * @param botid
   * @param parser
   * @param timeout whether to control the match attempt with a timeout thread
   */
  private static String getMatchResult(
      String input, String that, String topic, String userid, String botid, TemplateParser parser) {
    // Always show the input path (in any case, if match trace is on).
    if (SHOW_MATCH_TRACE) {
      Trace.userinfo(
          PredicateMaster.get(Globals.getClientNamePredicate(), userid, botid)
              + '>'
              + SPACE
              + input
              + SPACE
              + Graphmaster.PATH_SEPARATOR
              + SPACE
              + that
              + SPACE
              + Graphmaster.PATH_SEPARATOR
              + SPACE
              + topic
              + SPACE
              + Graphmaster.PATH_SEPARATOR
              + SPACE
              + botid);
    }

    // Create a case-insensitive pattern-fitted version of the input.
    String inputIgnoreCase = InputNormalizer.patternFitIgnoreCase(input);

    Match match = null;

    try {
      match = Graphmaster.match(InputNormalizer.patternFitIgnoreCase(input), that, topic, botid);
    } catch (NoMatchException e) {
      Log.userinfo(e.getMessage(), Log.CHAT);
      return EMPTY_STRING;
    }

    if (match == null) {
      Log.userinfo("No match found for input \"" + input + "\".", Log.CHAT);
      return EMPTY_STRING;
    }

    if (SHOW_MATCH_TRACE) {
      Trace.userinfo(LABEL_MATCH + match.getPath());
      Trace.userinfo(LABEL_FILENAME + QUOTE_MARK + match.getFileName() + QUOTE_MARK);
    }

    ArrayList stars = match.getInputStars();
    if (stars.size() > 0) {
      parser.setInputStars(stars);
    }

    stars = match.getThatStars();
    if (stars.size() > 0) {
      parser.setThatStars(stars);
    }

    stars = match.getTopicStars();
    if (stars.size() > 0) {
      parser.setTopicStars(stars);
    }

    String template = match.getTemplate();
    String reply = null;

    try {
      reply = parser.processResponse(template);
    } catch (ProcessorException e) {
      // Log the error message.
      Log.userinfo(e.getMessage(), Log.ERROR);

      // Set response to empty string.
      return EMPTY_STRING;
    }

    // Record activation, if targeting is in use.
    // Needs review in light of multi-bot update
    if (USE_TARGETING) {
      Nodemapper matchNodemapper = match.getNodemapper();
      if (matchNodemapper == null) {
        Trace.devinfo("Match nodemapper is null!");
      } else {
        Set activations = (Set) matchNodemapper.get(Graphmaster.ACTIVATIONS);
        if (activations == null) {
          activations = new HashSet();
        }
        String path =
            match.getPath()
                + SPACE
                + Graphmaster.PATH_SEPARATOR
                + SPACE
                + inputIgnoreCase
                + SPACE
                + Graphmaster.PATH_SEPARATOR
                + SPACE
                + that
                + SPACE
                + Graphmaster.PATH_SEPARATOR
                + SPACE
                + topic
                + SPACE
                + Graphmaster.PATH_SEPARATOR
                + SPACE
                + botid
                + SPACE
                + Graphmaster.PATH_SEPARATOR
                + SPACE
                + reply;
        if (!activations.contains(path)) {
          activations.add(path);
          match.getNodemapper().put(Graphmaster.ACTIVATIONS, activations);
          Graphmaster.activatedNode(match.getNodemapper());
        }
      }
    }
    return reply;
  }
示例#2
0
 public String process(int i, XMLNode xmlnode, TemplateParser templateparser)
     throws AIMLProcessorException {
   if (xmlnode.XMLType == 1) return templateparser.getUserID();
   else throw new AIMLProcessorException("<id/> cannot have content!");
 }