#! /bin/sh
LANG=C
export LANG
( cd ../../ud-kanbun/Pulleyblank
  git pull
)
for F in corpus.pulleyblank.mc corpus.mencius.mc
do ( case $F in
     corpus.pulleyblank.mc) cd ../../ud-kanbun/Pulleyblank
			    cat Pulleyblank*.txt ;;
     corpus.mencius.mc) cd ../../ud-kanbun/kanripo/kR1h0001
			cat 00[1-9]/*.txt 010/*.txt ;;
     esac
   ) | nawk '
/^[^#]/{
  if($0==""){
    if(n>0)
      printf("EOS\n");
    n=0;
  }
  else{
    if(n>=$1)
      printf("EOS\n");
    n=$1;
    printf("%s\t%s,*,*,%s,*,*,*\n",$2,$5,$3);
  }
}
END{
  if(n>0)
    printf("EOS\n");
}'> $F
done

for F in corpus.KT0.mc corpus.kanjikai.mc corpus.misc.mc
do nawk '
{
  if($1=="EOS")
    printf("EOS\n");
  else{
    split($2,a,",");
    printf("%s\t%s,%s,%s,%s,*,*,%s,*,*,*\n",$1,a[1],a[2],a[3],a[4],a[7]);
  }
}' ../seed_names2/$F > $F
done

sed -e /EOS/d -e 's/	/,0,0,0,/' corpus.pulleyblank.mc | sort -u > dict.pulleyblank.csv
sed 's/,[^,]*,[^,]*,[^,]*$/,*,*,*/' ../seed_names2/KTp2.*.csv ../seed_names2/name.Noun.girei.csv | sort -u | tr , ' ' | nawk '
BEGIN{
  c=sprintf("cat dict.pulleyblank.csv dict.yasuoka.csv | tr , %c %c",39,39);
  while((c|getline)>0)
    w[$1]=1;
  close(c);
}
length($1)==3{
  if(w[$1]!=1)
    printf("%s\n",$0);
}' | tr ' ' , > dict.KTp2.csv
sed 's/,[^,]*,[^,]*,[^,]*$/,*,*,*/' ../seed_names2/name.Noun.personal.csv ../seed_names2/name.Noun.surname.csv | sort -u > dict.name.csv
sed 's/,[^,]*,[^,]*,[^,]*$/,*,*,*/' ../seed_names2/ymzknk.*.csv | sort -u > dict.ymzknk.csv
sed 's/,[^,]*,[^,]*,[^,]*$/,*,*,*/' ../seed_names2/Symbol.csv | sort -u | tee dict.symbol.csv | awk -F, '{
  printf("1\t%s\t%s\tPUNCT\t%s,%s,%s,%s\t_\t0\troot\t_\tSpaceAfter=No\n\n",$1,$11,$5,$6,$7,$8);
}' > conllu.symbol.txt
cp -p ../seed_names2/*.def .
cp -p ../seed_names2/dicrc .
exit 0
