package memo;
import java.io.*;
import java.io.File;
public class pro {
int s,datanumber;
String[] data=new String[20000];
String[] sta=new String[50000];
String[] act=new String[50000];
String[] name=new String[50000];
String[] term=new String[50000];
String[] time=new String[50000];
int[] number=new int[50000];
String[] week=new String[50000];
String[] t1=new String[50000];
String[] t2=new String[50000];
String[] y1=new String[50000];
String[] m1=new String[50000];
String[] d1=new String[50000];
String[] y2=new String[50000];
String[] m2=new String[50000];
String[] d2=new String[50000];
String[] h1=new String[50000];
String[] h2=new String[50000];
public static void main(String[] args) {
pro t=new pro();
}
pro(){
readx("data.csv");
for(s=2;s<datanumber+1;s++){
String[] x=data[s].split(",");
name[s-1]=x[1];
sta[s-1]=x[2];
time[s-1]="";
if(x.length>4)time[s-1]=x[3];
term[s-1]="";
if(x.length>4)term[s-1]=x[4];
}
datanumber=datanumber-1;
for(s=1;s<datanumber+1;s++){
term[s]=term[s].replace("−","-");
term[s]=term[s].replace("〜","-");
term[s]=term[s].replace("?","-");
term[s]=term[s].replace("基本は","");
}
for(s=1;s<datanumber+1;s++){
String strx="";
t1[s]="";
t2[s]="";
if(term[s].indexOf("-")>0)strx=term[s];
String[] x1=strx.split("-");
if(x1.length>1)t1[s]=x1[0];
if(x1.length>1)t2[s]=x1[1];
}
for(s=1;s<datanumber+1;s++){
y1[s]="";
m1[s]="";
d1[s]="";
int p1=t1[s].indexOf("年");
int p2=t1[s].indexOf("月",p1);
int p3=t1[s].indexOf("日",p2);
if(p1>-1)y1[s]=t1[s].substring(0,p1);
if(p2>-1)m1[s]=t1[s].substring(p1+1,p2);
if(p3>-1)d1[s]=t1[s].substring(p2+1,p3);
}
for(s=1;s<datanumber+1;s++){
y1[s]="";
m1[s]="";
d1[s]="";
int p1=t1[s].indexOf("年");
int p2=t1[s].indexOf("月",p1);
int p3=t1[s].indexOf("日",p2);
if(p1>-1)y1[s]=t1[s].substring(0,p1);
if(p2>-1)m1[s]=t1[s].substring(p1+1,p2);
if(p3>-1)d1[s]=t1[s].substring(p2+1,p3);
}
for(s=1;s<datanumber+1;s++){
t2[s]=t2[s].replace("同年","");
}
for(s=1;s<datanumber+1;s++){
y2[s]="";
m2[s]="";
d2[s]="";
int p1=t2[s].indexOf("年");
int p2=t2[s].indexOf("月",p1);
int p3=t2[s].indexOf("日",p2);
if(p1>-1)y2[s]=t2[s].substring(0,p1);
if(p1<0)p1=-1;
if(p2>-1)m2[s]=t2[s].substring(p1+1,p2);
if(p3>-1)d2[s]=t2[s].substring(p2+1,p3);
int h=0;
if(m2[s].length()>0)h=h+1;
if(y2[s].length()<2)h=h+1;
if(h==2)y2[s]=y1[s];
}
for(s=1;s<datanumber+1;s++){
int h=0;
String sp="";
if(y1[s].length()<1)h=h+1;
if(term[s].indexOf("/")>-1)h=h+1;
if(h==2)sp=term[s];
String[] x2=sp.split("/");
if(h==2)y1[s]=x2[0];
if(h==2)m1[s]=x2[1];
if(h==2)d1[s]=x2[2];
}
String w1="月曜,火曜,水曜,木曜,金曜,土曜,日曜";
String[] ww=w1.split(",");
int sx;
int[] w2=new int[7];
for(s=1;s<datanumber+1;s++){
week[s]="";
time[s]=time[s].replace("毎週","");
for(sx=0;sx<7;sx++){
w2[sx]=0;
}
for(sx=0;sx<7;sx++){
if(time[s].indexOf(ww[sx])>-1)w2[sx]=100;
}
int z=0;
int sxs=0;
for(sx=0;sx<7;sx++){
z=z+w2[sx];
if(w2[sx]>0)sxs=sx;
}
if(z==100)week[s]=ww[sxs];
}
for(s=1;s<datanumber+1;s++){
if(time[s].indexOf("月曜-金曜")>-1)week[s]="月曜-金曜";
if(time[s].indexOf("月曜日-土曜")>-1)week[s]="月曜-土曜";
}
for(s=1;s<datanumber+1;s++){
h1[s]="";
h2[s]="";
String k= time[s].replace(week[s],"");
k= k.replace("日","");
int p1=k.indexOf("(");
if(p1>-1)k=k.substring(0,p1);
String[] x3=k.split("-");
if(x3.length==2)h1[s]=x3[0];
if(x3.length==2)h2[s]=x3[1];
}
for(s=1;s<datanumber+1;s++){
if(time[s].indexOf("同上")>-1)h1[s]=h1[s-1];
if(time[s].indexOf("同上")>-1)h2[s]=h2[s-1];
if(time[s].indexOf("同上")>-1)week[s]=week[s-1];
}
writexml("ren.csv");
}
void writexml(String file){
int s,sx;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
for(s=1;s<datanumber+1;s++){
pw.print(name[s]+",");
pw.print(sta[s]+",");
pw.print(week[s]+",");
pw.print(y1[s]+","+m1[s]+","+d1[s]+",");
pw.print(y2[s]+","+m2[s]+","+d2[s]+",");
pw.print(h1[s]+",");
pw.println(h2[s]);
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
void readx(String file){
String str;
BufferedReader br;
int s;
s=0;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
while((str = br.readLine()) != null) {
s=s+1;
data[s]=str;
}
br.close();
} catch (IOException e) {System.out.println(e);}
datanumber=s;
}
}
最終更新:2016年12月27日 01:19