Exemplo n.º 1
0
    def test_simple_grammar(self):
        rules = self.rules_optionals + self.rules_collection_entity
        grammar = Unit2Grammar(rules=rules, annotators=self.annotators)

        parses = grammar.parse('what is utah')
        self.assertEqual('/state/utah', parses[0].semantics)
        self.assertEqual(('/state/utah', ),
                         self.geobase.executor().execute(parses[0].semantics))
Exemplo n.º 2
0
    def test_grammar_with_relations(self):
        rules = (self.rules_optionals + self.rules_collection_entity +
                 self.rules_types + self.rules_relations)
        grammar = Unit2Grammar(rules=rules, annotators=self.annotators)

        parses = grammar.parse('what is the capital of vermont ?')
        self.assertEqual(('/state/vermont', 'capital'), parses[0].semantics)
        self.assertEqual(('/city/montpelier_vt', ),
                         self.geobase.executor().execute(parses[0].semantics))
Exemplo n.º 3
0
    def test_grammar_with_superlatives(self):
        rules = (self.rules_optionals + self.rules_collection_entity +
                 self.rules_types + self.rules_relations +
                 self.rules_intersection + self.rules_superlatives)
        grammar = Unit2Grammar(rules=rules, annotators=self.annotators)

        parses = grammar.parse('tallest mountain')
        self.assertEqual(('.argmax', 'height', 'mountain'),
                         parses[0].semantics)
        self.assertEqual(('/mountain/mckinley', ),
                         self.geobase.executor().execute(parses[0].semantics))
Exemplo n.º 4
0
    def test_grammar_with_intersections(self):
        rules = (self.rules_optionals + self.rules_collection_entity +
                 self.rules_types + self.rules_relations +
                 self.rules_intersection)
        grammar = Unit2Grammar(rules=rules, annotators=self.annotators)

        parses = grammar.parse('states bordering california')
        self.assertEqual(('.and', 'state', ('borders', '/state/california')),
                         parses[0].semantics)
        self.assertEqual(('/state/arizona', '/state/nevada', '/state/oregon'),
                         self.geobase.executor().execute(parses[0].semantics))
Exemplo n.º 5
0
    def test_grammar_with_types(self):
        rules = self.rules_optionals + self.rules_collection_entity + self.rules_types
        grammar = Unit2Grammar(rules=rules, annotators=self.annotators)

        parses = grammar.parse('name the lakes')
        self.assertEqual(
            ('/lake/becharof', '/lake/champlain', '/lake/erie',
             '/lake/flathead', '/lake/great_salt_lake', '/lake/huron',
             '/lake/iliamna', '/lake/lake_of_the_woods', '/lake/michigan',
             '/lake/mille_lacs', '/lake/naknek', '/lake/okeechobee',
             '/lake/ontario', '/lake/pontchartrain', '/lake/rainy',
             '/lake/red', '/lake/salton_sea', '/lake/st._clair',
             '/lake/superior', '/lake/tahoe', '/lake/teshekpuk',
             '/lake/winnebago'),
            self.geobase.executor().execute(parses[0].semantics))
Exemplo n.º 6
0
    def test_evaluate_simple_grammar(self):
        from experiment import sample_wins_and_losses
        from metrics import DenotationOracleAccuracyMetric
        from scoring import Model

        rules = self.rules_optionals + self.rules_collection_entity
        grammar = Unit2Grammar(rules=rules, annotators=self.annotators)
        model = Model(grammar=grammar,
                      executor=self.geobase.executor().execute)
        metric = DenotationOracleAccuracyMetric()

        # If printing=True, prints a sampling of wins (correct semantics in
        # first parse) and losses on the dataset.
        metric_values = sample_wins_and_losses(domain=self.domain,
                                               model=model,
                                               metric=metric,
                                               seed=1,
                                               printing=False)
        self.assertEqual(17, metric_values['number of parses'])