code: def test_get_valid_actions_returns_correct_set(self):
      # This test is long, but worth it.  These are all of the valid actions in the grammar, and
      # we want to be sure they are what we expect.
  
      # This test checks that our valid actions for each type match  PNP's, except for the
      # terminal productions for type 'p'.
      valid_actions = self.world.get_valid_actions()
      assert set(valid_actions.keys()) == set(
          [
              "<#1,#1>",
              "<#1,<#1,#1>>",
              "<#1,n>",
              "<<#1,#2>,<#2,#1>>",
              "<c,d>",
              "<c,n>",
              "<c,p>",
              "<c,r>",
              "<d,c>",
              "<d,d>",
              "<d,n>",
              "<d,r>",
              "<n,<n,<#1,<<#2,#1>,#1>>>>",
              "<n,<n,<n,d>>>",
              "<n,<n,n>>",
              "<n,c>",
              "<n,d>",
              "<n,n>",
              "<n,p>",
              "<n,r>",
              "<nd,nd>",
              "<p,c>",
              "<p,n>",
              "<r,c>",
              "<r,d>",
              "<r,n>",
              "<r,p>",
              "<r,r>",
              "@start@",
              "c",
              "d",
              "n",
              "p",
              "r",
          ]
      )
  
      check_productions_match(valid_actions["<#1,#1>"], ["!="])
  
      check_productions_match(
          valid_actions["<#1,<#1,#1>>"], ["and", "or"]
      )
  
      check_productions_match(valid_actions["<#1,n>"], ["count"])
  
      check_productions_match(
          valid_actions["<<#1,#2>,<#2,#1>>"], ["reverse"]
      )
  
      check_productions_match(
          valid_actions["<c,d>"],
          ["['lambda x', d]", "[<<#1,#2>,<#2,#1>>, <d,c>]"],
      )
  
      check_productions_match(
          valid_actions["<c,n>"],
          ["['lambda x', n]", "[<<#1,#2>,<#2,#1>>, <n,c>]"],
      )
  
      check_productions_match(
          valid_actions["<c,p>"], ["[<<#1,#2>,<#2,#1>>, <p,c>]"]
      )
  
      # Most of these are instance-specific production rules.  These are the columns in the
      # table.  Remember that SEMPRE did things backwards: fb:row.row.division takes a cell ID
      # and returns the row that has that cell in its row.division column.  This is why we have
      # to reverse all of these functions to go from a row to the cell in a particular column.
      check_productions_match(
          valid_actions["<c,r>"],
          [
              "fb:row.row.null",  # This one is global, representing an empty set.
              "fb:row.row.year",
              "fb:row.row.league",
              "fb:row.row.avg_attendance",
              "fb:row.row.division",
              "fb:row.row.regular_season",
              "fb:row.row.playoffs",
              "fb:row.row.open_cup",
          ],
      )
  
      # These might look backwards, but that's because SEMPRE chose to make them backwards.
      # fb:a.b is a function that takes b and returns a.  So fb:cell.cell.date takes cell.date
      # and returns cell and fb:row.row.index takes row.index and returns row.
      check_productions_match(
          valid_actions["<d,c>"],
          ["fb:cell.cell.date", "[<<#1,#2>,<#2,#1>>, <c,d>]"],
      )
  
      check_productions_match(
          valid_actions["<d,d>"],
          ["['lambda x', d]", "[<<#1,#2>,<#2,#1>>, <d,d>]"],
      )
  
      check_productions_match(
          valid_actions["<d,n>"],
          ["['lambda x', n]", "[<<#1,#2>,<#2,#1>>, <n,d>]"],
      )
  
      check_productions_match(
          valid_actions["<d,r>"], ["[<<#1,#2>,<#2,#1>>, <r,d>]"]
      )
  
      check_productions_match(
          valid_actions["<n,<n,<#1,<<#2,#1>,#1>>>>"],
          ["argmax", "argmin"],
      )
  
      # "date" is a function that takes three numbers: (date 2018 01 06).
      check_productions_match(valid_actions["<n,<n,<n,d>>>"], ["date"])
  
      check_productions_match(valid_actions["<n,<n,n>>"], ["-"])
  
      check_productions_match(
          valid_actions["<n,c>"],
          [
              "fb:cell.cell.num2",
              "fb:cell.cell.number",
              "[<<#1,#2>,<#2,#1>>, <c,n>]",
          ],
      )
  
      check_productions_match(
          valid_actions["<n,d>"],
          ["['lambda x', d]", "[<<#1,#2>,<#2,#1>>, <d,n>]"],
      )
  
      check_productions_match(
          valid_actions["<n,n>"],
          [
              "avg",
              "sum",
              "number",
              "['lambda x', n]",
              "[<<#1,#2>,<#2,#1>>, <n,n>]",
          ],
      )
  
      check_productions_match(
          valid_actions["<n,p>"], ["[<<#1,#2>,<#2,#1>>, <p,n>]"]
      )
  
      check_productions_match(
          valid_actions["<n,r>"],
          ["fb:row.row.index", "[<<#1,#2>,<#2,#1>>, <r,n>]"],
      )
  
      check_productions_match(
          valid_actions["<nd,nd>"], ["<", "<=", ">", ">=", "min", "max"]
      )
  
      # PART_TYPE rules.  A cell part is for when a cell has text that can be split into multiple
      # parts.
      check_productions_match(
          valid_actions["<p,c>"], ["fb:cell.cell.part"]
      )
  
      check_productions_match(
          valid_actions["<p,n>"], ["['lambda x', n]"]
      )
  
      check_productions_match(
          valid_actions["<r,c>"], ["[<<#1,#2>,<#2,#1>>, <c,r>]"]
      )
  
      check_productions_match(
          valid_actions["<r,d>"], ["['lambda x', d]"]
      )
  
      check_productions_match(
          valid_actions["<r,n>"],
          ["['lambda x', n]", "[<<#1,#2>,<#2,#1>>, <n,r>]"],
      )
  
      check_productions_match(
          valid_actions["<r,p>"],
          ["['lambda x', p]", "[<<#1,#2>,<#2,#1>>, <p,r>]"],
      )
  
      check_productions_match(
          valid_actions["<r,r>"],
          [
              "fb:row.row.next",
              "fb:type.object.type",
              "[<<#1,#2>,<#2,#1>>, <r,r>]",
          ],
      )
  
      check_productions_match(
          valid_actions["@start@"], ["d", "c", "p", "r", "n"]
      )
  
      check_productions_match(
          valid_actions["c"],
          [
              "[<#1,#1>, c]",
              "[<#1,<#1,#1>>, c, c]",
              "[<n,<n,<#1,<<#2,#1>,#1>>>>, n, n, c, <n,c>]",
              "[<n,<n,<#1,<<#2,#1>,#1>>>>, n, n, c, <d,c>]",
              "[<d,c>, d]",
              "[<n,c>, n]",
              "[<p,c>, p]",
              "[<r,c>, r]",
              "fb:cell.null",
              "fb:cell.2",
              "fb:cell.2001",
              "fb:cell.2005",
              "fb:cell.4th_round",
              "fb:cell.4th_western",
              "fb:cell.5th",
              "fb:cell.6_028",
              "fb:cell.7_169",
              "fb:cell.did_not_qualify",
              "fb:cell.quarterfinals",
              "fb:cell.usl_a_league",
              "fb:cell.usl_first_division",
          ],
      )
  
      check_productions_match(
          valid_actions["d"],
          [
              "[<n,<n,<n,d>>>, n, n, n]",
              "[<#1,#1>, d]",
              "[<#1,<#1,#1>>, d, d]",
              "[<n,<n,<#1,<<#2,#1>,#1>>>>, n, n, d, <d,d>]",
              "[<n,<n,<#1,<<#2,#1>,#1>>>>, n, n, d, <n,d>]",
              "[<c,d>, c]",
              "[<nd,nd>, d]",
          ],
      )
  
      check_productions_match(
          valid_actions["n"],
          [
              "-1",
              "0",
              "1",
              "2000",
              "[<#1,#1>, n]",
              "[<#1,<#1,#1>>, n, n]",
              "[<#1,n>, c]",
              "[<#1,n>, d]",
              "[<#1,n>, n]",
              "[<#1,n>, p]",
              "[<#1,n>, r]",
              "[<c,n>, c]",
              "[<n,<n,<#1,<<#2,#1>,#1>>>>, n, n, n, <d,n>]",
              "[<n,<n,<#1,<<#2,#1>,#1>>>>, n, n, n, <n,n>]",
              "[<n,<n,n>>, n, n]",
              "[<n,n>, n]",
              "[<nd,nd>, n]",
              "[<r,n>, r]",
          ],
      )
  
      check_productions_match(
          valid_actions["p"],
          [
              "[<n,<n,<#1,<<#2,#1>,#1>>>>, n, n, p, <n,p>]",
              "[<#1,#1>, p]",
              "[<c,p>, c]",
              "[<#1,<#1,#1>>, p, p]",
              "fb:part.4th",
              "fb:part.5th",
              "fb:part.western",
          ],
      )
  
      check_productions_match(
          valid_actions["r"],
          [
              "fb:type.row",
              "[<#1,#1>, r]",
              "[<#1,<#1,#1>>, r, r]",
              "[<n,<n,<#1,<<#2,#1>,#1>>>>, n, n, r, <d,r>]",
              "[<n,<n,<#1,<<#2,#1>,#1>>>>, n, n, r, <n,r>]",
              "[<n,r>, n]",
              "[<c,r>, c]",
              "[<r,r>, r]",
          ],
      )
  
imports: from __future__ import with_statement
  from __future__ import division
  from __future__ import absolute_import
  from __future__ import print_function
  import pytest
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.data.tokenizers import Token
  from allennlp.semparse import ParsingError
  from allennlp.semparse.contexts import TableQuestionKnowledgeGraph
  from allennlp.semparse.worlds import WikiTablesWorld
label_desc: Use image node_id 2 for calling the TestWikiTablesWorld obj's underlying member method code with example usage: obj.test_get_valid_actions_returns_correct_set() without return types