File: fst2strings-functionality.sh

package info (click to toggle)
hfst 3.16.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 14,532 kB
  • sloc: cpp: 101,875; sh: 6,717; python: 5,225; yacc: 4,985; lex: 2,900; makefile: 2,017; xml: 6
file content (98 lines) | stat: -rwxr-xr-x 3,038 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/sh
TOOLDIR=../../tools/src
TOOL=
FORMAT_TOOL=

if [ "$1" = '--python' ]; then
    TOOL="python3 ./hfst-fst2strings.py"
    FORMAT_TOOL="python3 ./hfst-format.py"
else
    TOOL=$TOOLDIR/hfst-fst2strings
    FORMAT_TOOL=$TOOLDIR/hfst-format
    for tool in $TOOL $FORMAT_TOOL; do
	if ! test -x $tool; then
	    exit 77;
	fi
    done
fi

for i in "" .sfst .ofst .foma; do
if ((test -z "$i") || $FORMAT_TOOL --list-formats | grep $i > /dev/null); then
    if test -f cat$i ; then
        if ! $TOOL cat$i > test.strings ; then
            echo turning cat$i to strings failed
            exit 1
        fi
        if ! diff test.strings cat.strings; then # > /dev/null 2>&1 ; then
            echo cat$i strings differ from expected
            exit 1
        fi
        rm test.strings;
    fi

    # extract 20 times 5 random strings and check that flags are obeyed
    if test -f unification_flags$i ; then
        for foo in 0 1
        do
            for bar in 0 1 2 3 4 5 6 7 8 9
            do
                if ! $TOOL --random 5 -X obey-flags \
                    unification_flags$i > test.strings ; then
                    echo extracting random flags from unification_flags$i failed
                    exit 1
                fi
            # flags do not allow [A|B|C] with [a|b|c]
                if (egrep "A|B|C" test.strings | egrep "a|b|c" > tmp); then
                        echo "error in processing flags in "unification_flags$i": the following path is not valid:"
                        cat tmp
                        exit 1
                fi
            done
        done
    fi

    # extract 5 times 100 random strings and check that the flags are obeyed, i.e. no string is accepted
    if test -f unification_flags_fail$i ; then
        for foo in 0 1 2 3 4
        do
            if ! $TOOL --random 100 -X obey-flags \
                unification_flags_fail$i > test.strings ; then
                echo extracting random flags from unification_flags_fail$i failed
                exit 1
            fi
            if ! (wc -l test.strings | grep '^ *0 ' > /dev/null); then
                echo "error in processing flags in "unification_flags$i": the following paths are not valid:"
                cat test.strings
                exit 1
            fi
        done
    fi
fi
done

for i in "" .sfst .ofst .foma; do
if ((test -z "$i") || $FORMAT_TOOL --list-formats | grep $i > /dev/null); then
    # Test the empty transducer
    if test -f empty$i ; then
	if ! $TOOL -r 20 empty$i > /dev/null ; then
	    echo "searching for random paths in an empty transducer failed"
	    exit 1
	fi
    fi

    # Test that epsilon paths are not accepted
    if test -f id_star_a_b_c$i ; then

        if ! ($TOOL -r 10 id_star_a_b_c$i > tmp); then
            echo "extracting random strings from id_star_a_b_c"$i" failed"
            exit 1
        fi

        if (grep '^$' tmp > /dev/null); then
            echo "the empty string should not be recognized: "$i
            exit 1
        fi

    fi
fi
done