This module contains code relating to processing logical forms for semantic parsing. The main functionality provided by this code is:

1. A way of declaring a type system for use in processing logical forms. This determines which (lisp-like) logical forms are valid in your logical form language, and it enables us to parse statements in that language into logical expressions. We rely heavily on NLTK for the logic processing here. This is the type_declarations module.

2. A way of specifying extra “context” that’s available to the parser / type system. Currently, this just consists of a KnowledgeGraph that can represent table entities, or question-specific entities. These entities can be made available to the type system to allow context-specific production rules. This is the contexts module.

3. A way to bundle the two things above together in the context of a particular training / testing instance. This bundling is called a World, and this is the primary means that a model should use to interact with the type system. The World has methods to get all possible actions in any state, all context entities that need to be linked, and so on. This is the worlds module.

Note that the main reason you would use this code is to get the set of actions that are available at any point during constrained decoding. If you have some other means of doing that, you might not need this code at all.

class allennlp.semparse.action_space_walker.ActionSpaceWalker(world: allennlp.semparse.domain_languages.domain_language.DomainLanguage, max_path_length: int)[source]

Bases: object

ActionSpaceWalker takes a world, traverses all the valid paths driven by the valid action specification of the world to generate all possible logical forms (under some constraints). This class also has some utilities for indexing logical forms to efficiently retrieve required subsets.


The world (domain language instantiation) from which valid actions will be taken.


The maximum path length till which the action space will be explored. Paths longer than this length will be discarded.

get_all_logical_forms(self, max_num_logical_forms: int = None) → List[str][source]
get_logical_forms_with_agenda(self, agenda: List[str], max_num_logical_forms: int = None, allow_partial_match: bool = False) → List[str][source]
max_num_logical_formsint (optional)
allow_partial_matchbool (optional, defaul=False)

If set, this method will return logical forms which contain not necessarily all the items on the agenda. The returned list will be sorted by how many items the logical forms match.