Beispiel #1
0
import hfst
import hfst_commandline
harmonize=True

options = hfst_commandline.hfst_getopt('H1:2:',['--do-not-harmonize'],2)
for opt in options[0]:
    if opt[0] == '-H' or opt[0] == '--do-not-harmonize':
        harmonize=False
    else:
        pass # raise RuntimeError('Usage: hfst-compose.py INFILE1 INFILE2')

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 ' + argv[1] + ' and ' + argv[2])
ostr = hfst.HfstOutputStream(type=istr1.get_type())

while((not istr1.is_eof()) and (not istr2.is_eof())):
    tr1 = istr1.read()
    tr2 = istr2.read()
    tr1.disjunct(tr2, harmonize)
    tr1.write(ostr)
    ostr.flush()

istr1.close()
istr2.close()
Beispiel #2
0
import hfst
import hfst_commandline

level = None
short_getopts = 'p:'
long_getopts = ['project=']
options = hfst_commandline.hfst_getopt(short_getopts, long_getopts, 1)

for opt in options[0]:
    if opt[0] == '-p' or opt[0] == '--project':
        level = opt[1]

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

while (not istr.is_eof()):
    tr = istr.read()
    if (level == 'input'):
        tr.input_project()
    elif (level == 'output'):
        tr.output_project()
    else:
        raise RuntimeError(
            'hfst-project: projection level must be defined with -p [input|output]'
        )
    tr.write(ostr)
    ostr.flush()

istr.close()
ostr.close()
import hfst
import hfst_commandline
options = hfst_commandline.hfst_getopt('', [], 1)

if len(options[1]) == 0:
    raise RuntimeError('Usage: hfst-determinize.py INFILE')

istr = hfst.HfstInputStream(options[1][0])
ostr = hfst.HfstOutputStream(type=istr.get_type())

while (not istr.is_eof()):
    tr = istr.read()
    tr.determinize()
    tr.write(ostr)
    ostr.flush()

istr.close()
ostr.close()
Beispiel #4
0
import hfst
import hfst_commandline

direction=None
short_getopts='p:'
long_getopts=['push=']
options = hfst_commandline.hfst_getopt(short_getopts, long_getopts, 1)

for opt in options[0]:
    if opt[0] == '-p' or opt[0] == '--push':
        if opt[1] == 'start' or opt[1] == 'initial' or opt[1] == 'begin':
            direction = 'start'
        elif opt[1] == 'end' or opt[1] == 'final':
            direction = 'end'
        else:
            raise RuntimeError('hfst-push-weights: push direction must be one of the following [[start|initial|begin]|[end|final]]')

if direction == None:
    raise RuntimeError('Usage: hfst-push-weights.py INFILE -p [input|output]')
        
istr = hfst_commandline.get_one_hfst_input_stream(options)[0]
ostr = hfst.HfstOutputStream(type=istr.get_type())

while(not istr.is_eof()):
    tr = istr.read()
    if (direction == 'start'):
        tr.push_weights_to_start()
    elif (direction == 'end'):
        tr.push_weights_to_end()
    tr.write(ostr)
    ostr.flush()
Beispiel #5
0
import hfst
import hfst_commandline
harmonize = True

options = hfst_commandline.hfst_getopt('H1:2:', ['--do-not-harmonize'], 2)
for opt in options[0]:
    if opt[0] == '-H' or opt[0] == '--do-not-harmonize':
        harmonize = False
    else:
        pass  # raise RuntimeError('Usage: hfst-compose.py INFILE1 INFILE2')

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])
ostr = hfst.HfstOutputStream(type=istr1.get_type())

while ((not istr1.is_eof()) and (not istr2.is_eof())):
    tr1 = istr1.read()
    tr2 = istr2.read()
    tr1.compose(tr2, harmonize)
    tr1.write(ostr)
    ostr.flush()

istr1.close()
istr2.close()
Beispiel #6
0
import hfst
import hfst_commandline
options = hfst_commandline.hfst_getopt('',[],1)

if len(options[1]) == 0:
    raise RuntimeError('Usage: hfst-determinize.py INFILE')

istr = hfst.HfstInputStream(options[1][0])
ostr = hfst.HfstOutputStream(type=istr.get_type())

while(not istr.is_eof()):
    tr = istr.read()
    tr.determinize()
    tr.write(ostr)
    ostr.flush()

istr.close()
ostr.close()
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()