File: pmatch2fst-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 (69 lines) | stat: -rwxr-xr-x 1,894 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
#!/bin/sh
TOOLDIR=../../tools/src
PMATCH2FST=
PMATCH=

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

if [ "$srcdir" = "" ] ; then
    srcdir=. ;
fi

if ! $PMATCH2FST $srcdir/pmatch_blanks.txt > test.pmatch ; then
    exit 1
fi
# Test with any old string
if ! $PMATCH --newline test.pmatch < $srcdir/cat.strings > pmatch.out ; then
    exit 1
fi

echo 'set need-separators off regex [\Whitespace]+ EndTag(Q);' | $PMATCH2FST > test.pmatch

echo 'a b  c' | $PMATCH --newline test.pmatch > pmatch.out
if ! echo '<Q>a</Q> <Q>b</Q>  <Q>c</Q>' | diff pmatch.out - > /dev/null ; then
    exit 1
fi

# printf to workaround a weird bug with \x22 when bash is called as /bin/sh on macos:
printf '%s\n' 'set need-separators off regex "\x22" EndTag(Q);' | $PMATCH2FST > test.pmatch

echo 'a "b"  c' | $PMATCH --newline test.pmatch > pmatch.out
if ! echo 'a <Q>"</Q>b<Q>"</Q>  c' | diff pmatch.out - > /dev/null ; then
    exit 1
fi

echo 'set need-separators off regex "\"" EndTag(Q);' | $PMATCH2FST > test.pmatch

echo 'a "b"  c' | $PMATCH --newline test.pmatch > pmatch.out
if ! echo 'a <Q>"</Q>b<Q>"</Q>  c' | diff pmatch.out - > /dev/null ; then
    exit 1
fi

echo 'set need-separators off regex {"} EndTag(Q);' | $PMATCH2FST > test.pmatch

echo 'a "b"  c' | $PMATCH --newline test.pmatch > pmatch.out
if ! echo 'a <Q>"</Q>b<Q>"</Q>  c' | diff pmatch.out - > /dev/null ; then
    exit 1
fi

echo 'set need-separators off regex %" EndTag(Q);' | $PMATCH2FST > test.pmatch

echo 'a "b"  c' | $PMATCH --newline test.pmatch > pmatch.out
if ! echo 'a <Q>"</Q>b<Q>"</Q>  c' | diff pmatch.out - > /dev/null ; then
    exit 1
fi

rm -f pmatch.out test.pmatch
exit 0