Ejemplo n.º 1
0
  private boolean isOneOf(Word word, AnalysisFragment fragment, String[] patterns) {

    for (String p : patterns) {

      if (word.matches(p, false, false)) return true;
    }

    return false;
  }
Ejemplo n.º 2
0
  /**
   * *******************************************************************
   *
   * <p>Calculating the actual distance between two words. This is done the following way:
   *
   * <p>- Disregard all words in the pattern, we only count the words between - Add 1 for minor
   * words (like the, a, on etc.) - Add 10 for major words (typically verbs, nouns and adjectives)
   *
   * @param w - first word
   * @param w2 - last word
   * @param fragment - for recursion
   * @param patterns
   * @return
   */
  private int calculateDistance(int w, int w2, AnalysisFragment fragment, String[] patterns) {

    List<Word> words = fragment.getWords();

    int distance = 0;

    // Statement to make pattern sequence irrelevant;
    if (w2 < w) {
      int temp = w;
      w = w2;
      w2 = temp;
    }

    for (int i = w + 1; i < w2; i++) {

      Word word = words.get(i);

      // System.out.println(word.display());
      if (!isOneOf(word, fragment, patterns)) distance += (word.isMinor() ? 1 : 10);
    }

    return distance;
  }