package wiki;
import tool.*;
public class pro {
String urlx;
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[100];
String[][] word=new String[100][100];
int[] wordnumber=new int[100];
public static void main(String[] args) {
pro test=new pro();
}
pro(){
urlx="http://ja.wikipedia.org/wiki/%E4%B8%AD%E6%9B%BD%E6%A0%B9%E5%BC%98%E6%96%87";
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];
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];
shuffle(s,str);
}
for(s=1;s<number+1;s++){
for(sx=1;sx<wordnumber[s]+1;sx++){
System.out.println(word[s][sx]);
}
}
}
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;
}
}
最終更新:2013年12月30日 22:49