Skip to content

HfstInputStream

eaxelson edited this page Aug 29, 2017 · 12 revisions

class HfstInputStream

A stream for reading HFST binary transducers.

An example:

istr = hfst.HfstInputStream('testfile1.hfst')
transducers = []
while not (istr.is_eof()):
    transducers.append(istr.read())
istr.close()
print("Read %i transducers in total." % len(transducers))

For documentation on the HFST binary transducer format, see here. class HfstInputStream:

init(self, filename=None)

Create a stream for reading binary transducers.

  • filename The name of the transducer file. If not given, standard input is used.

Throws: StreamNotReadableException Throws: NotTransducerStreamException Throws: EndOfStreamException Throws: TransducerHeaderException

istr_to_stdin = hfst.HfstInputStream()
istr_to_file = hfst.HfstInputStream(filename='transducer.hfst')

close(self)

Close the stream.

If the stream points to standard input, nothing is done.

is_eof(self)

Whether the stream is at end.

is_bad(self)

Whether badbit is set.

is_good(self)

Whether the state of the stream is good for input operations.

get_type(self)

The type of the first transducer in the stream.

By default, all transducers in a stream have the same type, else a TransducerTypeMismatchException is thrown when reading the first transducer that has a different type than the previous ones.

read(self)

Return next transducer.

Throws: EndOfStreamException