import java.io.*;
import java.util.List;
import net.reduls.igo.Morpheme;
import net.reduls.igo.Tagger;
public class pro{
int n,datanumber,articlenumber;
String[] data=new String[50000];
int s,sx;
String[][] word=new String[2000][5000];
String[] article=new String[2000];
String[] author=new String[2000];
String str;
int h;
int[] wordnumber=new int[2000];
public static void main(String[] args){
pro test=new pro();
}
pro(){
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("額賀議員"))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);
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;
}
writefile();
}
void writefile(){
try{
PrintWriter pw = new PrintWriter
(new BufferedWriter(new FileWriter("word.txt")));
for(s=1;s<articlenumber+1;s++){
pw.print(author[s]);
pw.print(",");
for(sx=1;sx<wordnumber[s];sx++){
pw.print(word[s][sx]);
pw.print(",");
}
pw.println(word[s][wordnumber[s]]);
}
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月11日 23:37