package dp3;
import tool.*;
import java.io.*;
public class pro {
int s,datanumber;
String[] data=new String[5000];
String[] credit=new String[5000];
String[] delta=new String[5000];
int[] k1=new int[50];
int[] k2=new int[50];
String[] subcredit=new String[5000];
String[] point=new String[5000];
String[] link=new String[5000];
int number;
String title;
public static void main(String[] args) {
pro t=new pro();
}
pro(){
int tr;
for(tr=4;tr<677;tr++){
readfile sub7=new readfile();
sub7.makedata("data/"+tr+".txt","UTF-8");
data=sub7.data;
datanumber=sub7.datanumber;
int sx=0;
for(s=1;s<datanumber+1;s++){
if(data[s].indexOf("infobox")>-1)sx=sx+1;
if(data[s].indexOf("infobox")>-1)k1[sx]=s;
}
int n=sx;
for(s=1;s<n+1;s++){
int s2=0;
for(sx=k1[s];sx<datanumber+1;sx++){
int h=0;
if(data[sx].indexOf("</table>")>-1)h=h+1;
if(s2==0)h=h+1;
if(h==2)s2=sx;
}
k2[s]=s2;
}
String str="";
for(s=1;s<n+1;s++){
for(sx=k1[s];sx<k2[s];sx++){
str=str+data[sx];
}
}
str=str.replace("th","td");
String[] x=str.split("</tr>");
for(s=0;s<x.length;s++){
String[] y=x[s].split("</td>");
credit[s]=change(y[0]);
delta[s]="";
for(sx=1;sx<y.length;sx++){
y[sx]=y[sx].replace("<td>","");
y[sx]=y[sx].replace("</a>","");
y[sx]=y[sx].replace("<br />","△");
delta[s]=y[sx];
}
}
int tx=0;
for(s=1;s<x.length;s++){
String[] z=delta[s].split("△");
for(sx=0;sx<z.length;sx++){
tx=tx+1;
subcredit[tx]=credit[s];
point[tx]=z[sx];
}
}
number=tx;
title=credit[0].replace(" ","");
System.out.println(title);
for(s=1;s<number+1;s++){
int p1=point[s].indexOf("/wiki/");
int p2=point[s].indexOf("\"",p1);
link[s]="";
if(p1>0)link[s]=point[s].substring(p1,p2);
p1=point[s].indexOf(">");
p2=point[s].length();
if(p1>0)point[s]=point[s].substring(p1+1,p2);
if(subcredit[s].indexOf("放送期間")>-1)point[s]=change(point[s]);
if(subcredit[s].indexOf("放送時間")>-1)point[s]=change(point[s]);
if(subcredit[s].indexOf("放送国")>-1)point[s]=change(point[s]);
System.out.println(subcredit[s]+","+point[s]+","+link[s]);
}
writexml("gdata/"+tr+".txt");
}
}
void writexml(String file){
int s,sx;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
pw.println(title);
for(s=1;s<number;s++){
if(subcredit[s].length()>0)pw.println(subcredit[s]+","+point[s]+","+link[s]);
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
String change(String str){
int n;
for(n=1;n<11;n++){
str=rev(str);
}
str=str.replace(" ","");
return str;
}
String rev(String str){
if(str==null)str="";
int p1=str.indexOf("<");
int p2=-1;
if(p1>-1)p2=str.indexOf(">",p1);
String strx="";
if(p2>-1)strx=str.substring(p1,p2+1);
str=str.replace(strx,"");
return str;
}
}
最終更新:2016年06月26日 12:31