Deterministic Generator module

This file deterministically generates strings from a JSGF Grammar, whether there are weights defined in rules or not. It requires one argument: the path to the JSGF Grammar file. You can run this on the included grammar IdeasNonRecursive.gram:

python DeterministicGenerator.py IdeasNonRecursive.gram

This will generate all strings defined by the public rules of IdeasNonRecursive.gram. It is important that the grammar used by the generator is not recursive (rules should not directly or indirectly reference themselves), so that the generator terminates. Otherwise, you may get a maximum recursion depth exceeded error or a segmentation fault.

DeterministicGenerator.combineSets(listOfSets)

Combines sets of strings by taking the cross product of the sets and concatenating the elements in the resulting tuples

Parameters:listOfSets – 2-D list of strings
Returns:a list of strings
DeterministicGenerator.processDisjunction(disj)

Returns the string representations of a set of alternatives

Returns:list of strings, where each string is each alternative
DeterministicGenerator.processNonTerminal(nt)

Finds the rule expansion for a nonterminal and returns its expansion.

DeterministicGenerator.processOptional(opt)

Returns the string representations of an optional grouping

Returns:list of strings, including an empty string
DeterministicGenerator.processRHS(rhs)

Depending on the type of the argument, calls the corresponding function to deal with that type.

Parameters:rhs (either a JSGF Expression, list, or string) – portion of JSGF rule
Returns:list of strings
DeterministicGenerator.processSequence(seq)

Combines adjacent elements in a sequence

Previous topic

Probabilistic Generator module

This Page