trap module

Version:30.05.2011
Authors:knopsa, Alexander Weigl (re-documentation for sphinx)
trap.is_ea_consistent(ea, type)[source]

Checks if the given ea is consistent.

Returns:false, iff the ea uses any state/token, which is not a member of the state-set/ alphabet.
trap.is_sigma_consistent(sigma)[source]
trap.load(filename=None, alt_order=False)[source]

Loads a model from the given path.

Parameter: :param filename: the path of the source-file :param alt_order: the order of the tulple in case of an automata.

If false then[Q, Sigma, delta, start, F] else [Sigma, Q, delta, start, F]

The Return-value is a finite state machine or a regular expression.

Finite State Machine: A finite state Machine is a list [Q, Sigma, delta, start, F] or [Sigma, Q, delta, start, F] with - Q is a set of states (set of int values) - Sigma is a a alphabet (set of str values of length 1) - delta is the transition function (dictionary) - start is the start-state (int value) - F is a set of accept states (set of int values)

Regular Expression: The return value is a list [exp, Sigma] with - exp is the regular Expression (str vaule) - Sigma is a a alphabet (set of int values)

Returns:a list of five elements, see above
trap.save_dea(dea, filename=None, alt_order=False)[source]

Writes an DEA to the given file.

Parameters:
  • dea – an deterministic finite-state machines
  • filename – the path of the target-file
  • alt_order – the order of the DEA-tulple false: [Q, Sigma, delta, start, F] true: [Sigma, Q, delta, start, F]
Returns:

true, if the file was written successfully.

A deterministic finite-state Machine is a list

[Q, Sigma, delta, start, F] with - Q is a set of states (set of int values) - Sigma is a a alphabet (set of str values of length 1) - delta is the transition function

(dictionary: state X token -> state)
  • start is the start-state (int value)
  • F is a set of accept states (set of int values)
trap.save_enea(enea, filename=None, alt_order=False)[source]

Writes an ENEA to the given file.

Parameters:
  • enea – an nondeterministic finite-state machines with epsilon moves
  • filename – the path of the target-file
  • alt_order – the order of the ENEA-tulple false: [Q, Sigma, delta, start, F] true: [Sigma, Q, delta, start, F]

:return:true, iff the file was written successfully.

A nondeterministic finite-state machines with epsilon moves is a list [Q, Sigma, delta, start, F] with - Q is a set of states (set of int values) - Sigma is a a alphabet (set of str values of length 1) - delta is the transition function

(dictionary: state X (token + epsilon) -> set of states)
  • start is the start-state (int value)
  • F is a set of accept states (set of int values)
trap.save_nea(nea, filename=None, alt_order=False)[source]

Writes an NEA to the given file.

Parameters:
  • nea – an nondeterministic finite-state machines
  • filename – the path of the target-file
  • alt_order – the order of the NEA-tulple false: [Q, Sigma, delta, start, F] true: [Sigma, Q, delta, start, F]
Returns:

true iff the file was written successfully.

A nondeterministic finite-state machines with epsilon moves Machine is a list [Q, Sigma, delta, start, F] with - Q is a set of states (set of int values) - Sigma is a a alphabet (set of str values of length 1) - delta is the transition function

(dictionary: state X (token + epsilon) -> set of states)
  • start is the start-state (int value)
  • F is a set of accept states (set of int values)
trap.save_regex(expression, sigma, file_name=None)[source]

Writes an regular Expression to the given file.

Parameters:
  • expression – The regular Expression.
  • sigma – the Alphabet.
  • file_name – The name of the file.
Returns:

true, iff the file was written successfully.

This Page