@@ -9,12 +9,18 @@ function print_usage() {
99 echo
1010 echo " -h, --help Print this usage info"
1111 echo " -m, --merge-homonyms Count homonyms as one entry, default=count each homonym"
12- echo " -c, --giella-core PATH Path to giella-core, if not given will try to find from $0 "
12+ echo " -c, --giella-core PATH Path to giella-core, if not given will try to find from \$ 0"
13+ echo " -s, --custom-script SCRIPT Use custom script to count lemmas instead of default"
14+ echo " The script will be called with INPUTDIR as argument and"
15+ echo " should output the lemma count to stdout"
16+ echo
17+ echo " Note: If INPUTDIR/src/fst/morphology/lemma-count.sh exists and is executable,"
18+ echo " it will be used automatically (unless --custom-script overrides it)."
1319 echo
1420}
1521
1622# Wrong usage - short instruction:
17- if (( $# < 1 || $# > 3 )) ; then
23+ if (( $# < 1 )) ; then
1824 print_usage
1925 exit 1
2026fi
@@ -29,6 +35,9 @@ while test $# -ge 1 ; do
2935 elif test x$1 = x--giella-core -o x$1 = x-c ; then
3036 giella_core=$2
3137 shift
38+ elif test x$1 = x--custom-script -o x$1 = x-s ; then
39+ custom_script=$2
40+ shift
3241 elif test -d " $1 " ; then
3342 inputdir=" $1 "
3443 else
5463 homonyms=" -H"
5564fi
5665
66+ # Initialise:
5767lemmacount=0
68+
69+ # Check for custom counting script
70+ # Priority: 1) --custom-script option, 2) language repo's lemma-count.sh, 3) default logic
71+ if test -n " $custom_script " ; then
72+ # Use manually specified custom script
73+ if test ! -x " $custom_script " ; then
74+ echo " $0 : Error: Custom script not found or not executable: $custom_script " >&2
75+ exit 1
76+ fi
77+ lemmacount=$( " $custom_script " " $inputdir " )
78+ elif test -x " $inputdir /src/fst/morphology/lemma-count.sh" ; then
79+ # Use language repo's lemma-count.sh if it exists
80+ lemmacount=$( " $inputdir /src/fst/morphology/lemma-count.sh" " $inputdir " )
81+ fi
82+
83+ # Default logic for standard repository structures
5884if compgen -G " $inputdir /src/fst/morphology/stems/*.lexc" > /dev/null; then
5985 lemmacounts=$( for f in " $inputdir " /src/fst/morphology/stems/* .lexc ; do
6086 " $GIELLA_CORE " /scripts/extract-lemmas.sh $homonyms " $f " | # extract all lemmas for each stem file
0 commit comments