Exemple #1
0
def test_grammar(service_name):
    print('Testing grammar for service \'{0}\'...'.format(service_name))
    try:
        grammar = get_grammar_for_service(service_name)
    except ValueError as e:
        print 'Error: {}'.format(e.args[0])
        return
    all_examples = parse_examples()
    ex_total = 0
    counter_ex_total = 0
    hits = 0
    misses = 0
    for key, examples in all_examples.iteritems():
        if key == service_name:
            ex_total += len(examples)
            for example in examples:
                parse_tree = parse(example, grammar)
                if parse_tree:
                    # pprint(parse_tree)
                    # print example
                    hits += 1
                else:
                    print '>', example
        else:
            counter_ex_total += len(examples)
            for counterexample in examples:
                if parse(counterexample, grammar):
                    misses += 1
                    print 'X', counterexample
    print('Success:\t\t{0}/{1}'.format(hits, ex_total))
    print('False Positives:\t{0}/{1}'.format(misses, counter_ex_total))
Exemple #2
0
def main():
    examples = parse_examples()
    services = {s: Heuristic(s) for s in get_all_service_names()}

    step_size = float(FIRST_STEP_SIZE)
    services_to_step = climbing(examples, services, int(step_size))

    counter = 0
    while len(services_to_step):
        if step_size != 1.0:
            step_size -= 0.5

        counter += 1
        sys.stdout.flush()
        services_to_step = climbing(examples, services, int(step_size))

        # Write to file after so many steps, that way we don't lose
        # progress if we end early.
        if counter == STEPS_BETWEEN_WRITES or not len(services_to_step):
            counter = 0
            for name, heuristic in services.iteritems():
                fname = path.realpath(
                    path.join(
                        path.dirname(__file__),
                        'climbed_values',
                        name + '_climbed_values.txt'))
                heuristic.write_to_file(fname)

    print "Success! You did it! Hills have been climbed!"
Exemple #3
0
    def generate_summary(self, intent, object_, result):
        data = {
            'name': object_['name'].title(),
            'title': object_['title'].title(),
            'verb_phrase': verb_phrase_from_role(object_['role']),
            'result': result
        }
        SUMMARY_TEMPLATES = {
            ('CREDITS', 'BOOLEAN_OF'): '{result}.',
            ('CREDITS', 'COUNT_OF'): '{name} {verb_phrase} {result} movies.',
            ('CREDITS', 'MOVIES_OF'): '{result}.',
            ('CREDITS', 'PEOPLE_OF'): '{result}.',
            ('MOVIES', 'YEAR_OF'): '{title} was in the year {result}.'
        }
        if intent in SUMMARY_TEMPLATES:
            return SUMMARY_TEMPLATES[intent].format(**data)


if __name__ == "__main__":
    from pal.test import parse_examples
    examples = parse_examples()
    i = 0
    for example in examples['movie']:
        if i > 10:
            pass
        i += 1
        print example
        print MovieService().go({'query': example})['summary']
        print
Exemple #4
0
 def __init__(self):
     self.examples = parse_examples()
     super(HeuristicTestCase, self).__init__()
Exemple #5
0
 def __init__(self):
     self.examples = parse_examples()
     super(HeuristicTestCase, self).__init__()
Exemple #6
0
        data = {
            'name': object_['name'].title(),
            'title': object_['title'].title(),
            'verb_phrase': verb_phrase_from_role(object_['role']),
            'result': result
        }
        SUMMARY_TEMPLATES = {
            ('CREDITS', 'BOOLEAN_OF'): '{result}.',
            ('CREDITS', 'COUNT_OF'): '{name} {verb_phrase} {result} movies.',
            ('CREDITS', 'MOVIES_OF'): '{result}.',
            ('CREDITS', 'PEOPLE_OF'): '{result}.',
            ('MOVIES', 'YEAR_OF'): '{title} was in the year {result}.'
        }
        if intent in SUMMARY_TEMPLATES:
            return SUMMARY_TEMPLATES[intent].format(**data)


if __name__ == "__main__":
    from pal.test import parse_examples
    examples = parse_examples()
    i = 0
    for example in examples['movie']:
        if i > 10:
            pass
        i += 1
        print example
        print MovieService().go({
            'query': example
        })['summary']
        print