Now I have problem about read file and collect data. I wrote script that read file and edit if is follow condition - Just show if found some text - Edit if word contains in dictionary - Edit if word does not contains in dictionary But I stuck in case 3 "Edit if word does not contains in dictionary".
This is my script package howtoreadthai;
import static com.sun.org.apache.xalan.internal.lib.NodeInfo.lineNumber;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.util.StringTokenizer;
public class HowToReadThai {
public static void main(String[] args) throws IOException {
String st1 = null, st2 = null,st3 = null, rR1, rR2, sCurrentLine = null,A,B = null,C = null;
int line = 0;
// int line;
// read input file
try (BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\DELL\\Desktop\\sample.txt"))) {
//String sCurrentLine;
while ((sCurrentLine = br.readLine()) != null) {
// System.out.println(sCurrentLine);
if (sCurrentLine.contains("Seikatsu") || sCurrentLine.contains("EOS") || sCurrentLine.isEmpty()||sCurrentLine.contains("PUNC")) {
System.out.println(sCurrentLine);
} else {
StringTokenizer st = new StringTokenizer(sCurrentLine);
st1 = st.nextToken("\t");
st2 = st.nextToken("\t");
//read reference file
try (BufferedReader br2 = new BufferedReader(new FileReader("C:\\Users\\DELL\\Desktop\\wordReadThai_BK"))) {
String readRef;
while ((readRef = br2.readLine()) != null) {
// System.out.println(sCurrentLine);
StringTokenizer rR = new StringTokenizer(readRef);
rR1 = rR.nextToken("\t");
rR2 = rR.nextToken("\t");
if (st1.equalsIgnoreCase(rR1)) {
B = st1 + "\t" + st2 + "\t" + rR2;
System.out.println(B);
C=br.readLine();
break;
// write=st1 + "\t" + st2 + "\t" + rR2
}
else {System.out.println(sCurrentLine); break; }
}
} catch (IOException e) {
e.printStackTrace();
} //end read reference
}// end else of line checking
} //end read input file
} catch (IOException e) {
e.printStackTrace();
}
}
}
And this is file that script read
00003 Se1\A-A_\000090\ja\\Th\\ [c]
Sawatdee VACT
Krab JSBR
Phom XVMM
pen VSTA
newbie FIXV
khonf VSTA
PUNC
Java JSBR
Krab DIBQ
EOS
And This is dictionary
Sawatdee Sa wat dee
Krab krab
Phom phom
My expect result is adding word from 2 column from dictionary into input file and show "NEW_WORD" if this word is not in dictionary.
00003 Se1\A-A_\000090\ja\\Th\\ [c]
Sawatdee VACT Sa wat dee
Krab JSBR krab
Phom XVMM phom
pen VSTA NEW_WORD
newbie FIXV NEW_WORD
khonf VSTA NEW_WORD
PUNC
Java JSBR NEW_WORD
Krab DIBQ NEW_WORD
EOS
I try to create condition for third case, but it seem "else condition" does not work. It read whole dictionary and show result that not edited until read end of file and when in put 'break', it skip it(no NEW_WORD line show).
Could you mind to give me some idea/logic or give me some example. Thank you in advance.
Aucun commentaire:
Enregistrer un commentaire