| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | case $# in |
| 3 | 0|1|2) echoscip-shell system . . echo. "Usage: wordforms [-s | -p] dictionary.aff dictionary.dic word |
| 4 | -s: print only suffixed forms |
| 5 | -p: print only prefixed forms |
| 6 | "; exit 1;; |
| 7 | esac |
| 8 | fx=0 |
| 9 | case $1 in |
| 10 | -s) fx=1; shift;; |
| 11 | -p) fx=2; shift;; |
| 12 | esac |
| 13 | testscip-shell system . . test. -h /tmp/wordforms.affscip-shell filesystem . . `/tmp/wordforms.aff`. && rmscip-shell system . . rm. /tmp/wordforms.affscip-shell filesystem . . `/tmp/wordforms.aff`. |
| 14 | lnscip-shell system . . ln. -s $PWD/$1 /tmp/wordforms.affscip-shell filesystem . . `/tmp/wordforms.aff`. |
| 15 | # prepared dic only with the query word |
| 16 | echoscip-shell system . . echo. 1 >/tmp/wordforms.dicscip-shell filesystem . . `/tmp/wordforms.dic`. |
| 17 | grepscip-shell system . . grep. "^$3/" $2 >>/tmp/wordforms.dicscip-shell filesystem . . `/tmp/wordforms.dic`. |
| 18 | echoscip-shell system . . echo. $3 | awkscip-shell system . . awk. -v "fx=$fx" ' |
| 19 | fx!=2 && FILENAME!="-" && /^SFX/ && NF > 4{split($4,a,"/");clen=($3=="0") ? 0 : length($3);sfx[a[1],clen]=a[1];sfxc[a[1],clen]=clen;next} |
| 20 | fx!=1 && FILENAME!="-" && /^PFX/ && NF > 4{split($4,a,"/");clen=($3=="0") ? 0 : length($3);pfx[a[1],clen]=a[1];pfxc[a[1],clen]=clen;next} |
| 21 | FILENAME=="-"{ |
| 22 | wlen=length($1) |
| 23 | if (fx==0 || fx==2) { |
| 24 | for (j in pfx) {if (wlen<=pfxc[j]) continue; print (pfx[j]=="0" ? "" : pfx[j]) substr($1, pfxc[j]+1)} |
| 25 | } |
| 26 | if (fx==0 || fx==1) { |
| 27 | for(i in sfx){clen=sfxc[i];if (wlen<=clen) continue; print substr($1, 1, wlen-clen) (sfx[i]=="0" ? "": sfx[i]) } |
| 28 | } |
| 29 | if (fx==0) { |
| 30 | for (j in pfx) {if (wlen<=pfxc[j]) continue; |
| 31 | for(i in sfx){clen=sfxc[i];if (wlen<=clen || wlen <= (clen + pfxc[j]))continue; |
| 32 | print (pfx[j]=="0" ? "" : pfx[j]) substr($1, pfxc[j]+1, wlen-clen-pfxc[j]) (sfx[i]=="0" ? "": sfx[i]) }} |
| 33 | } |
| 34 | } |
| 35 | ' /tmp/wordforms.affscip-shell filesystem . . `/tmp/wordforms.aff`. - | hunspell -d /tmp/wordformsscip-shell filesystem . . `/tmp/wordforms`. -G -l |