Skip to content

PackageHfstExceptions

eaxelson edited this page Feb 8, 2018 · 16 revisions

Package hfst.exceptions


class HfstException

Base class for HfstExceptions. Holds its own name and the file and line number where it was thrown.

  • what(): A message describing the error in more detail.

class HfstTransducerTypeMismatchException(HfstException)

Two or more HfstTransducers are not of the same type.

Thrown by:


class ImplementationTypeNotAvailableException(HfstException)

The library required by the implementation type requested is not linked to HFST.

Thrown by all functions that require an ImplementationType parameter, if the implementation is not available (for the function in question).


class FunctionNotImplementedException(HfstException)

Function has not been implemented (yet).


class FlagDiacriticsAreNotIdentitiesException(HfstException)

Flag diacritics encountered on one but not the other side of a transition.

Thrown by:


class NotValidPrologFormatException(HfstException)

The input is not in valid prolog format.

Thrown by:


class StreamNotReadableException(HfstException)

Stream cannot be read.

Thrown by: ...


class StreamCannotBeWrittenException(HfstException)

Stream cannot be written.

Thrown by


class StreamIsClosedException(HfstException)

Stream is closed.

Thrown by

An example:

try:
    tr = hfst.regex('foo')
    outstr = hfst.HfstOutputStream(filename='testfile')
    outstr.close()
    outstr.write(tr)
except hfst.exceptions.StreamIsClosedException:
    print("Could not write transducer: stream to file was closed.")

class EndOfStreamException(HfstException)

The stream is at end.

Thrown by:


class TransducerIsCyclicException(HfstException)

Transducer is cyclic.

Thrown by

An example

transducer = hfst.regex('[a:b]*')
try:
    results = transducer.extract_paths(output='text')
    print("The transducer has %i paths:" % len(results))
    print(results)
except hfst.exceptions.TransducerIsCyclicException:
    print("The transducer is cyclic and has an infinite number of paths. Some of them:")
    results = transducer.extract_paths(output='text', max_cycles=5)
    print(results)

class NotTransducerStreamException(HfstException)

The stream does not contain transducers.

Thrown by:

f = open('foofile', 'w')
f.write('This is an ordinary text file.\n')
f.close()
try:
    instr = hfst.HfstInputStream('foofile')
    tr = instr.read()
    print(tr)
    instr.close()
except hfst.exceptions.NotTransducerStreamException:
    print("Could not print transducer: the file does not contain binary transducers.")

class NotValidAttFormatException(HfstException)

The stream is not in valid AT&T format.

An example:
f = open('testfile1.att', 'w')
f.write('0 1 a b\n\
1 2 c\n\
2\n')
f.close()
f = hfst.hfst_open('testfile1.att', 'r')
try:
    tr = hfst.read_att(f)
except hfst.exceptions.NotValidAttFormatException:
    print('Could not read file: it is not in valid ATT format.')
f.close()

class NotValidLexcFormatException(HfstException)

The input is not in valid LexC format.

Thrown by: ...


class StateIsNotFinalException(HfstException)

State is not final (and cannot have a final weight).

An example :
tr = hfst.HfstBasicTransducer()
tr.add_state(1)
    An exception is thrown as state number 1 is not final
try:
    w = tr.get_final_weight(1)
except hfst.exceptions.StateIsNotFinalException:
    print("State is not final.")

You should use function hfst.HfstBasicTransducer.is_final_state if you are not sure whether a state is final.

Thrown by:


class ContextTransducersAreNotAutomataException(HfstException)

Transducers given as rule context are not automata. See also: HfstTransducer.is_automaton(self)

Thrown by:

  • two_level_if_and_only_if(context, mappings, alphabet)

class TransducersAreNotAutomataException(HfstException)

Transducers are not automata.

Example:

tr1 = hfst.regex('foo:bar')
tr2 = hfst.regex('bar:baz')
try:
    tr1.cross_product(tr2)
except hfst.exceptions.TransducersAreNotAutomataException:
    print('Transducers must be automata in cross product.')
This exception is thrown by
[[HfstTransducer.cross_product(self, another)|HfstTransducer#cross_product-self-another]]
when either input transducer does not have equivalent input and
output symbols in all its transitions.

class StateIndexOutOfBoundsException(HfstException)

The state number argument is not valid.

An example :
tr = hfst.HfstBasicTransducer()
tr.add_state(1)
try:
    w = tr.get_final_weight(2)
except hfst.exceptions.StateIndexOutOfBoundsException:
    print('State number 2 does not exist')

See also: HfstBasicTransducer.is_final_state(self, state)

Thrown by:

Todo: Return None instead of throwing an error?


class TransducerHeaderException(HfstException)

Transducer has a malformed HFST header.

Thrown by:


class MissingOpenFstInputSymbolTableException(HfstException)

An OpenFst transducer does not have an input symbol table.

When converting from OpenFst to tropical or log HFST, the OpenFst transducer
must have at least an input symbol table. If the output symbol table
is missing, it is assumed to be equivalent to the input symbol table.

class TransducerTypeMismatchException(HfstException)

Two or more transducers do not have the same type.

This can happen if (1) the calling and called transducer in a binary
operation, (2) two transducers in a pair of transducers,
(3) two consecutive transducers coming from an HfstInputStream or
(4) two transducers in a function taking two or more transducers as
arguments do not have the same type.

An example:

hfst.set_default_fst_type(hfst.types.TROPICAL_OPENFST_TYPE)
tr1 = hfst.regex('foo')
tr2 = hfst.regex('bar')
tr2.convert(hfst.types.FOMA_TYPE)
try:
    tr1.disjunct(tr2)
except hfst.exceptions.TransducerTypeMismatchException:
    print('The implementation types of transducers must be the same.')

class EmptySetOfContextsException(HfstException)

The set of transducer pairs is empty.

Thrown by rule functions.


class SpecifiedTypeRequiredException(HfstException)

The type of a transducer is not specified.

This exception is thrown when an implementation type argument is hfst.types.ERROR_TYPE.


class HfstFatalException(HfstException)

An error happened probably due to a bug in the HFST code.


class TransducerHasWrongTypeException(HfstException)

Transducer has wrong type.

This exception suggests that an HfstTransducer has not been properly
initialized, probably due to a bug in the HFST library. Alternatively
the default constructor of HfstTransducer has been called at some point.

See also: hfst.HfstTransducer.\_\_init\_\_

class IncorrectUtf8CodingException(HfstException)

String is not valid utf-8.

This exception suggests that an input string is not valid utf8.

class EmptyStringException(HfstException)

An argument string is an empty string. A transition symbol cannot be an empty string.


class SymbolNotFoundException(HfstException)

A bug in the HFST code.


class MetadataException(HfstException)

A piece of metadata in an HFST header is not supported.

Clone this wiki locally