import java.io.*;
public class report{
String[] data=new String[50000];
String[] dic=new String[50000];
String[][] word=new String[500][10000];
int[][] nword=new int[500][10000];
String[] xml=new String[20000];
String str,file;
int[] wordnumber=new int[500];
int s,sx,datanumber,xmlnumber;
int dicnumber,page,dx,dxs;
public static void main(String[] args){
report test=new report();
}
report(){
dicnumber=0;
readfile("dic.txt");
dicnumber=datanumber;
for(s=1;s<dicnumber+1;s++){
dic[s]=data[s];
}
for(page=150;page<200;page++){
file="pdata/";
file=file+page;
file=file+".txt";
readfile(file);
for(s=1;s<datanumber+1;s++){
str=data[s];
xymaker(str);
for(sx=1;sx<xmlnumber+1;sx++){
word[s][sx]=xml[sx];
}
wordnumber[s]=xmlnumber;
}
for(s=1;s<datanumber+1;s++){
for(sx=1;sx<wordnumber[s]+1;sx++){
str=word[s][sx];
dxs=0;
for(dx=1;dx<dicnumber+1;dx++){
if(str.equals(dic[dx]))dxs=dx;
}
nword[s][sx]=dxs;
}
}
file="nword/";
file=file+page;
file=file+".txt";
writefile(file);
}
}
void writefile(String file){
int s,sx;
try{
PrintWriter pw = new PrintWriter
(new BufferedWriter(new FileWriter(file)));
for(s=1;s<datanumber+1;s++){
for(sx=1;sx<wordnumber[s];sx++){
pw.print("<");
pw.print(nword[s][sx]);
pw.print(">");
}
sx=wordnumber[s];
pw.print("<");
pw.print(nword[s][sx]);
pw.println(">");
}
System.out.println("ファイルに書きこみました。");
pw.close();
}
catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
void xymaker(String str){
int sx,p1;
int[] x=new int[10000];
int[] y=new int[10000];
sx=1;
p1=str.indexOf("<");
x[1]=p1;
while(p1>-1){
p1=str.indexOf("<",p1+1);
if(p1>0)sx=sx+1;
if(p1>0)x[sx]=p1;
}
xmlnumber=sx;
for(sx=1;sx<xmlnumber+1;sx++){
y[sx]=str.indexOf(">",x[sx]);
}
for(sx=1;sx<xmlnumber+1;sx++){
xml[sx]=str.substring(x[sx]+1,y[sx]);
}
}
void readfile(String file){
String str;
BufferedReader br;
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年07月04日 15:06