示例#1
0
文件: util.py 项目: schlevik/sam
def showcase_all(out_file, given_bundle: Bundle = None, do_x_repetitions=12):
    test_bundle = given_bundle or bundle
    lines = []
    for i in range(len(test_bundle.templates_modifier['sentences']['goal'])):
        lines.append(click.style(f"goal[{i}]", fg='blue', bold=True))
        for j in range(do_x_repetitions // 6):
            stories = showcase(test_bundle, i, False)
            lines.extend(highlight(text=s, colors=colors) for s in stories)
    for i in range(len(test_bundle.templates_modifier['sentences']['foul'])):
        generator, cfg, events, realizer, story, all_questions, visits = interactive_env_football_modifier(
            test_bundle,
            cfg={"world.num_sentences": 3},
            do_print=False,
            do_realise=False,
            first_modification=1)
        lines.append(click.style(f"foul[{i}]", fg='blue', bold=True))
        for j in range(do_x_repetitions):
            templates = only(test_bundle.templates_modifier,
                             n=i,
                             action='foul')
            realizer = Realizer(**templates, unique_sentences=False)
            story, visits = realizer.realise_story(events, generator.world)
            lines.append(story[0])
    print("\n".join(lines))
    with open(out_file, "w+") as f:
        f.write('\n'.join(lines))
def test_pessimistic_condition():
    only_templates = only(templates, 0)
    a = Accessor(context=Context(), **only_templates)
    r = SizeEstimator(Processor(a, RandomChooser()))
    assert r.estimate_size(a.sentences['test']) == 20

    a = Accessor(context=Context(), **only_templates)
    r = SizeEstimator(Processor(a, RandomChooser()))
    assert r.estimate_size(a.sentences['test'], pessimistic=True) == 4
示例#3
0
def test_different_dollar_templates_nested():
    only_templates = only(templates, 1)
    r = Realizer(**only_templates, unique_sentences=False)
    logic_sents = [Event(0)]
    logic_sents[0].event_type = 'test'
    world = {}
    realised_sents, visits = r.realise_story(logic_sents, world)
    assert '1' in realised_sents[0]
    assert '2' in realised_sents[0]
    assert '3' in realised_sents[0]
示例#4
0
def test_different_dollar_templates_flat_with_multiple_sentences_when_not_leaf():
    only_templates = only(templates, 2)
    r = Realizer(**only_templates, unique_sentences=False)
    logic_sents = [Event(0), Event(1)]
    logic_sents[0].event_type = 'test'
    logic_sents[1].event_type = 'test'
    world = {}
    realised_sents, visits = r.realise_story(logic_sents, world)
    assert '1' in realised_sents[0]
    assert '2' in realised_sents[0]
    assert 'b' in realised_sents[0]
示例#5
0
def test_different_dollar_templates_flat():
    # sents = only(sentences, 0)  # flat
    only_templates = only(templates, 0)
    r = Realizer(**only_templates)
    # r = TestRealizer(sentences=sents)
    logic_sents = [Event(0)]
    logic_sents[0].event_type = 'test'
    world = {}
    realised_sents, visits = r.realise_story(logic_sents, world)
    assert '1' in realised_sents[0]
    assert '2' in realised_sents[0]
    assert '3' in realised_sents[0]
示例#6
0
文件: util.py 项目: schlevik/sam
def showcase(given_bundle=None, n=0, do_print=True):
    test_bundle = only(given_bundle, n, 'goal') if given_bundle else only(
        bundle, n, 'goal')
    templates = test_bundle.templates_modifier
    generator, cfg, events, realizer, story, all_questions, visits = interactive_env_football_modifier(
        test_bundle,
        cfg={"world.num_sentences": 2},
        do_print=False,
        do_realise=False)
    sentences = []
    for f in MODIFIER_TYPES:
        events[0].features = [f]
        generator.modifier_type = f
        realizer = Realizer(**templates, unique_sentences=False)
        story, visits = realizer.realise_story(events, generator.world)
        # ssq, maq, uaq, abq = get_questions(generator, realizer, events, visits, story)
        if do_print:
            print(f"==== {f} ====")
            print(story[0])
            print(story[1])
        # print_out(story, [])
        sentences.append(story[0])
    return sentences
示例#7
0
文件: debug.py 项目: schlevik/sam
def test_modifier(sent_nr, action, n, domain, config, first_modification,
                  fill_with_modification, modify_event_types, modifier_type,
                  modification_distance, total_modifiable_actions):
    if modify_event_types:
        modify_event_types = [modify_event_types]
    if sent_nr is not None and action is not None:
        domain = only(domain, sent_nr, action)
    for i in range(n):
        _ = interactive_env_football_modifier(
            changed_bundle=domain,
            cfg=config,
            do_print=True,
            do_realise=True,
            first_modification=first_modification,
            fill_with_modification=fill_with_modification,
            modify_event_types=modify_event_types,
            modification_distance=modification_distance,
            total_modifiable_actions=total_modifiable_actions,
            modifier_type=modifier_type)
示例#8
0
def test_bang_works_with_number_when_implicitly_defined_with_args():
    only_templates = only(templates, 6)
    a = Accessor(context=Context(), **only_templates)
    r = SizeEstimator(Processor(a, RandomChooser()))
    assert r.estimate_size(a.sentences['test']) == 18
示例#9
0
def test_bang_works_with_options_when_explicitly_defined():
    only_templates = only(templates, 4)
    a = Accessor(context=Context(), **only_templates)
    r = SizeEstimator(Processor(a, RandomChooser()))
    assert r.estimate_size(a.sentences['test']) == 9
示例#10
0
def test_estimate_size_works_per_sentence():
    only_templates = only(templates, 0)
    a = Accessor(context=Context(), **only_templates)
    r = SizeEstimator(Processor(a, RandomChooser()))
    assert r.estimate_size(a.sentences['test']) == 12
示例#11
0
def test_estimate_size_works_with_option():
    only_templates = only(templates, 5)
    a = Accessor(context=Context(), **only_templates)
    r = SizeEstimator(Processor(a, RandomChooser()))
    assert r.estimate_size(a.sentences['test']) == 9
    assert r._estimate_words(a.sentences['test'][0]) == 9