package don;
import java.io.*;
import tool.*;
public class pro {
int number,dicnumber;
String[] data=new String[6000];
int s,datanumber;
String[] city=new String[6000];
String[] credit=new String[6000];
String[] v=new String[6000];
String[] dic=new String[6000];
String[] name=new String[6000];
String[][][] point=new String[30][100][100];
public static void main(String[] args) {
pro t=new pro();
}
pro(){
dicnumber=0;
number=0;
int tr;
for(tr=19;tr<28;tr++){
readx("gdata/"+tr+".txt");
for(s=1;s<datanumber+1;s++){
catchword sub=new catchword();
city[s]=sub.makedata(data[s],"city");
city[s]=city[s].replace(" ","");
credit[s]=sub.makedata(data[s],"credit");
v[s]=sub.makedata(data[s],"city");
}
int sx,h;
for(s=1;s<datanumber+1;s++){
String str=credit[s];
if(str.equals("海 外姉妹・友好都 市 数"))str="海外姉妹・友好都市数";
if(str.equals("国 内姉妹・友好都 市 数"))str="国内姉妹・友好都市数";
if(str.equals("外国人人口"))str="外国人登録者数";
if(str.equals("人口集中地区面積(A))"))str="人口集中地区面積";
credit[s]=str;
}
for(s=1;s<datanumber+1;s++){
String str=city[s];
if(str.indexOf("平均")>-1)str="";
if(str.indexOf("中核")>-1)str="";
if(str.indexOf("合計")>-1)str="";
if(str.indexOf("候補")>-1)str="";
city[s]=str;
}
name[0]="";
for(s=1;s<datanumber+1;s++){
h=0;
for(sx=1;sx<dicnumber+1;sx++){
if(dic[sx].equals(credit[s]))h=100;
}
if(h<50)dicnumber=dicnumber+1;
if(h<50)dic[dicnumber]=credit[s];
}
for(s=1;s<datanumber+1;s++){
h=0;
for(sx=0;sx<number+1;sx++){
if(name[sx].equals(city[s]))h=100;
}
if(h<50)number=number+1;
if(h<50)name[number]=city[s];
}
}
System.out.println(dicnumber);
int sx;
for(sx=1;sx<dicnumber+1;sx++){
System.out.println(dic[sx]);
}
for(sx=1;sx<number+1;sx++){
System.out.println(name[sx]);
}
for(tr=19;tr<28;tr++){
readx("gdata/"+tr+".txt");
for(s=1;s<datanumber+1;s++){
catchword sub=new catchword();
city[s]=sub.makedata(data[s],"city");
credit[s]=sub.makedata(data[s],"credit");
v[s]=sub.makedata(data[s],"value");
}
int h;
for(s=1;s<datanumber+1;s++){
String str=credit[s];
if(str.equals("海 外姉妹・友好都 市 数"))str="海外姉妹・友好都市数";
if(str.equals("国 内姉妹・友好都 市 数"))str="国内姉妹・友好都市数";
if(str.equals("外国人人口"))str="外国人登録者数";
if(str.equals("人口集中地区面積(A))"))str="人口集中地区面積";
credit[s]=str;
}
for(s=1;s<datanumber+1;s++){
String str=city[s];
if(str.indexOf("平均")>-1)str="";
if(str.indexOf("中核")>-1)str="";
if(str.indexOf("合計")>-1)str="";
if(str.indexOf("候補")>-1)str="";
city[s]=str;
}
for(s=1;s<number+1;s++){
for(sx=1;sx<number+1;sx++){
point[tr][s][sx]="";
}}
for(s=1;s<datanumber+1;s++){
int s1=0;
for(sx=1;sx<number+1;sx++){
if(city[s].equals(name[sx]))s1=sx;
}
int s2=0;
for(sx=1;sx<dicnumber+1;sx++){
if(credit[s].equals(dic[sx]))s2=sx;
}
point[tr][s1][s2]=v[s];
}
}
writexml("re.txt");
}
void writexml(String file){
int s,sx;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
pw.print("year,city,code,");
for(sx=1;sx<dicnumber;sx++){
pw.print(dic[sx]);
pw.print(",");
}
pw.println(dic[dicnumber]);
int tr;
for(tr=19;tr<28;tr++){
for(s=1;s<number+1;s++){
pw.print(tr);
pw.print(",");
pw.print(name[s]);
pw.print(",");
pw.print(s);
pw.print(",");
for(sx=1;sx<dicnumber;sx++){
pw.print(point[tr][s][sx]);
pw.print(",");
}
pw.println(point[tr][s][dicnumber]);
}
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
void readx(String file){
String str;
BufferedReader br;
int s;
s=0;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
while((str = br.readLine()) != null) {
s=s+1;
data[s]=str;
}
br.close();
} catch (IOException e) {System.out.println(e);}
datanumber=s;
}
}
最終更新:2017年03月12日 09:43