def test_world_parses_logical_forms_with_decimals(self): question_tokens = [Token(x) for x in ['0.2']] table_kg = TableQuestionKnowledgeGraph.read_from_file( self.FIXTURES_ROOT / "data" / "wikitables" / "sample_table.tsv", question_tokens) world = WikiTablesWorld(table_kg) sempre_form = "(fb:cell.cell.number (number 0.200))" expression = world.parse_logical_form(sempre_form) assert str(expression) == "I1(I(num:0_200))"
def test_with_deeply_nested_logical_form(self): question_tokens = [Token(x) for x in ['what', 'was', 'the', 'district', '?']] table_filename = self.FIXTURES_ROOT / 'data' / 'wikitables' / 'table' / '109.tsv' table_kg = TableQuestionKnowledgeGraph.read_from_file(table_filename, question_tokens) world = WikiTablesWorld(table_kg) logical_form = ("(count ((reverse fb:cell.cell.number) (or (or (or (or (or (or (or (or " "(or (or (or (or (or (or (or (or (or (or (or (or (or fb:cell.virginia_1 " "fb:cell.virginia_10) fb:cell.virginia_11) fb:cell.virginia_12) " "fb:cell.virginia_13) fb:cell.virginia_14) fb:cell.virginia_15) " "fb:cell.virginia_16) fb:cell.virginia_17) fb:cell.virginia_18) " "fb:cell.virginia_19) fb:cell.virginia_2) fb:cell.virginia_20) " "fb:cell.virginia_21) fb:cell.virginia_22) fb:cell.virginia_3) " "fb:cell.virginia_4) fb:cell.virginia_5) fb:cell.virginia_6) " "fb:cell.virginia_7) fb:cell.virginia_8) fb:cell.virginia_9)))") print("Parsing...") world.parse_logical_form(logical_form)
def test_world_adds_numbers_from_question(self): question_tokens = [Token(x) for x in ['what', '2007', '2,107', '0.2', '1800s', '1950s', '?']] table_kg = TableQuestionKnowledgeGraph.read_from_file( self.FIXTURES_ROOT / "data" / "wikitables" / "sample_table.tsv", question_tokens) world = WikiTablesWorld(table_kg) valid_actions = world.get_valid_actions() assert 'n -> 2007' in valid_actions['n'] assert 'n -> 2107' in valid_actions['n'] # It appears that sempre normalizes floating point numbers. assert 'n -> 0.200' in valid_actions['n'] # We want to add the end-points to things like "1800s": 1800 and 1900. assert 'n -> 1800' in valid_actions['n'] assert 'n -> 1900' in valid_actions['n'] assert 'n -> 1950' in valid_actions['n'] assert 'n -> 1960' in valid_actions['n']
def setUp(self): super().setUp() self.world_without_recursion = FakeWorldWithoutRecursion() self.world_with_recursion = FakeWorldWithRecursion() test_filename = self.FIXTURES_ROOT / "data" / "nlvr" / "sample_ungrouped_data.jsonl" data = [ json.loads(line)["structured_rep"] for line in open(test_filename).readlines() ] self.nlvr_world = NlvrWorld(data[0]) question_tokens = [ Token(x) for x in ['what', 'was', 'the', 'last', 'year', '2004', '?'] ] table_file = self.FIXTURES_ROOT / 'data' / 'wikitables' / 'sample_table.tsv' table_kg = TableQuestionKnowledgeGraph.read_from_file( table_file, question_tokens) self.wikitables_world = WikiTablesWorld(table_kg)
def _get_world_with_question_tokens(self, tokens: List[Token]) -> WikiTablesWorld: table_kg = TableQuestionKnowledgeGraph.read_from_file(self.table_file, tokens) world = WikiTablesWorld(table_kg) return world
def setUp(self): super().setUp() question_tokens = [Token(x) for x in ['what', 'was', 'the', 'last', 'year', '2000', '?']] self.table_file = self.FIXTURES_ROOT / 'data' / 'wikitables' / 'sample_table.tsv' self.table_kg = TableQuestionKnowledgeGraph.read_from_file(self.table_file, question_tokens) self.world = WikiTablesWorld(self.table_kg)