Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1.  
  2. import java.io.BufferedReader;
  3. import java.io.FileInputStream;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.nio.charset.Charset;
  7. import java.util.HashSet;
  8. import java.util.Set;
  9.  
  10. /*
  11. * To change this license header, choose License Headers in Project Properties.
  12. * To change this template file, choose Tools | Templates
  13. * and open the template in the editor.
  14. */
  15. /**
  16. *
  17. * @author ukasz
  18. */
  19. public class CorrectSpelling {
  20.  
  21. public static void main(String[] args) throws IOException {
  22. FileInputStream fis = new FileInputStream("C:\\slowa.txt");
  23. InputStreamReader isr = new InputStreamReader(fis, Charset.forName("UTF-8"));
  24. Set<String> dictionary = new HashSet<>();
  25.  
  26. String input = "w ogródkó rosną hrzan i rzółte ogurki";
  27. String correct = "";
  28. String[] words = input.split(" ");
  29. BufferedReader br = new BufferedReader(isr);
  30. String line;
  31. while ((line = br.readLine()) != null) {
  32. dictionary.add(line);
  33. }
  34.  
  35. for (String s : words) {
  36. if (s.length() > 1) {
  37. Set<String> variants = new HashSet<>();
  38. variants.add(s);
  39. variants.add(s.replace("ch", "h"));
  40. variants.add(s.replace("h", "ch"));
  41. variants.add(s.replace("ó", "u"));
  42. variants.add(s.replace("u", "ó"));
  43. variants.add(s.replace("ż", "rz"));
  44. variants.add(s.replace("rz", "ż"));
  45. variants.add(s.replace("sz", "rz"));
  46. variants.add(s.replace("rz", "sz"));
  47. variants.add(s.replace("ą", "om"));
  48. variants.add(s.replace("om", "ą"));
  49. variants.add(s.replace("ą", "on"));
  50. variants.add(s.replace("on", "ą"));
  51. //System.out.println(variants);
  52. for (String str : variants) {
  53. if (dictionary.contains(str)) {
  54. //System.out.println(str);
  55. correct = correct.concat(str + " ");
  56. }
  57. }
  58. } else {
  59. correct = correct.concat(s + " ");
  60. }
  61. }
  62. System.out.println(correct);
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement