File: test_att_reader.py

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 (46 lines) | stat: -rw-r--r-- 1,120 bytes parent folder | download | duplicates (3)
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
# -*- coding: utf-8 -*-
import sys
if len(sys.argv) > 1:
    sys.path.insert(0, sys.argv[1])
import hfst

transducers = []

with open('testfile.att', 'r') as f:
    r = hfst.AttReader(f, "<eps>")
    for tr in r:
        transducers.append(tr)

assert(f.closed)
assert(len(transducers)) == 4

transducers = []

with open('testfile_fail.att', 'r') as f:
    try:
        r = hfst.AttReader(f, "<eps>")
        for tr in r:
            transducers.append(tr)
    except hfst.exceptions.NotValidAttFormatException as e:
        assert("1      baz    baz      0.3" in e.what())
        assert("line: 11" in e.what())

assert(f.closed)
assert(len(transducers)) == 4

transducers = []
if sys.version_info[0] < 3:
    with open('testfile_unicode.att', 'rb') as f:
        r = hfst.AttReader(f)
        for tr in r:
            transducers.append(tr)
else:
    with open('testfile_unicode.att', 'r', encoding='utf-8') as f:
        r = hfst.AttReader(f)
        for tr in r:
            transducers.append(tr)

assert(f.closed)
assert(len(transducers)) == 1
TR = hfst.regex('föö:bär::0.5')
assert(TR.compare(transducers[0]))