Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- LinearProbingHashST<String, String> st = new LinearProbingHashST<String, String>();
- // reads the text file with collections of misspellings and corresponding
- // correct spelling of words and puts into Symbol table
- In dictionary = new In(args[0]);
- while (dictionary.hasNextLine()) {
- String misspelled = dictionary.readString();
- String corrected = dictionary.readLine().trim();
- st.put(misspelled, corrected);
- }
- // reads the second file of text with eventual misspellings and replaces
- // these with the correct ones
- In text = new In(args[1]);
- while (text.hasNextLine()) {
- String row = text.readLine();
- String[] wordCollection = row.split(" ");
- for (int i = 0; i < wordCollection.length; i++) {
- if (st.contains(wordCollection[i])) System.out.print(st.get(wordCollection[i]) + " ");
- else System.out.print(wordCollection[i] + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement