アットウィキロゴ

package word;
 
 
import java.util.HashMap;
 
public class pro {
 
    String[] dic=new String[600];
    int[] count=new int[600];
    int s,dicnumber;
    String str;
     String[] word=new String[600];
 
    int wordnumber;
 
    HashMap<String,Integer> map = new HashMap<String,Integer>();
 
 
    public static void main(String[] args) {
       pro test=new pro();
    }
 
    pro(){
 
        str="私は猫です";
 
        makeword(str);
 
        dicnumber=0;
 
       makedic();
 
 
    str="風は風";    
 
    select(str);    
 
    makedic();    
 
    str="大根はうまい";
 
    select(str);    
 
    makedic();    
 
    System.out.println(dicnumber);
 
 
    }
    void makedic(){
 
        int s,h,n;
 
          for(s=1;s<wordnumber+1;s++){
        h=0;
        if(map.containsKey(word[s]))h=100;
        if(h<50)dicnumber=dicnumber+1;
        if(h<60)map.put(word[s], dicnumber);
        if(h<60)dic[dicnumber]=word[s];
        n=map.get(word[s]);
        count[n]=count[n]+1;
        }
 
    }
 
    void select(String str){
 
        double[] p=new double[600];
        String[] subword=new String[600];
        int subnumber;
        int s,c1;
        c1=0;
        for(s=1;s<dicnumber+1;s++){
        c1=c1+count[s];
        }
 
    for(s=1;s<dicnumber+1;s++){
    p[s]=(double)count[s]/c1;
    }
 
    double minp;
    minp=1;
    for(s=1;s<dicnumber+1;s++){
    if(p[s]<minp)minp=p[s];
    }
    p[0]=minp;
 
    subnumber=0;
 
    int tr,sx;
    double p1,maxl;
    maxl=-9999;
    for(tr=1;tr<11;tr++){
    makeword(str);
    p1=0;
    for(s=1;s<wordnumber+1;s++){
    sx=0;
   if(map.containsKey(word[s]))sx=map.get(word[s]);
    p1=p1+Math.log(p[sx]);
    }
    if(p1>maxl){
    for(s=1;s<wordnumber+1;s++){
    subword[s]=word[s];    
    }    
    subnumber=wordnumber;
    }
    }
 
    for(s=1;s<subnumber+1;s++){
    word[s]=subword[s];
    }
    wordnumber=subnumber;
 
 
    }
 
void makeword(String str){
 
    int num;
    int[] px=new int[1000];
    num=str.length();    
    int s;
 
    for(s=1;s<num;s++){
    px[s]=0;
    if(Math.random()<0.2)px[s]=1;
    }
 
    wordnumber=1;
 
word[wordnumber]=str.substring(0,1);     
for(s=1;s<num;s++){
if(px[s]==1)wordnumber=wordnumber+1;
if(px[s]==1)word[wordnumber]="";
word[wordnumber]=word[wordnumber]+str.substring(s,s+1);        
}
 
}
}
 
最終更新:2014年04月15日 18:54