package infobox;
import tool.*;
import java.io.*;
public class pro {
String urlx;
String[] credit=new String[100];
String[][] word=new String[100][100];
int[] wordnumber=new int[100];
int s,number,datanumber;
String[] data=new String[100];
String[] name=new String[500];
String[] link=new String[500];
String str,file;
public static void main(String[] args) {
pro test=new pro();
}
pro(){
readfile sub2=new readfile();
sub2.makedata("data.csv","UTF-8");
data=sub2.data;
datanumber=sub2.datanumber;
for(s=2;s<datanumber+1;s++){
str=data[s];
String[] x=str.split(",");
name[s]=x[0];
link[s]=x[1];
}
for(s=2;s<50;s++){
urlx="http://ja.wikipedia.org"+link[s];
int ch;
check sub7=new check();
ch=sub7.makedata(urlx);
if(ch<50){
infobox sub=new infobox();
sub.makedata(urlx);
credit=sub.credit;
number=sub.number;
word=sub.word;
wordnumber=sub.wordnumber;
System.out.println(s);
file="gdata/"+name[s]+".txt";
writex(file);
}
}
}
void writex(String file){
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
int s,sx;
for(s=1;s<number+1;s++){
for(sx=1;sx<wordnumber[s]+1;sx++){
pw.print(credit[s]);
pw.print(",");
pw.print(sx);
pw.print(",");
pw.println(word[s][sx]);
}
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
}
package infobox;
import tool.*;
public class infobox {
String[] data=new String[5000];
int s,sx,datanumber;
int[] x=new int[5000];
int[] y=new int[5000];
int number;
String[] article=new String[100];
String[] credit=new String[100];
String[] value=new String[5000];
String[][] word=new String[500][100];
int[] wordnumber=new int[500];
void makedata(String urlx){
getdata sub=new getdata();
sub.makedata(urlx, "UTF-8");
data=sub.data;
datanumber=sub.datanumber;
int s1,h,s2;
s1=0;
for(s=1;s<datanumber+1;s++){
h=0;
if(data[s].indexOf("<table class")>-1)h=h+1;
if(data[s].indexOf("infobox")>-1)h=h+1;
if(h==2)s1=s;
}
s2=0;
for(s=s1;s<datanumber+1;s++){
h=0;
if(data[s].indexOf("</table>")>-1)h=h+1;
if(s2<1)h=h+1;
if(h==2)s2=s;
}
sx=0;
for(s=s1+1;s<s2;s++){
if(data[s].indexOf("<tr")>-1)sx=sx+1;
if(data[s].indexOf("<tr")>-1)x[sx]=s;
}
number=sx;
sx=0;
for(s=s1+1;s<s2;s++){
if(data[s].indexOf("</tr")>-1)sx=sx+1;
if(data[s].indexOf("</tr")>-1)y[sx]=s;
}
String str;
int tx;
for(s=1;s<number+1;s++){
s1=x[s];
s2=y[s];
str="";
for(sx=s1;sx<s2+1;sx++){
str=str+data[sx]+"<delta>";
}
article[s]=str;
}
for(s=1;s<number+1;s++){
str=article[s];
str=str.replace("</th","</td");
article[s]=str;
}
for(s=1;s<number+1;s++){
str=article[s];
String[] x=str.split("</td>");
credit[s]=x[0];
if(x.length>1)value[s]=x[1];
}
for(s=1;s<number+1;s++){
str=credit[s];
credit[s]=cleaning(str);
}
for(s=1;s<number+1;s++){
str=value[s];
if(str==null)str="abc";
shuffle(s,str);
}
}
void shuffle(int s,String str){
String strx;
int p1,sx,num;
int[] x=new int[100];
int[] y=new int[100];
String[] cr=new String[100];
sx=0;
p1=str.indexOf("<");
if(p1>-1)sx=sx+1;
if(p1>-1)x[sx]=p1;
while(p1>-1){
p1=str.indexOf("<",p1+1);
if(p1>-1)sx=sx+1;
if(p1>-1)x[sx]=p1;
}
num=sx;
for(sx=1;sx<num+1;sx++){
y[sx]=str.indexOf(">",x[sx]);
}
for(sx=1;sx<num+1;sx++){
cr[sx]=str.substring(x[sx]+1,y[sx]);
}
strx=str;
for(sx=1;sx<num+1;sx++){
strx=strx.replace(cr[sx],"");
}
String[] xc=strx.split("<>");
int h,tx;
tx=0;
for(sx=0;sx<xc.length;sx++){
h=0;
if(xc[sx].length()<1)h=100;
if(xc[sx].equals(" "))h=100;
if(xc[sx].equals(" - "))h=100;
if(xc[sx].equals(" "))h=100;
if(h<50)tx=tx+1;
if(h<50)word[s][tx]=xc[sx];
}
wordnumber[s]=tx;
}
String cleaning(String str){
String strx;
int p1,sx,num;
int[] x=new int[100];
int[] y=new int[100];
String[] cr=new String[100];
sx=0;
p1=str.indexOf("<");
if(p1>-1)sx=sx+1;
if(p1>-1)x[sx]=p1;
while(p1>-1){
p1=str.indexOf("<",p1+1);
if(p1>-1)sx=sx+1;
if(p1>-1)x[sx]=p1;
}
num=sx;
for(sx=1;sx<num+1;sx++){
y[sx]=str.indexOf(">",x[sx]);
}
for(sx=1;sx<num+1;sx++){
cr[sx]=str.substring(x[sx]+1,y[sx]);
}
strx=str;
for(sx=1;sx<num+1;sx++){
strx=strx.replace(cr[sx],"");
}
strx=strx.replace("<>","");
return strx;
}
}
package infobox;
import tool.*;
public class check {
String[] data=new String[5000];
int s,sx,datanumber;
int[] x=new int[5000];
int[] y=new int[5000];
int number;
String[] article=new String[100];
String[] credit=new String[100];
String[] value=new String[5000];
String[][] word=new String[500][100];
int[] wordnumber=new int[500];
int makedata(String urlx){
getdata sub=new getdata();
sub.makedata(urlx, "UTF-8");
data=sub.data;
datanumber=sub.datanumber;
int s1,h,s2;
s1=0;
for(s=1;s<datanumber+1;s++){
h=0;
if(data[s].indexOf("<table class")>-1)h=h+1;
if(data[s].indexOf("infobox")>-1)h=h+1;
if(h==2)s1=s;
}
int ch;
ch=0;
if(s1<5)ch=100;
return ch;
}
}
最終更新:2013年12月31日 02:45