Exemple #1
0
  public void appendWildcard(int begWord, int endWord) {

    begWord = begWord - 1;
    endWord = endWord - 1;

    int topicLength = topic.getNormalizedWordsSize();

    // Wildcard from topic.
    if (begWord < topicLength) appendWildcard(Section.TOPIC, topic, begWord, endWord);

    begWord = begWord - (topicLength + 1);
    endWord = endWord - (topicLength + 1);

    int thatLength = that.getNormalizedWordsSize();

    // Wildcard from that.
    if (begWord <= thatLength) {
      appendWildcard(Section.THAT, that, begWord, endWord);
      return;
    }

    begWord = begWord - (thatLength + 1);
    endWord = endWord - (thatLength + 1);

    // Wildcard from pattern.
    if (begWord <= pattern.getNormalizedWordsSize())
      appendWildcard(Section.PATTERN, pattern, begWord, endWord);
  }
Exemple #2
0
  public Match(AliceBot callback, Sentence pattern, Sentence that, Sentence topic) {
    sections.put(Section.TOPIC, new ArrayList<String>(2)); // Topic 	wildcards.
    sections.put(Section.THAT, new ArrayList<String>(2)); // That 	wildcards.
    sections.put(Section.PATTERN, new ArrayList<String>(2)); // Pattern wildcards.

    this.callback = callback;
    this.pattern = pattern;
    this.that = that;
    this.topic = topic;
    setUpMatchPath(
        pattern.getNormalizedWords(), that.getNormalizedWords(), topic.getNormalizedWords());
  }
Exemple #3
0
 private void appendWildcard(Section section, Sentence source, int beginIndex, int endIndex) {
   if (beginIndex == endIndex) sections.get(section).add(0, "");
   else {
     try {
       sections
           .get(section)
           .add(0, source.getOriginalFromBetweenNormalizedWords(beginIndex, endIndex));
     } catch (RuntimeException exception) {
       throw new RuntimeException(
           "Source: {\""
               + source.getOriginal()
               + "\", \""
               + source.getNormalized()
               + "\"}\n"
               + "Begin Index: "
               + beginIndex
               + "\n"
               + "End Index: "
               + endIndex,
           exception);
     }
   }
 }