關於HashTable

將HashTable和HashTableDemo的程式碼改得更有用,修正過的程是必須讀進一個文字檔,

並分析每一個字,看是否它在Hash table,如果不是,output the line

number and word of the potentially misspelled word.捨棄任何標點

符號在原始的文字檔,使用words.txt為基本的hash table dictionary,

注意有些字是大寫的。測試你的spell checker在一個短的text document.

words.text

HashTable

HashTableDemo

請各位高手幫幫忙啊!!

有些英文怕翻的讓大大看不懂

所以就打原文

希望可以幫幫忙

感激不盡^^

Update:

HashTable and HashTableDemo provide the beginnings of spell checker.

Refine the program to make it useful. The modified progeam should

read in a text file, parse each word, see if it is in the hash table,

Update 2:

and, if not, output the line number and word of the potentially

misspelled word. Discard any punctuation in the original text file.

Use the word.txt file as the basis for the hash table dictionary.

The file contains 45407 common words and names in the English

Update 3:

language. Note that some words are capitalized. Test your spell

checker on a short text document.

Update 4:

感激=ˇ=

1 Answer

Rating
  • 1 decade ago
    Favorite Answer

    還是有點看不懂題目的意思,可以直接貼原文嗎?

    2008-06-19 08:32:57 補充:

    看完程式碼後,發現你少提供了「LinkedList2」這個類別。

    下面是對於LinkedList2的說明(從程式碼的註解摘錄下來):

    // Uses the generic LinkedList2 class from Display 15.7

    2008-06-20 08:38:19 補充:

    我將HashTableDemo照題意去改寫,你看看這是不是你要的吧!

    import java.io.*;

    public class HashTableDemo

    {

    public static void main(String[] args) {

    System.out.println("Read word from 'words.txt',Please wait...");

    try {

    BufferedReader br = new BufferedReader(new FileReader(new File("words.txt")));

    LineNumberReader lr = new LineNumberReader(new FileReader(new File("test.txt")));

    String line = ""; HashTable ht = new HashTable();

    while (true) {//取出words.txt內的單字並放入HashTable

    if ((line=br.readLine())==null) break;

    ht.put(line.trim());

    }

    System.out.println("Read complete!!!");

    StringBuilder sb = new StringBuilder();

    while (true) {

    if ((line=lr.readLine())==null) break;

    char cs[] = line.toCharArray();

    for (char c:cs) {

    if (Character.isLetter(c)) sb.append(c);//過濾掉非英文的字元

    }

    if (!ht.containsString(sb.toString())) {//如果不在HashTable當中,就列印行號及字串

    System.out.print("Line Number:"+lr.getLineNumber()+",\t");

    System.out.println("Potentially misspelled word:"+sb.toString());

    }

    sb.delete(0,sb.length());

    }

    } catch (IOException ie) {;

    ie.printStackTrace();

    }

    }

    }

    2008-06-20 08:39:05 補充:

    attack,

    Attech,

    attempt

    Anger,

    argument

    Aunt,

    Austrian,

    Author

    authority,

    Autograph.

    Source(s): Zodiac, test.txt的內容
Still have questions? Get your answers by asking now.