package neko;
import tool.*;
import tool.readfile;
import java.io.*;
import java.io.File;
public class pro {
int s,datanumber;
String[] data=new String[5000];
String[] subdata=new String[5000];
String[] name=new String[5000];
String[] wiki=new String[5000];
String[] dic_name=new String[5000];
String[] dic_wiki=new String[5000];
String[] dic_code=new String[5000];
String[] code=new String[5000];
int number;
String[] memo=new String[500000];
public static void main(String[] args) {
pro t=new pro();
}
pro(){
File f=new File("gdata");
String[] ff=f.list();
int tx=0;
int den=0;
for(den=0;den<ff.length;den++){
readfile sub3=new readfile();
sub3.makedata("gdata/"+ff[den],"UTF-8");
data=sub3.data;
datanumber=sub3.datanumber;
for(s=1;s<datanumber+1;s++){
String[] x=data[s].split(",");
name[s]=x[1];
wiki[s]=x[2];
}
int sx;
int dicnumber=0;
for(s=1;s<datanumber+1;s++){
int h=0;
for(sx=1;sx<dicnumber+1;sx++){
if(name[s].equals(dic_name[sx]))h=100;
}
if(h<50)dicnumber=dicnumber+1;
if(h<50)dic_name[dicnumber]=name[s];
if(h<50)dic_wiki[dicnumber]=wiki[s];
}
int tr;
for(tr=1;tr<dicnumber+1;tr++){
dic_code[tr]="";
if(dic_wiki[tr].length()>0){
String urlx="https://ja.wikipedia.org"+dic_wiki[tr];
getdata sub=new getdata();
sub.makedata(urlx,"UTF-8");
subdata=sub.data;
number=sub.datanumber;
String str="";
for(s=1;s<number+1;s++){
if(subdata[s].indexOf("wgArticleId")>-1)str=subdata[s];
}
int p1=str.indexOf("wgArticleId");
p1=str.indexOf(":",p1);
int p2=str.indexOf(",",p1);
dic_code[tr]=str.substring(p1+1,p2);
}
}
String yy=ff[den].replace(".txt","");
System.out.println(yy);
for(s=1;s<datanumber+1;s++){
code[s]="";
for(sx=1;sx<dicnumber+1;sx++){
if(name[s].equals(dic_name[sx]))code[s]=dic_code[sx];
}
tx=tx+1;
memo[tx]=yy+","+data[s]+","+code[s];
}
}
number=tx;
writexml("s.csv");
}
void writexml(String file){
int s,sx;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
for(s=1;s<number+1;s++){
pw.println(memo[s]);
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
}
最終更新:2017年10月13日 04:08