|
HFST - Helsinki Finite-State Transducer Technology - Python API
version 3.11.0
|
A stream for writing binary transducers. More...
Public Member Functions | |
| def | __init__ |
| Open a stream for writing binary transducers. More... | |
| def | close |
| Close the stream. More... | |
| def | flush |
| Flush the stream. More... | |
| def | write |
| Write the transducer transducer in binary format to the stream. More... | |
A stream for writing binary transducers.
An example:
res = ['foo:bar','0','0 - 0','"?":?','a* b+']
ostr = hfst.HfstOutputStream(filename='testfile1.hfst')
for re in res:
ostr.write(hfst.regex(re))
ostr.flush()
ostr.close()For more information on HFST transducer structure, see this page.
| def __init__ | ( | self, | |
| kvargs | |||
| ) |
Open a stream for writing binary transducers.
| kvargs | Arguments recognized are filename, hfst_format, type. |
| filename | The name of the file where transducers are written. If the file exists, it is overwritten. If filename is not given, transducers are written to standard output. |
| hfst_format | Whether transducers are written in hfst format (default is True) or as such in their backend format. |
| type | The type of the transducers that will be written to the stream. Default is hfst.get_default_fst_type(). |
ostr = hfst.HfstOutputStream() # a stream for writing default type transducers in hfst format to standard output
transducer = hfst.regex('foo:bar::0.5')
ostr.write(transducer)
ostr.flush() ostr = hfst.HfstOutputStream(filename='transducer.sfst', hfst_format=False, type=hfst.types.SFST_TYPE) # a stream for writing SFST_TYPE transducers in their back-end format to a file
transducer1 = hfst.regex('foo:bar')
transducer1.convert(hfst.types.SFST_TYPE) # if not set as the default type
transducer2 = hfst.regex('bar:baz')
transducer2.convert(hfst.types.SFST_TYPE) # if not set as the default type
ostr.write(transducer1)
ostr.write(transducer2)
ostr.flush()
ostr.close()
| def close | ( | ) |
Close the stream.
If the stream points to standard output, nothing is done.
| def flush | ( | ) |
Flush the stream.
| def write | ( | transducer | ) |
Write the transducer transducer in binary format to the stream.
All transducers must have the same type as the stream, else a TransducerTypeMismatchException is thrown.
1.8.7