-
-
Save daohoangson/3845318 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e: em | |
a: anh | |
b h: bây giờ | |
b: nhưng | |
h: giờ | |
k: không | |
j`: gì | |
dc: được | |
uh: ừ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Scanner; | |
public class SpellChecker { | |
public static String[] results; | |
public boolean loadRuleBase(String filename){ | |
try{ | |
File inFile = new File(filename); | |
FileReader fileReader = new FileReader(inFile); | |
BufferedReader reader = new BufferedReader(fileReader); | |
ArrayList<String> list = new ArrayList<String>(); | |
String line = null; | |
int LineNumber = -1; | |
while((line = reader.readLine()) != null){ | |
LineNumber++; | |
String[] tmp = line.split(": "); | |
list.add(tmp[0]); | |
list.add(tmp[1]); | |
} | |
results = new String[(LineNumber+1)*2]; | |
list.toArray(results); | |
reader.close(); | |
return true; | |
} | |
catch (Exception e){ | |
e.printStackTrace(); | |
return false; | |
} | |
} | |
public String fix(String input){ | |
String[] tmp = input.split(" "); | |
for(int i=0; i<tmp.length; i++) | |
for(int k=0; k<results.length; k++){ | |
// if(tmp[i].equals(results[i])== true) { -- sondh: phải so sánh với results[k] chứ không phải results[i] | |
if(tmp[i].equals(results[k])== true) { | |
// results[k+1]=tmp[i]; -- sondh: sao lại gán tmp[i] vào results[k+1]? Phải ngược lại chứ... | |
tmp[i] = results[k+1]; | |
break; | |
} | |
} | |
//Dua mang tmp[] thanh string | |
String str = Arrays.toString(tmp); | |
str=str.substring(1,str.length()-1).replaceAll(",",""); // loai bo dau [ va , | |
return str; | |
} | |
public static void main(String[] args) { | |
System.out.println("Nhap mot xau bat ki: "); | |
Scanner input = new Scanner(System.in); | |
String a = input.nextLine(); | |
SpellChecker x = new SpellChecker(); | |
x.loadRuleBase("rule.txt"); | |
System.out.print(x.fix(a)); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment