package power;
import java.io.*;
public class pro {
int s,datanumber;
String[] data=new String[60000];
String[] city=new String[60000];
String[] pref=new String[60000];
String[] town=new String[60000];
String[] code_city=new String[60000];
String[] code_pref=new String[60000];
String[] code_town=new String[60000];
String[] lon=new String[60000];
String[] lat=new String[60000];
int[] delta=new int[60000];
String[] don=new String[60000];
String[] dondon=new String[60000];
public static void main(String[] args) {
pro t=new pro();
}
pro(){
int tr;
String file="data/2.txt";
readx(file);
for(s=1;s<datanumber+1;s++){
String[] x=data[s].split(",");
pref[s-1]=x[3];
city[s-1]=x[4];
town[s-1]=x[5];
code_pref[s-1]=x[0];
code_city[s-1]=x[1];
code_town[s-1]=x[2];
lon[s-1]=x[6];
lat[s-1]=x[7];
}
int number=datanumber;
file="a.csv";
readjis(file);
for(s=6;s<datanumber+1;s++){
String[] x=data[s].split(",");
don[s]=x[1].replace("\"","");
dondon[s]=x[9]+x[10];
dondon[s]=dondon[s].replace("\"","");
}
for(tr=1;tr<500;tr++){
int sxs=0;
int maxp;
maxp=100;
for(s=6;s<datanumber+1;s++){
int p5=wordcheck(town[tr],dondon[s]);
if(code_city[tr].equals(don[s]))p5=p5+100;
if(p5>maxp)sxs=s;
if(p5>maxp)maxp=p5;
}
delta[tr]=sxs;
System.out.println(town[tr]+","+dondon[sxs]);
}
}
int wordcheck(String w1,String w2){
int n1=w1.length();
int n2=w2.length();
w1=change(w1);
w2=change(w2);
String[] x1=new String[600];
String[] x2=new String[600];
int s;
for(s=1;s<n1+1;s++){
x1[s]=w1.substring(s-1,s);
}
for(s=1;s<n2+1;s++){
x2[s]=w2.substring(s-1,s);
}
int sx,p1,h;
p1=0;
for(s=1;s<n1+1;s++){
h=0;
for(sx=1;sx<n2+1;sx++){
if(x1[s].equals(x2[sx]))h=100;
}
if(h>50)p1=p1+1;
}
return (100*p1/n1);
}
String change(String px){
px=px.replace(" ","");
px=px.replace(" ","");
String p5;
p5=px.replace("1丁目","1丁目");
p5=p5.replace("2丁目","2丁目");
p5=p5.replace("3丁目","3丁目");
p5=p5.replace("4丁目","4丁目");
p5=p5.replace("5丁目","5丁目");
p5=p5.replace("6丁目","6丁目");
p5=p5.replace("7丁目","7丁目");
p5=p5.replace("8丁目","8丁目");
p5=p5.replace("一丁目","1丁目");
p5=p5.replace("二丁目","2丁目");
p5=p5.replace("三丁目","3丁目");
p5=p5.replace("四丁目","4丁目");
p5=p5.replace("五丁目","5丁目");
p5=p5.replace("六丁目","6丁目");
p5=p5.replace("七丁目","7丁目");
p5=p5.replace("八丁目","8丁目");
return p5;
}
void writexml(String file){
int s,sx;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
for(s=1;s<datanumber+1;s++){
pw.println(data[s]);
}
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;
}
void readjis(String file){
String str;
BufferedReader br;
int s;
s=0;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file),"SJIS"));
while((str = br.readLine()) != null) {
s=s+1;
data[s]=str;
}
br.close();
} catch (IOException e) {System.out.println(e);}
datanumber=s;
}
}
最終更新:2016年02月05日 16:13