import java.io.*;
public class pro{
int s,sx,tx,datanumber,articlenumber;
String[] data=new String[50000];
String[] dic=new String[50000];
String[][] word=new String[5000][5000];
int[][] nword=new int[5000][5000];
int[] wordnumber=new int[5000];
int xlong,h,dicnumber;
String file;
int n,sxs;
public static void main(String[] args){
pro test=new pro();
}
pro(){
readfile("lib.txt");
for(s=1;s<datanumber+1;s++){
dic[s]=data[s];
}
dicnumber=datanumber;
for (n=2;n<901;n++){
file="data/";
file=file+n;
file=file+".txt";
readfile(file);
articlenumber=datanumber;
for(s=1;s<datanumber+1;s++){
String[] x=data[s].split(",");
xlong=x.length;
wordnumber[s]=xlong;
for(sx=1;sx<xlong+1;sx++){
word[s][sx]=x[sx-1];
}
}
for(s=1;s<datanumber+1;s++){
xlong=wordnumber[s];
for(sx=1;sx<xlong+1;sx++){
sxs=0;
for(tx=1;tx<dicnumber+1;tx++){
if(word[s][sx].equals(dic[tx]))sxs=tx;
}
nword[s][sx]=sxs;
}
}
file="ndata/";
file=file+n;
file=file+".txt";
writefile(file);
}
}
void writefile(String file){
try{
PrintWriter pw = new PrintWriter
(new BufferedWriter(new FileWriter(file)));
for(s=1;s<articlenumber+1;s++){
for(sx=1;sx<wordnumber[s];sx++){
pw.print(nword[s][sx]);
pw.print(",");
}
sx=wordnumber[s];
pw.println(nword[s][sx]);
}
System.out.println("ファイルに書きこみました。");
pw.close();
}
catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
void readfile(String file){
String str;
BufferedReader br;
int s;
s=0;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file),"SJIS"));
while((str = br.readLine()) != null) {
s=s+1;
data[s]=str;
}
br.close();
} catch (IOException e) {System.out.println(e);}
datanumber=s;
}
}
最終更新:2011年06月13日 23:51