import java.net.URLEncoder;
class ren02{
String bun,str,str1,str2;
int[] x=new int[1000];
int[] y=new int[1000];
int[] word1=new int[100];
int[] word2=new int[100];
String[] surface=new String[100];
String[] reading=new String[100];
String[] pos=new String[100];
int ma1,ma2;
String xml[]=new String[1000];
int xmlnumber,wordnumber;
int s;
public static void main(String args[]){
ren02 test=new ren02();
}
ren02(){
str="東京電力福島第一原発の事故による放射能汚染水の海への放出が10日にも終わる見通しになった。";
bun=yahoo(str);
xymaker(bun);
System.out.println(xmlnumber);
for(s=1;s<xmlnumber+1;s++){
xml[s]=xmlmaker(s,bun);
}
makema();
makeword();
for(s=1;s<wordnumber+1;s++){
surface[s]=makesurface(s);
reading[s]=makereading(s);
pos[s]=makepos(s);
System.out.println(pos[s]);
}
}
String makepos(int s){
int s1,s2,sx,sx1,sx2,p1,p2;
String strx;
sx1=0;
sx2=1;
s1=word1[s];
s2=word2[s];
for(sx=s1;sx<s2;sx++){
if(xml[sx].equals("pos"))sx1=sx;
if(xml[sx].equals("/pos"))sx2=sx;
}
p1=y[sx1];
p2=x[sx2];
strx=bun.substring(p1+1,p2);
return strx;
}
String makereading(int s){
int s1,s2,sx,sx1,sx2,p1,p2;
String strx;
sx1=0;
sx2=1;
s1=word1[s];
s2=word2[s];
for(sx=s1;sx<s2;sx++){
if(xml[sx].equals("reading"))sx1=sx;
if(xml[sx].equals("/reading"))sx2=sx;
}
p1=y[sx1];
p2=x[sx2];
strx=bun.substring(p1+1,p2);
return strx;
}
String makesurface(int s){
int s1,s2,sx,sx1,sx2,p1,p2;
String strx;
sx1=0;
sx2=1;
s1=word1[s];
s2=word2[s];
for(sx=s1;sx<s2;sx++){
if(xml[sx].equals("surface"))sx1=sx;
if(xml[sx].equals("/surface"))sx2=sx;
}
p1=y[sx1];
p2=x[sx2];
strx=bun.substring(p1+1,p2);
return strx;
}
void makema(){
int sx;
ma1=0;
ma2=0;
for(s=1;s<xmlnumber+1;s++){
if(xml[s].equals("ma_result"))ma1=s;
if(xml[s].equals("/ma_result"))ma2=s;
}
}
void makeword(){
int s,sx;
sx=0;
for(s=ma1;s<ma2;s++){
if(xml[s].equals("word"))sx=sx+1;
if(xml[s].equals("word"))word1[sx]=s;
}
wordnumber=sx;
sx=0;
for(s=ma1;s<ma2;s++){
if(xml[s].equals("/word"))sx=sx+1;
if(xml[s].equals("/word"))word2[sx]=s;
}
}
String yahoo(String str){
String bun,urlx,word;
bun="";
urlx="";
try{
word = URLEncoder.encode(str,"utf-8");
urlx="http://jlp.yahooapis.jp/MAService/V1/parse?appid=WoXaNHexg668pKcMtkTiHW1IEwmWXxh55u41_G.ivEbV70qjf2UqLvdMYd4S7A--&results=ma,uniq&uniq_filter=9|10&sentence=";
urlx=urlx+word;
}catch(Exception e) { System.err.println(e); }
getdata gt=new getdata();
gt.makedata(urlx);
bun=gt.bun;
return bun;
}
void xymaker(String str){
int p1;
int s;
s=1;
p1=str.indexOf("<");
x[1]=p1;
while(p1>-1){
p1=str.indexOf("<",p1+1);
if(p1>-1)s=s+1;
if(p1>-1)x[s]=p1;
}
xmlnumber=s;
for(s=1;s<xmlnumber+1;s++){
y[s]=str.indexOf(">",x[s]);
}
}
String xmlmaker(int s,String str){
int p1,p2;
String bara;
p1=x[s];
p2=y[s];
bara=str.substring(p1+1,p2);
return bara;
}
}
最終更新:2011年04月09日 15:28