File: tokenize-flushing-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 (75 lines) | stat: -rwxr-xr-x 1,998 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
#!/bin/sh

if [ "$1" = "--python" ]; then
    exit 77
fi

TOOLDIR=../../tools/src

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

if ! command -V timeout >/dev/null 2>/dev/null; then
    # require /usr/bin/timeout, since it could hang if there's a bug
    exit 77
fi

# Prerequisites
if ! $TOOLDIR/hfst-lexc -q < $srcdir/tokenize-dog-in.lexc > $srcdir/tokenize-dog-gen.hfst; then
    echo lexc dog fail
    exit 1
fi
if ! $TOOLDIR/hfst-invert < $srcdir/tokenize-dog-gen.hfst > $srcdir/tokenize-dog.hfst; then
    echo invert dog fail
    exit 1
fi
if ! $TOOLDIR/hfst-pmatch2fst < $srcdir/tokenize-dog.pmscript > $srcdir/tokenize-dog.pmhfst; then
    echo pmatch2fst tokenize-dog fail
    exit 1
fi

tmpd=$(mktemp -d -t hfst-tokenize-tests.XXXXXXXX)
to="${tmpd}/to"
from="${tmpd}/from"
mkfifo "${to}" "${from}"

# Server:
$TOOLDIR/hfst-tokenize --giella-cg --superblanks $srcdir/tokenize-dog.pmhfst <"${to}" >"${from}" &
pid=$!
trap 'kill $pid; wait $pid 2>/dev/null; rm -rf "${tmpd}"' EXIT


# Client:
exec 3>"${to}"
exec 4<"${from}"
for _ in test a couple times; do
    timeout 1 printf 'dog[\\\n<\\\\>]cat !and \ndogs[][\n]\0' >&3
    case $? in
        0) : ;;
        124) echo tokenize --giella-cg flushing write timed out
             exit 1
             ;;
        *) echo tokenize --giella-cg flushing write failed with "$?"
           exit 1
           ;;
    esac
    timeout 1 sed '/^<STREAMCMD:FLUSH>$/{q}' <&4 >test.strings
    case $? in
        0) : ;;
        124) echo tokenize --giella-cg flushing read timed out
             exit 1
             ;;
        *) echo tokenize --giella-cg flushing read failed with "$?", output is:
           cat test.strings
           exit 1
           ;;
    esac
    if ! diff test.strings $srcdir/tokenize-dog-out-giella-cg-flushing.strings ; then
        echo diff test.strings $srcdir/tokenize-dog-out-giella-cg-flushing.strings
        exit 1
    fi
done

rm test.strings tokenize-dog.pmhfst tokenize-dog.hfst tokenize-dog-gen.hfst
exit 0