| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | set -e -u |
| 4 | |
| 5 | if [[ $# -eq 1 ]]; then |
| 6 | lang=$1 |
| 7 | monodix=guess |
| 8 | bidix=guess |
| 9 | side=guess |
| 10 | elif [[ $# -eq 4 ]]; then |
| 11 | lang=$1 |
| 12 | monodix=$2 |
| 13 | bidix=$3 |
| 14 | side=$4 |
| 15 | else |
| 16 | catscip-shell system . . cat. >&2 <<EOF |
| 17 | Usage: $0 lang |
| 18 | or: $0 lang mono.dix bi.dix [r|l] |
| 19 | |
| 20 | Expands the analyser, and looks up all the bidix entries in the |
| 21 | expanded analyser. |
| 22 | |
| 23 | For example, do \`$0 nno' in trunk/apertium-nno-nob/' to find |
| 24 | nno-words that are in bidix but not the nno-analyser. If the source |
| 25 | .dix files have a non-standard name, you can specify them in the |
| 26 | second and third arguments, for example |
| 27 | \`$0 eng ../apertium-eng_feil/apertium-eng.eng.dix apertium-eng-sco.eng-sco.dix l' |
| 28 | (where \`l' means eng is the left-side of the bidix). |
| 29 | EOF |
| 30 | exit 1 |
| 31 | fi |
| 32 | |
| 33 | |
| 34 | if [[ ${monodix} = guess ]]; then |
| 35 | langdir=$(grepscip-shell system . . grep. -m1 "^AP_SRC.*apertium-${lang}" config.log | sedscip-shell system . . sed. "s/^[^=]*='//;s/'$//") |
| 36 | monodix=${langdir}/apertium-${lang}.${lang}.dix |
| 37 | fi |
| 38 | if [[ ${bidix} = guess ]]; then |
| 39 | basename=$(grepscip-shell system . . grep. -m1 "^PACKAGE='apertium-" config.log | sedscip-shell system . . sed. "s/^[^=]*='//;s/'$//") |
| 40 | pair=${basename##apertium-} |
| 41 | bidix=${basename}.${pair}.dix |
| 42 | fi |
| 43 | if [[ ${side} = guess ]]; then |
| 44 | if [[ ${lang} = ${pair%%-*} ]]; then |
| 45 | side=l |
| 46 | else |
| 47 | side=r |
| 48 | fi |
| 49 | fi |
| 50 | |
| 51 | exp=$(mktempscip-shell system . . mktemp. -t bidix-unknowns.XXXXXXXX) |
| 52 | trap 'rm -f "${exp}"' EXIT |
| 53 | |
| 54 | echoscip-shell system . . echo. "Expanding monodix …" >&2 |
| 55 | lt-expand "${monodix}" \ |
| 56 | | grepscip-shell system . . grep. -ve __REGEXP__ \ |
| 57 | | sedscip-shell system . . sed. 's/[^:]*//; s/\(<.*>\)\(#.*\)/\2\1/' \ |
| 58 | | LC_ALL=C sortscip-shell system . . sort. -u >"${exp}" |
| 59 | |
| 60 | in_monoscip-shell shell apertium-swe-nor 0.4.0-1 in_mono(). () { |
| 61 | # bidix has prefixes of monodix, have to use look instead of comm :-/ |
| 62 | LC_ALL=C lookscip-shell system . . look. "$1" "${exp}" >/dev/nullscip-shell filesystem . . `/dev/null`. |
| 63 | } |
| 64 | echoscip-shell system . . echo. "Expanding bidix and checking for entries missing from monodix …" >&2 |
| 65 | lt-expand "${bidix}" \ |
| 66 | | awkscip-shell system . . awk. -vside="${side}" -F':|:[<>]:' ' |
| 67 | BEGIN { |
| 68 | if(side=="l") { |
| 69 | nside=1 |
| 70 | LR=":>:" |
| 71 | RL=":<:" |
| 72 | } |
| 73 | else { |
| 74 | nside=2 |
| 75 | LR=":<:" # flip it |
| 76 | RL=":>:" # and reverse |
| 77 | } |
| 78 | } |
| 79 | # Make bidix match up with monodix (left=left, right=right): |
| 80 | /:>:/ { print LR $nside; next } |
| 81 | /:<:/ { print RL $nside; next } |
| 82 | /:/ { print ":"$nside } |
| 83 | ' \ |
| 84 | | while read -r bientry; do |
| 85 | # Bidix now normalised to have the requested monodix on the "left" |
| 86 | case ${bientry} in |
| 87 | ":>:"* ) # If it's LR in bidix, then we check if unmarked / LR is in monodix |
| 88 | in_monoscip-shell shell apertium-swe-nor 0.4.0-1 in_mono(). "${bientry##:>}" || in_monoscip-shell shell apertium-swe-nor 0.4.0-1 in_mono(). "${bientry}" || echoscip-shell system . . echo. "${bientry}" |
| 89 | ;; |
| 90 | ":<:"* ) # If it's RL in bidix, then we check if unmarked / RL is in monodix |
| 91 | in_monoscip-shell shell apertium-swe-nor 0.4.0-1 in_mono(). "${bientry##:<}" || in_monoscip-shell shell apertium-swe-nor 0.4.0-1 in_mono(). "${bientry}" || echoscip-shell system . . echo. "${bientry}" |
| 92 | ;; |
| 93 | ":"* ) # If it's unmarked in bidix, then we check if unmarked / LR / RL in monodix |
| 94 | in_monoscip-shell shell apertium-swe-nor 0.4.0-1 in_mono(). "${bientry}" || in_monoscip-shell shell apertium-swe-nor 0.4.0-1 in_mono(). ":>${bientry}" || in_monoscip-shell shell apertium-swe-nor 0.4.0-1 in_mono(). ":<${bientry}" || echoscip-shell system . . echo. "${bientry}" |
| 95 | ;; |
| 96 | *) echoscip-shell system . . echo. "ERROR: unexpected bientry format: ${bientry}" >&2;; |
| 97 | esac |
| 98 | done |