Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. public static void main(String[] args) {
  2.  
  3. LinearProbingHashST<String, String> st = new LinearProbingHashST<String, String>();
  4.  
  5. // reads the text file with collections of misspellings and corresponding
  6. // correct spelling of words and puts into Symbol table
  7. In dictionary = new In(args[0]);
  8.  
  9. while (dictionary.hasNextLine()) {
  10. String misspelled = dictionary.readString();
  11.  
  12. String corrected = dictionary.readLine().trim();
  13.  
  14. st.put(misspelled, corrected);
  15. }
  16.  
  17. // reads the second file of text with eventual misspellings and replaces
  18. // these with the correct ones
  19. In text = new In(args[1]);
  20. while (text.hasNextLine()) {
  21. String row = text.readLine();
  22.  
  23. String[] wordCollection = row.split(" ");
  24.  
  25.  
  26. for (int i = 0; i < wordCollection.length; i++) {
  27. if (st.contains(wordCollection[i])) System.out.print(st.get(wordCollection[i]) + " ");
  28. else System.out.print(wordCollection[i] + " ");
  29. }
  30.  
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement