HFST - Helsinki Finite-State Transducer Technology - Python API  version 3.12.1
 All Classes Namespaces Files Functions Variables Pages
Public Member Functions | List of all members
PrologReader Class Reference

A class for reading input in prolog text format and converting it into transducer(s). More...

Public Member Functions

def __init__
 Create a PrologReader that reads input from file f. More...
 
def __iter__
 An iterator to the reader. More...
 
def __next__
 Return next element (for python version 3). More...
 
def next
 Return next element (for python version 2). More...
 
def read
 Read next transducer. More...
 

Detailed Description

A class for reading input in prolog text format and converting it into transducer(s).

An example that reads prolog input from file 'testfile.prolog' and creates the corresponding transducers and prints them. If the input cannot be parsed, a message showing the invalid line in prolog input is printed and reading is stopped.

 with open('testfile.prolog', 'r') as f:
     try:
         r = hfst.PrologReader(f)
         for tr in r:
             print(tr)
     except hfst.exceptions.NotValidPrologFormatException as e:
         print(e.what())

Constructor & Destructor Documentation

def __init__ (   self,
  f 
)

Create a PrologReader that reads input from file f.

Parameters
fA python file.

Member Function Documentation

def __iter__ (   self)

An iterator to the reader.

Needed for 'for ... in' statement.

 for transducer in prolog_reader:
     print(transducer)
def __next__ (   self)

Return next element (for python version 3).

Needed for 'for ... in' statement.

 for transducer in prolog_reader:
     print(transducer)
Exceptions
StopIteration
def next (   self)

Return next element (for python version 2).

Needed for 'for ... in' statement.

 for transducer in prolog_reader:
     print(transducer)
Exceptions
StopIteration
def read (   self)

Read next transducer.

Read next transducer description in prolog format and return a corresponding transducer.

Exceptions
hfst.exceptions.NotValidPrologFormatException
hfst.exceptions.EndOfStreamException

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