Created
October 5, 2012 12:50
-
-
Save anonymous/3839649 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
package SpellCheckerTest; | |
import java.io.*; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
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) { | |
results[k+1]=tmp[i]; | |
} | |
} | |
//Dua mang tmp[] thanh string | |
String str = Arrays.toString(tmp); | |
str=str.substring(1,str.length()-1).replaceAll(",",""); // loai bo dau [ va , | |
return str; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment