Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.nio.charset.Charset;
- import java.util.HashSet;
- import java.util.Set;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author ukasz
- */
- public class CorrectSpelling {
- public static void main(String[] args) throws IOException {
- FileInputStream fis = new FileInputStream("C:\\slowa.txt");
- InputStreamReader isr = new InputStreamReader(fis, Charset.forName("UTF-8"));
- Set<String> dictionary = new HashSet<>();
- String input = "w ogródkó rosną hrzan i rzółte ogurki";
- String correct = "";
- String[] words = input.split(" ");
- BufferedReader br = new BufferedReader(isr);
- String line;
- while ((line = br.readLine()) != null) {
- dictionary.add(line);
- }
- for (String s : words) {
- if (s.length() > 1) {
- Set<String> variants = new HashSet<>();
- variants.add(s);
- variants.add(s.replace("ch", "h"));
- variants.add(s.replace("h", "ch"));
- variants.add(s.replace("ó", "u"));
- variants.add(s.replace("u", "ó"));
- variants.add(s.replace("ż", "rz"));
- variants.add(s.replace("rz", "ż"));
- variants.add(s.replace("sz", "rz"));
- variants.add(s.replace("rz", "sz"));
- variants.add(s.replace("ą", "om"));
- variants.add(s.replace("om", "ą"));
- variants.add(s.replace("ą", "on"));
- variants.add(s.replace("on", "ą"));
- //System.out.println(variants);
- for (String str : variants) {
- if (dictionary.contains(str)) {
- //System.out.println(str);
- correct = correct.concat(str + " ");
- }
- }
- } else {
- correct = correct.concat(s + " ");
- }
- }
- System.out.println(correct);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement