アットウィキロゴ

辞書作成XX

import java.io.*;

public class dic{

String[] data=new String[50000];
String[] word=new String[50000];
String[] dic=new String[50000];
String[] xml=new String[50000];
int s,sx,datanumber,articlenumber;
int xmlnumber,wordnumber,dicnumber;
String file,str;
int page,n,h;

public static void main(String[] args){
dic test=new dic();
}

dic(){        

dicnumber=0;

for(page=100;page<150;page++){

if(page>1)readfile("dic.txt");
if(page>1)dicnumber=datanumber;
for(s=1;s<dicnumber+1;s++){
dic[s]=data[s];
}

file="pdata/";
file=file+page;
file=file+".txt";

readfile(file);

n=0;
for(s=1;s<datanumber+1;s++){
str=data[s];
xymaker(str);
for(sx=1;sx<xmlnumber+1;sx++){
n=n+1;
word[n]=xml[sx];
}
}

wordnumber=n;

System.out.println(wordnumber);

for(s=1;s<wordnumber+1;s++){
h=0;
for(sx=1;sx<dicnumber+1;sx++){
if(word[s].equals(dic[sx]))h=100;
}
if(h<50)dicnumber=dicnumber+1;
if(h<50)dic[dicnumber]=word[s];
}

System.out.println(dicnumber);

writefile();

}


}

void writefile(){

int sx;

try{
PrintWriter pw = new PrintWriter
(new BufferedWriter(new FileWriter("dic.txt")));

for(sx=1;sx<dicnumber+1;sx++){                                              
pw.println(dic[sx]);                                                              
}

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日 01:53