HFST - Helsinki Finite-State Transducer Technology - Python API  version 3.12.3 (under development)
Public Member Functions | List of all members
HfstInputStream Class Reference

A stream for reading HFST binary transducers. More...

Public Member Functions

def __init__ (self, filename=None)
 Create a stream for reading binary transducers. More...
 
def close (self)
 Close the stream. More...
 
def get_type (self)
 The type of the first transducer in the stream. More...
 
def is_bad (self)
 Whether badbit is set. More...
 
def is_eof (self)
 Whether the stream is at end. More...
 
def is_good (self)
 Whether the state of the stream is good for input operations. More...
 
def read (self)
 Return next transducer. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

def __init__ (   self,
  filename = None 
)

Create a stream for reading binary transducers.

Parameters
filenameThe name of the transducer file. If not given, standard input is used.
Exceptions
StreamNotReadableException
NotTransducerStreamException
EndOfStreamException
TransducerHeaderException
 istr_to_stdin = hfst.HfstInputStream()
 istr_to_file = hfst.HfstInputStream(filename='transducer.hfst')

Member Function Documentation

def close (   self)

Close the stream.

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

def 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.

def is_bad (   self)

Whether badbit is set.

def is_eof (   self)

Whether the stream is at end.

def is_good (   self)

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

def read (   self)

Return next transducer.

Exceptions
EndOfStreamException

The documentation for this class was generated from the following file: