class_docstr: A ``GrammarState`` specifies the currently valid actions at every step of decoding.
  
  If we had a global context-free grammar, this would not be necessary - the currently valid
  actions would always be the same, and we would not need to represent the current state.
  However, our grammar is not context free (we have lambda expressions that introduce
  context-dependent production rules), and it is not global (each instance can have its own
  entities of a particular type, or its own functions).
  
  We thus recognize three different sources of valid actions.  The first are actions that come
  from the type declaration; these are defined once by the model and shared across all
  ``GrammarStates`` produced by that model.  The second are actions that come from the current
  instance; these are defined by the ``World`` that corresponds to each instance, and are shared
  across all decoding states for that instance.  The last are actions that come from the current
  state of the decoder; these are updated after every action taken by the decoder, though only
  some actions initiate changes.
  
  In practice, we use the ``World`` class to get the first two sources of valid actions at the
  same time, and we take as input a ``valid_actions`` dictionary that is computed by the
  ``World``.  These will not change during the course of decoding.  The ``GrammarState`` object
  itself maintains the context-dependent valid actions.
  
  Parameters
  ----------
  nonterminal_stack : ``List[str]``
      Holds the list of non-terminals that still need to be expanded.  This starts out as
      [START_SYMBOL], and decoding ends when this is empty.  Every time we take an action, we
      update the non-terminal stack and the context-dependent valid actions, and we use what's on
      the stack to decide which actions are valid in the current state.
  lambda_stacks : ``Dict[Tuple[str, str], List[str]]``
      The lambda stack keeps track of when we're in the scope of a lambda function.  The
      dictionary is keyed by the production rule we are adding (like "r -> x", separated into
      left hand side and right hand side, where the LHS is the type of the lambda variable and
      the RHS is the variable itself), and the value is a nonterminal stack much like
      ``nonterminal_stack``.  When the stack becomes empty, we remove the lambda entry.
  valid_actions : ``Dict[str, List[int]]``
      A mapping from non-terminals (represented as strings) to all valid (global and
      instance-specific) productions from that non-terminal (represented as a list of integers).
  action_indices : ``Dict[str, int]``
      We use integers to represent productions in the ``valid_actions`` dictionary for efficiency
      reasons in the decoder.  This means we need a way to map from the production rule strings
      that we generate for lambda variables back to the integer used to represent it.
  is_nonterminal : ``Callable[[str], bool]``
      A function that is used to determine whether each piece of the RHS of the action string is
      a non-terminal that needs to be added to the non-terminal stack.  You can use
      ``type_declaraction.is_nonterminal`` here, or write your own function if that one doesn't
      work for your domain.
docstr: Takes a string like '[<d,d>, d]' and parses it into a list like ['<d,d>', 'd'].  For
  production strings that are not lists, like '<e,d>', we return a single-element list:
  ['<e,d>'].
code: def _get_productions_from_string(production_string):
      """
      Takes a string like '[<d,d>, d]' and parses it into a list like ['<d,d>', 'd'].  For
      production strings that are not lists, like '<e,d>', we return a single-element list:
      ['<e,d>'].
      """
      if production_string[0] == "[":
          return production_string[1:-1].split(", ")
      else:
          return [production_string]
  
file_path: magnitude/pymagnitude/third_party/allennlp/nn/decoding/grammar_state.py
imports: from __future__ import absolute_import
  from copy import deepcopy
label_desc: Use image node_id 5 for calling the GrammarState obj's underlying member method code with example usage: obj._get_productions_from_string(production_string) and returns: production_string, list