tr = instr.read() print(tr) instr.close() except libhfst.NotTransducerStreamException: print( "Could not print transducer: the file does not contain binary transducers." ) f = open('testfile1.att', 'w') f.write('0 1 a b\n\ 1 2 c\n\ 2\n') f.close() f = libhfst.hfst_open('testfile1.att', 'r') try: tr = libhfst.read_att(f) except libhfst.NotValidAttFormatException: print('Could not read file: it is not in valid ATT format.') f.close() # StateIsNotFinalException tr = libhfst.HfstBasicTransducer() tr.add_state(1) # An exception is thrown as state number 1 is not final try: w = tr.get_final_weight(1) except libhfst.StateIsNotFinalException: print("State is not final.") # ContextTransducersAreNotAutomataException # try:
import libhfst f = libhfst.hfst_stdin() while not f.is_eof(): print(libhfst.read_att(f))
tr.set_final_weights(0.4, True) # reading and writing in text format f = open('testfile.att', 'w') f.write('0 1 foo bar 0.5\n\ 0 1 fo ba 0.2\n\ 0 1 f b 0\n\ 1 2 baz baz\n\ 2 0.1\n\ --\n') f.close() numtr = 0 f = libhfst.hfst_open('testfile.att', 'r') while not f.is_eof(): TR = libhfst.read_att(f) numtr += 1 try: libhfst.read_att(f) except libhfst.EndOfStreamException: pass f.close() if numtr != 2: raise RuntimeError(get_linenumber()) f = libhfst.hfst_open('foo_att_prolog', 'w') f.write('-- in ATT format --\n') TR.write_att(f) f.write('-- in prolog format --\n') TR.write_prolog(f, 'FOOBAR_TRANSDUCER') f.close()
tr = instr.read() print(tr) instr.close() except libhfst.NotTransducerStreamException: print("Could not print transducer: the file does not contain binary transducers.") f = open("testfile1.att", "w") f.write( "0 1 a b\n\ 1 2 c\n\ 2\n" ) f.close() f = libhfst.hfst_open("testfile1.att", "r") try: tr = libhfst.read_att(f) except libhfst.NotValidAttFormatException: print("Could not read file: it is not in valid ATT format.") f.close() # StateIsNotFinalException tr = libhfst.HfstBasicTransducer() tr.add_state(1) # An exception is thrown as state number 1 is not final try: w = tr.get_final_weight(1) except libhfst.StateIsNotFinalException: print("State is not final.") # ContextTransducersAreNotAutomataException # try: