File: hfst-repeat.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 (31 lines) | stat: -rw-r--r-- 666 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
import hfst
import hfst_commandline
minimum=0
maximum='inf'

short_getopts='f:t:'
long_getopts=['from=', 'to=']
options = hfst_commandline.hfst_getopt(short_getopts, long_getopts, 1)

for opt in options[0]:
    if opt[0] == '-f' or opt[0] == '--from':
        minimum = int(opt[1])
    elif opt[0] == '-t' or opt[0] == '--to':
        maximum = int(opt[1])
    else:
        pass

istr = hfst_commandline.get_one_hfst_input_stream(options)[0]
ostr = hfst.HfstOutputStream(type=istr.get_type())

tr = istr.read()

if (maximum == 'inf'):
    tr.repeat_n_plus(minimum)
else:
    tr.repeat_n_to_k(minimum, maximum)

tr.write(ostr)
ostr.flush()
istr.close()
ostr.close()