/** * *********************************************************** * * @param patterns * @param recursiveExtractions * @param fragment - for recursion * <p>will pay he will immediately pay the bill or pay fine * <p>Distance method populates the matrix pattern/word with Trues at hit. */ public Distance( String[] patterns, List<RecursiveExtraction> recursiveExtractions, AnalysisFragment fragment, boolean verbatim, boolean caseSensitive) { List<Word> words = fragment.getWords(); this.recursiveExtractions = recursiveExtractions; hit = new boolean[patterns.length][words.size()]; this.words = words; this.patterns = patterns; for (int p = 0; p < patterns.length; p++) { for (int w = 0; w < words.size(); w++) { if (words.get(w).matches(patterns[p], verbatim, caseSensitive)) hit[p][w] = true; } } // display(); }
/** * ******************************************************************* * * <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; }