/**
  * Tests the methods created above.
  *
  * @param args
  */
 public static void main(String[] args) {
   SpellChecker newChecker = new SpellChecker();
   newChecker.readDictionaryFile();
   newChecker.spellCheck();
   System.out.println("Number of misspelled words: " + newChecker.notFoundWords);
   System.out.println("Number of correct spelled words: " + newChecker.foundWords);
   System.out.println(
       "Number of misspelled words comparisons: " + newChecker.wordsNotFoundComparison);
   System.out.println(
       "Number of correct spelled words comparisons: " + newChecker.wordsFoundComparison);
   System.out.println(
       "The average number of comparisons for words "
           + "found: "
           + (double) newChecker.wordsFoundComparison / newChecker.foundWords);
   System.out.println(
       "The average number of comparisons for words not"
           + " found: "
           + (double) newChecker.wordsNotFoundComparison / newChecker.notFoundWords);
 }
Esempio n. 2
0
  public void reversePairs() {
    String firstWord;
    String secondWord;

    for (int i = 0; i < arrayOfLines.length; i++) {
      String line = arrayOfLines[i];
      String[] localWordsOnLineArray = stringToElements(line, i);

      for (int j = 0; j < localWordsOnLineArray.length - 1; j++) {
        firstWord = localWordsOnLineArray[j];
        secondWord = localWordsOnLineArray[j + 1];

        // if both words are in the dictionary then swap them
        if (checker.checkWord(firstWord) && checker.checkWord(secondWord)) {
          localWordsOnLineArray[j + 1] = firstWord;
          localWordsOnLineArray[j] = secondWord;
          j++; // increment to prevent accidental swapping of pairs
        }
      }
      arrayOfLines[i] = elementsToString(localWordsOnLineArray);
    } // for i
  } // reverse pairs()
Esempio n. 3
0
  public void countWordsFunc() {
    for (int i = 0; i < arrayOfLines.length; i++) {
      String line = arrayOfLines[i];
      String[] localWordsOnLineArray = stringToElements(line, i);

      for (String word : localWordsOnLineArray) {
        if (checker.checkWord(word)) {
          // increase the count of the word found in the wordCountMap
          Integer count = wordCountMap.get(word);
          // if it's the first time the word is found make it 1, else count++
          wordCountMap.put(word, (count == null) ? 1 : count + 1);
        }
      } // for words on the line
    } // for amount of lines
  } // countWordsFunc()