class_docstr: World representation for the Atis SQL domain. This class has a ``SqlTableContext`` which holds the base
  grammars, it then augments this grammar with the entities that are detected from utterances.
  
  Parameters
  ----------
  utterances: ``List[str]``
      A list of utterances in the interaction, the last element in this list is the
      current utterance that we are interested in.
class_docstr_tok: ["World","representation","for","the","Atis","SQL","domain",".","This","class","has","a","``","SqlTableContext","``","which","holds","the","base","grammars",",","it","then","augments","this","grammar","with","the","entities","that","are","detected","from","utterances",".","Parameters","--","--","--","--","--","utterances",":","``","List","[","str","]","``","A","list","of","utterances","in","the","interaction",",","the","last","element","in","this","list","is","the","current","utterance","that","we","are","interested","in","."]
docstr: We initialize the valid actions with the global actions. We then iterate through the
  utterances up to and including the current utterance and add the valid strings.
docstr_tok: ["We","initialize","the","valid","actions","with","the","global","actions",".","We","then","iterate","through","the","utterances","up","to","and","including","the","current","utterance","and","add","the","valid","strings","."]
code: def init_all_valid_actions(self):
      """
      We initialize the valid actions with the global actions. We then iterate through the
      utterances up to and including the current utterance and add the valid strings.
      """
  
      valid_actions = deepcopy(self.sql_table_context.valid_actions)
      linking_scores = []
      current_tokenized_utterance = (
          []
          if not self.tokenized_utterances
          else self.tokenized_utterances[-1]
      )
  
      strings = set()
      for tokenized_utterance in self.tokenized_utterances:
          string_linking_dict = get_strings_from_utterance(
              tokenized_utterance
          )
          strings.update(list(string_linking_dict.keys()))
  
      # We want to sort things in reverse here to be consistent with the grammar.
      # The parser is greedy which means that if we have a rule that has
      # multiple options for the right hand side, the first one that succeeds is
      # the one that is used. For example, if ``1400`` appears in the query, and
      # both ``1400`` and ``1`` are valid numbers, then we want to try to match
      # ``1400`` first. Otherwise, ``1`` will succeed but nothing will match ``400``.
      # The same applies for strings here.
      strings_list = sorted(strings, reverse=True)
  
      # We construct the linking scores for strings from the ``string_linking_dict`` here.
      string_linking_scores = []
      for string in strings_list:
          entity_linking = [0 for token in current_tokenized_utterance]
          # string_linking_dict has the strings and linking scores from the last utterance.
          # If the string is not in the last utterance, then the linking scores will be all 0.
          for token_index in string_linking_dict.get(string, []):
              entity_linking[token_index] = 1
          string_linking_scores.append(entity_linking)
      linking_scores.extend(string_linking_scores)
  
      for string in strings_list:
          action = format_action("string", string)
          if action not in valid_actions["string"]:
              valid_actions["string"].append(action)
  
      numbers = set(["0", "1"])
      number_linking_dict = {}
  
      for utterance, tokenized_utterance in izip(
          self.utterances, self.tokenized_utterances
      ):
          number_linking_dict = get_numbers_from_utterance(
              utterance, tokenized_utterance
          )
          numbers.update(list(number_linking_dict.keys()))
      numbers_list = sorted(numbers, reverse=True)
  
      # We construct the linking scores for numbers from the ``number_linking_dict`` here.
      number_linking_scores = []
      for number in numbers_list:
          entity_linking = [0 for token in current_tokenized_utterance]
          # number_linking_scores has the numbers and linking scores from the last utterance.
          # If the number is not in the last utterance, then the linking scores will be all 0.
          for token_index in number_linking_dict.get(number, []):
              entity_linking[token_index] = 1
          number_linking_scores.append(entity_linking)
      linking_scores.extend(number_linking_scores)
  
      for number in list(numbers_list):
          action = format_action("number", number)
          valid_actions["number"].append(action)
      return valid_actions, numpy.array(linking_scores)
  
file_path: magnitude/pymagnitude/third_party/allennlp/semparse/worlds/atis_world.py
imports: from __future__ import absolute_import
  from copy import deepcopy
  import numpy
  from parsimonious.grammar import Grammar
  from allennlp.semparse.contexts.atis_tables import *
  from allennlp.semparse.contexts.sql_table_context import SqlTableContext, SqlVisitor, generate_one_of_string, format_action
  from allennlp.data.tokenizers import Token, WordTokenizer
label_desc: Use image node_id 3 for calling the AtisWorld obj's underlying member method code with example usage: obj.init_all_valid_actions() and returns: valid_actions,  numpy