アットウィキロゴ

コード1

package travel;
 
import tool.*;
 
public class pro {
 
 
     String[] data=new String[50000];
int s,sx,datanumber,tx;
      String[] v=new String[50000];
      String[] bus=new String[50000];
      String[] credit=new String[50000];
       String[] year=new String[50000];
      String[] pref=new String[50000];
 
      String[] code=new String[50000];
 
       String[] code_pref=new String[50000];
       String[] code_credit=new String[50000];
       String[] code_bus=new String[50000];
 
       int creditnumber;
String[] creditp=new String[50];
String[] style=new String[50];
int[] strlong=new int[50];
     String[][] datax=new String[500000][10];
 
    public static void main(String[] args) {
       pro re=new pro();
    }
 
 
    pro(){
 
 
        creditnumber=5;
        creditp[1]="year";
         creditp[2]="pref";
        creditp[3]="bus";
        creditp[4]="credit";
        creditp[5]="value"; 
        style[1]="INTEGER";
        style[2]="VARCHAR";
        style[4]="VARCHAR";
       style[3]="VARCHAR";
         style[5]="VARCHAR";
 
         strlong[4]=20;
strlong[3]=20;
        strlong[1]=20;
strlong[2]=20;
 
        String db,tab;
 
 
         db="ken";
        tab="ken";
 
 
 
        table sub7=new table();
        sub7.credit=creditp;
        sub7.creditnumber=creditnumber;
        sub7.style=style;
        sub7.strlong=strlong;
        sub7.makedata(db,tab);
 
 
 
 
            int dicnumber,h,dicnumber2,dicnumber3;
 
          String[] dic=new String[50000];
          String[] dic2=new String[50000];
           String[] dic3=new String[50000];
          dicnumber=0;
         dicnumber2=0;
          dicnumber3=0;
        int tr;
 
 
 
        for(tr=1;tr<381;tr++){    
 
     readfile sub79=new readfile();
    sub79.makedata("gdata/"+tr+".txt", "UTF-8");
    data=sub79.data;
    datanumber=sub79.datanumber;
 
    String str;
 
        for(s=1;s<datanumber+1;s++){
 
        catchword sub8=new catchword();
        v[s]=sub8.makedata(data[s],"value");
        bus[s]=sub8.makedata(data[s],"bus");
        credit[s]=sub8.makedata(data[s],"credit");
        year[s]=sub8.makedata(data[s],"year");
        pref[s]=sub8.makedata(data[s],"pref");
     code[s]=sub8.makedata(data[s],"code");
        }
 
 
 
 
 
        for(s=1;s<datanumber+1;s++){
 
        h=0;    
        if(bus[s].indexOf("食料品")>-1)h=h+1;
        if(code[s].indexOf("b")>-1)h=h+1;
        if(h==2)bus[s]="食料品";  
 
        h=0;    
        if(bus[s].indexOf("食料品")>-1)h=h+1;
        if(code[s].indexOf("c")>-1)h=h+1;
        if(h==2)bus[s]="繊維"; 
 
 
 
         h=0;    
        if(bus[s].indexOf("パルプ")>-1)h=h+1;
        if(code[s].indexOf("b")>-1)h=h+1;
        if(h==2)bus[s]="パルプ・紙";  
        h=0;    
        if(bus[s].indexOf("パルプ")>-1)h=h+1;
        if(code[s].indexOf("c")>-1)h=h+1;
        if(h==2)bus[s]="化学";  
        h=0;    
        if(bus[s].indexOf("石油")>-1)h=h+1;
        if(code[s].indexOf("b")>-1)h=h+1;
        if(h==2)bus[s]="石油・石炭";  
        h=0;    
        if(bus[s].indexOf("石油")>-1)h=h+1;
        if(code[s].indexOf("c")>-1)h=h+1;
        if(h==2)bus[s]="窯業・土石製品";  
        h=0;    
        if(bus[s].indexOf("鉄鋼")>-1)h=h+1;
        if(code[s].indexOf("b")>-1)h=h+1;
        if(h==2)bus[s]="鉄鋼";  
        h=0;    
        if(bus[s].indexOf("鉄鋼")>-1)h=h+1;
        if(code[s].indexOf("c")>-1)h=h+1;
        if(h==2)bus[s]="非鉄金属";  
         h=0;    
        if(bus[s].indexOf("金属製品")>-1)h=h+1;
        if(code[s].indexOf("b")>-1)h=h+1;
        if(h==2)bus[s]="金属製品";  
        h=0;    
        if(bus[s].indexOf("金属製品")>-1)h=h+1;
        if(code[s].indexOf("c")>-1)h=h+1;
        if(h==2)bus[s]="一般機械";  
        h=0;    
        if(bus[s].indexOf("電気機械")>-1)h=h+1;
        if(code[s].indexOf("b")>-1)h=h+1;
        if(h==2)bus[s]="電気機械";  
        h=0;    
        if(bus[s].indexOf("電気機械")>-1)h=h+1;
        if(code[s].indexOf("c")>-1)h=h+1;
        if(h==2)bus[s]="輸送用機械"; 
        h=0;    
        if(bus[s].indexOf("精密機械")>-1)h=h+1;
        if(code[s].indexOf("b")>-1)h=h+1;
        if(h==2)bus[s]="精密機械";  
        h=0;    
        if(bus[s].indexOf("精密機械")>-1)h=h+1;
        if(code[s].indexOf("c")>-1)h=h+1;
        if(h==2)bus[s]="その他製造業"; 
 
        }
 
    for(s=1;s<datanumber+1;s++){
     h=0;
    for(sx=1;sx<dicnumber+1;sx++){
    if(bus[s].equals(dic[sx]))h=100;     
     }
    if(h<50)dicnumber=dicnumber+1;
    if(h<50)dic[dicnumber]=bus[s];
     }
 
 
 
 
    for(s=1;s<datanumber+1;s++){
    for(sx=1;sx<dicnumber+1;sx++){
    if(bus[s].equals(dic[sx]))code_bus[s]="b"+sx;       
    }
    }
 
 
 
    for(s=1;s<datanumber+1;s++){
     h=0;
    for(sx=1;sx<dicnumber2+1;sx++){
    if(credit[s].equals(dic2[sx]))h=100;     
     }
    if(h<50)dicnumber2=dicnumber2+1;
    if(h<50)dic2[dicnumber2]=credit[s];
     }
 
     for(s=1;s<datanumber+1;s++){
    for(sx=1;sx<dicnumber2+1;sx++){
    if(credit[s].equals(dic2[sx]))code_credit[s]="c"+sx;       
    }
    }
 
     for(s=1;s<datanumber+1;s++){
     h=0;
    for(sx=1;sx<dicnumber3+1;sx++){
    if(pref[s].equals(dic3[sx]))h=100;     
     }
    if(h<50)dicnumber3=dicnumber3+1;
    if(h<50)dic3[dicnumber3]=pref[s];
     }
 
 
     for(s=1;s<datanumber+1;s++){
    for(sx=1;sx<dicnumber3+1;sx++){
    if(pref[s].equals(dic3[sx]))code_pref[s]="p"+sx;       
    }
    }
 
 
 
 
        for(s=1;s<datanumber+1;s++){
 
        datax[s][1]=""+year[s];
        datax[s][2]=""+code_pref[s];
        datax[s][3]=""+code_bus[s];
        datax[s][4]=""+code_credit[s];
        datax[s][5]=""+v[s];
        }
 
 
 
 
        insert sub5=new insert();
        sub5.creditnumber=creditnumber;
        sub5.style=style;
        sub5.data=datax;
        sub5.datanumber=datanumber;
        sub5.makedata(db,tab);
 
 
 
 
    System.out.println(dicnumber);    
 
 
 
        }
 
 
 
    for(sx=1;sx<dicnumber+1;sx++){
    System.out.println(sx+","+dic[sx]);  
     }
 
     for(sx=1;sx<dicnumber2+1;sx++){
    System.out.println(sx+","+dic2[sx]);  
     }
 
 
 
    }
 
 
 
}
 
 
 
 
package travel;
 
import java.sql.*;
import java.io.*;
 
class insert {
 
    Connection dbx;   
Statement stx;   
String sqx; 
ResultSet  rsx; 
 
String[] style=new String[50];
int creditnumber;
  String[][] data=new String[5000][50];  
int datanumber;
 
int p;
 
    void makedata(String db,String tab) {
 
        String str;
 
        int s,sx;
 
        for(p=1;p<datanumber+1;p++){
 
 
       str="";
 
        for(sx=1;sx<creditnumber;sx++){
        if(style[sx].equals("VARCHAR"))str=str+change(data[p][sx])+",";
        if(style[sx].equals("INTEGER"))str=str+data[p][sx]+",";
        }
        sx=creditnumber;
        if(style[sx].equals("VARCHAR"))str=str+change(data[p][sx]);
        if(style[sx].equals("INTEGER"))str=str+data[p][sx];
 
    String url = "jdbc:h2:"+db+";create=true";   
String usr = "";   
String pwd = ""; 
 
 
 try{
 Class.forName("org.h2.Driver");
 
dbx = DriverManager.getConnection(url, usr, pwd); 
 
 
      stx = dbx.createStatement();
 
      String sql = "INSERT INTO "+tab+" VALUES("+str+")";
 
    int num = stx.executeUpdate(sql);
 
    stx.close();
 } catch (Exception ex) { ex.printStackTrace();} 
 
        }
 
 
  }
String change(String str){
String str1;
str1="'"+str+"'";
return str1;
}
}
 
 
 
 
package travel;
 
 
import java.sql.*; 
 
public class table{
 
    Connection dbx;   
Statement stx;   
String sqx; 
ResultSet  rsx; 
int creditnumber;
String[] credit=new String[50];
String[] style=new String[50];
int[] strlong=new int[50];
 
 
 
 
    void makedata(String db,String tab){
 
 
 
        String str;
 
        str="";
        int s;
        for(s=1;s<creditnumber;s++){
        if(style[s].equals("INTEGER"))str=str+credit[s]+" "+style[s]+",";
        if(style[s].equals("VARCHAR"))str=str+credit[s]+" "+style[s]+"("+strlong[s]+"),";
        }
        s=creditnumber;
        if(style[s].equals("INTEGER"))str=str+credit[s]+" "+style[s];
        if(style[s].equals("VARCHAR"))str=str+credit[s]+" "+style[s]+"("+strlong[s]+")";
 
 
 
 
    String url = "jdbc:h2:"+db+";create=true";   
String usr = "";   
String pwd = ""; 
 
 
 try{
 Class.forName("org.h2.Driver");
 
dbx = DriverManager.getConnection(url, usr, pwd); 
 
 
      stx = dbx.createStatement();
 
      String sqx = "CREATE TABLE " +tab+"("+str+")"; 
 
 
      stx.executeUpdate(sqx);
 
 } catch (Exception ex) { ex.printStackTrace();} 
 
 
 
 
 
 
    }
}
 
最終更新:2015年07月26日 06:43