File: hfst-compose-intersect.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 (26 lines) | stat: -rw-r--r-- 721 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
import hfst
import hfst_commandline

options = hfst_commandline.hfst_getopt('1:2:',[],2)
istreams = hfst_commandline.get_two_hfst_input_streams(options)
istr1 = istreams[0][0]
istr2 = istreams[1][0]

if (istr1.get_type() != istr2.get_type()):
    raise RuntimeError('Error: transducer types differ in ' + istreams[0][1] + ' and ' + istreams[1][1])

tr1 = istr1.read()
if not istr1.is_eof():
    raise RuntimeError('Error: ' + infile1 + ' must contain exactly one transducer')
istr1.close()

transducers = []
while(not istr2.is_eof()):
    transducers.append(istr2.read())
istr2.close()

tr1.compose_intersect(transducers, False)
ostr = hfst.HfstOutputStream(type=tr1.get_type())
ostr.write(tr1)
ostr.flush()
ostr.close()