アットウィキロゴ

AOA

import java.io.*;
import java.util.List;
import net.reduls.igo.Morpheme;
import net.reduls.igo.Tagger;

public class opinion{

int n,datanumber,articlenumber;
String[] data=new String[50000];
int s,sx;
String[][] word=new String[4000][5000];
String[] article=new String[50000];  
String[] author=new String[50000];  

String str,file;
int h;
int[] wordnumber=new int[5000];
int t,t1;
int dicnumber;
String[] dic=new String[1005];
int op;

public static void main(String[] args){
opinion test=new opinion();
}

opinion(){        

readfile("author.txt");

dicnumber=datanumber;
for(s=1;s<dicnumber+1;s++){
dic[s]=data[s];
}

op=1;

readfile("article.txt");

sx=0;
for(s=1;s<datanumber+1;s++){
String[] x=data[s].split(",");
h=0;
if(x.length>1)h=h+1;
if(x[0].equals(dic[op]))h=h+1;

if(h==2)sx=sx+1;
if(h==2)author[sx]=x[0];
if(h==2)article[sx]=x[1];
}

articlenumber=sx;

System.out.println(articlenumber);

System.out.println(dic[op]);


for(n=1;n<articlenumber+1;n++){

str=article[n];

try {
Tagger tagger = new Tagger( "ipadic" );
List<Morpheme> list = tagger.parse(str);
s=0;        
for(Morpheme morph : list ){
s=s+1;            
word[n][s]=morph.surface;
}    

} catch(IOException e) {
      System.err.println(e.getMessage());  
    }

wordnumber[n]=s;

}

file="data/";
file=file+op;
file=file+".txt";

writefile(file);




}

void writefile(String file){

try{
PrintWriter pw = new PrintWriter
(new BufferedWriter(new FileWriter(file)));

for(s=1;s<articlenumber+1;s++){                            
for(sx=1;sx<wordnumber[s];sx++){              
pw.print(word[s][sx]);              
pw.print(",");              
}
sx=wordnumber[s];                      
pw.println(word[s][sx]);              
}

System.out.println("ファイルに書きこみました。");
pw.close();
}
catch(IOException ep){ System.out.println("入出力エラーです。"); }

}


void readfile(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;

}








}
最終更新:2011年06月12日 20:34