Ejemplo n.º 1
0
    def test_get_nonterminal_productions_all_column_types(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.
        productions = self.language.get_nonterminal_productions()
        assert set(productions.keys()) == {
            "@start@",
            "<List[Row],StringColumn:List[str]>",
            "<List[Row],DateColumn:Date>",
            "<List[Row],NumberColumn,Number:List[Row]>",
            "<List[Row],ComparableColumn:List[Row]>",
            "<List[Row],Column:List[Row]>",
            "<List[Row],List[Row],NumberColumn:Number>",
            "<List[Row],StringColumn,List[str]:List[Row]>",
            "<Number,Number,Number:Date>",
            "<List[Row],DateColumn,Date:List[Row]>",
            "<List[Row],NumberColumn:Number>",
            "<List[Row]:List[Row]>",
            '<List[Row],StringColumn:List[str]>',
            "<List[Row]:Number>",
            "List[str]",
            "List[Row]",
            "Date",
            "Number",
            "StringColumn",
            "NumberColumn",
            "ComparableColumn",
            "Column",
            "DateColumn",
            "List[str]",
        }

        check_productions_match(productions['@start@'],
                                ['Date', 'Number', 'List[str]'])

        check_productions_match(
            productions['<List[Row],StringColumn:List[str]>'],
            ['select_string', 'mode_string'])

        check_productions_match(
            productions['<List[Row],DateColumn:Date>'],
            ['select_date', 'max_date', 'min_date', 'mode_date'])

        check_productions_match(
            productions['<List[Row],NumberColumn,Number:List[Row]>'], [
                'filter_number_equals', 'filter_number_greater',
                'filter_number_greater_equals', 'filter_number_lesser',
                'filter_number_lesser_equals', 'filter_number_not_equals'
            ])

        check_productions_match(
            productions['<List[Row],ComparableColumn:List[Row]>'],
            ['argmax', 'argmin'])

        check_productions_match(productions['<List[Row],Column:List[Row]>'],
                                ['same_as'])

        check_productions_match(
            productions['<List[Row],List[Row],NumberColumn:Number>'], ['diff'])

        check_productions_match(
            productions['<List[Row],StringColumn,List[str]:List[Row]>'],
            ['filter_in', 'filter_not_in'])

        check_productions_match(productions['<Number,Number,Number:Date>'],
                                ['date'])

        check_productions_match(
            productions['<List[Row],DateColumn,Date:List[Row]>'], [
                'filter_date_equals', 'filter_date_greater',
                'filter_date_greater_equals', 'filter_date_lesser',
                'filter_date_lesser_equals', 'filter_date_not_equals'
            ])

        check_productions_match(productions['<List[Row],NumberColumn:Number>'],
                                [
                                    'average', 'max_number', 'min_number',
                                    'sum', 'select_number', 'mode_number'
                                ])

        check_productions_match(productions['<List[Row]:List[Row]>'],
                                ['first', 'last', 'next', 'previous'])

        check_productions_match(productions['<List[Row]:Number>'], ['count'])

        check_productions_match(
            productions['List[Row]'],
            [
                'all_rows',
                '[<List[Row],Column:List[Row]>, List[Row], Column]',
                '[<List[Row],DateColumn,Date:List[Row]>, List[Row], DateColumn, Date]',
                '[<List[Row],ComparableColumn:List[Row]>, List[Row], ComparableColumn]',
                '[<List[Row],NumberColumn,Number:List[Row]>, List[Row], NumberColumn, Number]',
                '[<List[Row],StringColumn,List[str]:List[Row]>, List[Row], StringColumn, List[str]]',  # pylint: disable=line-too-long
                '[<List[Row]:List[Row]>, List[Row]]'
            ])

        check_productions_match(productions['Date'], [
            '[<Number,Number,Number:Date>, Number, Number, Number]',
            '[<List[Row],DateColumn:Date>, List[Row], DateColumn]'
        ])

        # Some of the number productions are instance-specific, and some of them are from the
        # grammar.
        check_productions_match(productions['Number'], [
            '2001', '2002', '2005', '2010', '2013', '-1', '1', '2', '23',
            '8000',
            '[<List[Row],NumberColumn:Number>, List[Row], NumberColumn]',
            '[<List[Row],List[Row],NumberColumn:Number>, List[Row], List[Row], NumberColumn]',
            '[<List[Row]:Number>, List[Row]]'
        ])

        # These are the columns in table, and are instance specific.
        check_productions_match(productions['StringColumn'], [
            'string_column:league', 'string_column:playoffs',
            'string_column:open_cup', 'string_column:year',
            'string_column:division', 'string_column:avg_attendance',
            'string_column:regular_season'
        ])

        check_productions_match(productions['DateColumn'],
                                ['date_column:year'])

        check_productions_match(productions['NumberColumn'], [
            'number_column:avg_attendance', 'number_column:open_cup',
            'number_column:regular_season', 'number_column:division',
            'number_column:year'
        ])

        check_productions_match(productions['ComparableColumn'], [
            'date_column:year', 'number_column:avg_attendance',
            'number_column:open_cup', 'number_column:regular_season',
            'number_column:division', 'number_column:year'
        ])

        check_productions_match(productions['Column'], [
            'string_column:league', 'string_column:playoffs',
            'string_column:open_cup', 'string_column:year',
            'string_column:division', 'string_column:avg_attendance',
            'string_column:regular_season', 'date_column:year',
            'number_column:avg_attendance', 'number_column:open_cup',
            'number_column:regular_season', 'number_column:division',
            'number_column:year'
        ])

        # Strings come from the question - any span in the question that shows up as a cell in the
        # table is a valid string production.
        check_productions_match(productions['List[str]'], [
            'string:quarterfinals', 'string:did_not_qualify',
            'string:a_league', 'string:usl_first_division',
            'string:usl_a_league', 'string:1', 'string:2', 'string:2005',
            'string:2001',
            '[<List[Row],StringColumn:List[str]>, List[Row], StringColumn]'
        ])
 def test_get_nonterminal_productions(self):
     productions = self.language.get_nonterminal_productions()
     assert set(productions.keys()) == {
         "QuaRelType",
         "@start@",
         "World",
         "Direction",
         "<QuaRelType,QuaRelType:QuaRelType>",
         "int",
         "<QuaRelType,QuaRelType,QuaRelType:int>",
         "<Direction,World:QuaRelType>",
     }
     check_productions_match(
         productions["QuaRelType"],
         [
             "[<QuaRelType,QuaRelType:QuaRelType>, QuaRelType, QuaRelType]",
             "[<Direction,World:QuaRelType>, Direction, World]",
         ],
     )
     check_productions_match(productions["@start@"], ["int"])
     check_productions_match(productions["World"], ["world1", "world2"])
     check_productions_match(productions["Direction"],
                             ["higher", "lower", "high", "low"])
     check_productions_match(
         productions["<QuaRelType,QuaRelType:QuaRelType>"], ["and"])
     check_productions_match(
         productions["int"],
         [
             "[<QuaRelType,QuaRelType,QuaRelType:int>, QuaRelType, QuaRelType, QuaRelType]"
         ],
     )
     check_productions_match(
         productions["<QuaRelType,QuaRelType,QuaRelType:int>"], ["infer"])
     check_productions_match(
         productions["<Direction,World:QuaRelType>"],
         [
             "friction",
             "speed",
             "distance",
             "heat",
             "smoothness",
             "acceleration",
             "amountSweat",
             "apparentSize",
             "breakability",
             "brightness",
             "exerciseIntensity",
             "flexibility",
             "gravity",
             "loudness",
             "mass",
             "strength",
             "thickness",
             "time",
             "weight",
         ],
     )
Ejemplo n.º 3
0
 def test_get_nonterminal_productions(self):
     productions = self.language.get_nonterminal_productions()
     assert set(productions.keys()) == {
         'QuaRelType', '@start@', 'World', 'Direction',
         '<QuaRelType,QuaRelType:QuaRelType>', 'int',
         '<QuaRelType,QuaRelType,QuaRelType:int>',
         '<Direction,World:QuaRelType>'
     }
     check_productions_match(productions['QuaRelType'], [
         '[<QuaRelType,QuaRelType:QuaRelType>, QuaRelType, QuaRelType]',
         '[<Direction,World:QuaRelType>, Direction, World]'
     ])
     check_productions_match(productions['@start@'], ['int'])
     check_productions_match(productions['World'], ['world1', 'world2'])
     check_productions_match(productions['Direction'],
                             ['higher', 'lower', 'high', 'low'])
     check_productions_match(
         productions['<QuaRelType,QuaRelType:QuaRelType>'], ['and'])
     check_productions_match(productions['int'], [
         '[<QuaRelType,QuaRelType,QuaRelType:int>, QuaRelType, QuaRelType, QuaRelType]'
     ])
     check_productions_match(
         productions['<QuaRelType,QuaRelType,QuaRelType:int>'], ['infer'])
     check_productions_match(productions['<Direction,World:QuaRelType>'], [
         "friction", "speed", "distance", "heat", "smoothness",
         "acceleration", "amountSweat", "apparentSize", "breakability",
         "brightness", "exerciseIntensity", "flexibility", "gravity",
         "loudness", "mass", "strength", "thickness", "time", "weight"
     ])
    def test_get_nonterminal_productions_all_column_types(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.
        productions = self.language.get_nonterminal_productions()
        assert set(productions.keys()) == {
            "@start@",
            "<List[Row],StringColumn:List[str]>",
            "<List[Row],DateColumn:Date>",
            "<List[Row],NumberColumn,Number:List[Row]>",
            "<List[Row],ComparableColumn:List[Row]>",
            "<List[Row],Column:List[Row]>",
            "<List[Row],List[Row],NumberColumn:Number>",
            "<List[Row],StringColumn,List[str]:List[Row]>",
            "<Number,Number,Number:Date>",
            "<List[Row],DateColumn,Date:List[Row]>",
            "<List[Row],NumberColumn:Number>",
            "<List[Row]:List[Row]>",
            "<List[Row],StringColumn:List[str]>",
            "<List[Row]:Number>",
            "List[str]",
            "List[Row]",
            "Date",
            "Number",
            "StringColumn",
            "NumberColumn",
            "ComparableColumn",
            "Column",
            "DateColumn",
            "List[str]",
        }

        check_productions_match(productions["@start@"], ["Date", "Number", "List[str]"])

        check_productions_match(
            productions["<List[Row],StringColumn:List[str]>"], ["select_string", "mode_string"]
        )

        check_productions_match(
            productions["<List[Row],DateColumn:Date>"],
            ["select_date", "max_date", "min_date", "mode_date"],
        )

        check_productions_match(
            productions["<List[Row],NumberColumn,Number:List[Row]>"],
            [
                "filter_number_equals",
                "filter_number_greater",
                "filter_number_greater_equals",
                "filter_number_lesser",
                "filter_number_lesser_equals",
                "filter_number_not_equals",
            ],
        )

        check_productions_match(
            productions["<List[Row],ComparableColumn:List[Row]>"], ["argmax", "argmin"]
        )

        check_productions_match(productions["<List[Row],Column:List[Row]>"], ["same_as"])

        check_productions_match(productions["<List[Row],List[Row],NumberColumn:Number>"], ["diff"])

        check_productions_match(
            productions["<List[Row],StringColumn,List[str]:List[Row]>"],
            ["filter_in", "filter_not_in"],
        )

        check_productions_match(productions["<Number,Number,Number:Date>"], ["date"])

        check_productions_match(
            productions["<List[Row],DateColumn,Date:List[Row]>"],
            [
                "filter_date_equals",
                "filter_date_greater",
                "filter_date_greater_equals",
                "filter_date_lesser",
                "filter_date_lesser_equals",
                "filter_date_not_equals",
            ],
        )

        check_productions_match(
            productions["<List[Row],NumberColumn:Number>"],
            ["average", "max_number", "min_number", "sum", "select_number", "mode_number"],
        )

        check_productions_match(
            productions["<List[Row]:List[Row]>"], ["first", "last", "next", "previous"]
        )

        check_productions_match(productions["<List[Row]:Number>"], ["count"])

        check_productions_match(
            productions["List[Row]"],
            [
                "all_rows",
                "[<List[Row],Column:List[Row]>, List[Row], Column]",
                "[<List[Row],DateColumn,Date:List[Row]>, List[Row], DateColumn, Date]",
                "[<List[Row],ComparableColumn:List[Row]>, List[Row], ComparableColumn]",
                "[<List[Row],NumberColumn,Number:List[Row]>, List[Row], NumberColumn, Number]",
                "[<List[Row],StringColumn,List[str]:List[Row]>, List[Row], StringColumn, List[str]]",
                "[<List[Row]:List[Row]>, List[Row]]",
            ],
        )

        check_productions_match(
            productions["Date"],
            [
                "[<Number,Number,Number:Date>, Number, Number, Number]",
                "[<List[Row],DateColumn:Date>, List[Row], DateColumn]",
            ],
        )

        # Some of the number productions are instance-specific, and some of them are from the
        # grammar.
        check_productions_match(
            productions["Number"],
            [
                "2001",
                "2002",
                "2005",
                "2010",
                "2013",
                "-1",
                "1",
                "2",
                "23",
                "8000",
                "[<List[Row],NumberColumn:Number>, List[Row], NumberColumn]",
                "[<List[Row],List[Row],NumberColumn:Number>, List[Row], List[Row], NumberColumn]",
                "[<List[Row]:Number>, List[Row]]",
            ],
        )

        # These are the columns in table, and are instance specific.
        check_productions_match(
            productions["StringColumn"],
            [
                "string_column:league",
                "string_column:playoffs",
                "string_column:open_cup",
                "string_column:year",
                "string_column:division",
                "string_column:avg_attendance",
                "string_column:regular_season",
            ],
        )

        check_productions_match(productions["DateColumn"], ["date_column:year"])

        check_productions_match(
            productions["NumberColumn"],
            [
                "number_column:avg_attendance",
                "number_column:open_cup",
                "number_column:regular_season",
                "number_column:division",
                "number_column:year",
            ],
        )

        check_productions_match(
            productions["ComparableColumn"],
            [
                "date_column:year",
                "number_column:avg_attendance",
                "number_column:open_cup",
                "number_column:regular_season",
                "number_column:division",
                "number_column:year",
            ],
        )

        check_productions_match(
            productions["Column"],
            [
                "string_column:league",
                "string_column:playoffs",
                "string_column:open_cup",
                "string_column:year",
                "string_column:division",
                "string_column:avg_attendance",
                "string_column:regular_season",
                "date_column:year",
                "number_column:avg_attendance",
                "number_column:open_cup",
                "number_column:regular_season",
                "number_column:division",
                "number_column:year",
            ],
        )

        # Strings come from the question - any span in the question that shows up as a cell in the
        # table is a valid string production.
        check_productions_match(
            productions["List[str]"],
            [
                "string:quarterfinals",
                "string:did_not_qualify",
                "string:a_league",
                "string:usl_first_division",
                "string:usl_a_league",
                "string:1",
                "string:2",
                "string:2005",
                "string:2001",
                "[<List[Row],StringColumn:List[str]>, List[Row], StringColumn]",
            ],
        )