Exemple #1
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]
Exemple #2
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]
Exemple #3
0
def test_different_sentences():
    sents = sentences  # nested
    r = Realizer(**templates)
    ii = [0, 1, 2, 3]
    logic_sents = [Event(i) for i in ii]
    for i in ii:
        logic_sents[i].event_type = "unique_sentence_test"
    world = {}
    realised_sents, visits = r.realise_story(logic_sents, world)
    for i in ii:
        assert any([str(i) in sent for sent in realised_sents]), f"{i} not in story!"
Exemple #4
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]
Exemple #5
0
def test_generate_one_possible_template_choice_works_for_football_bundle():
    must_haves = [
        random.choice(['coactor', 'time', 'distance', None]) for _ in range(5)
    ]
    # events = (('modified', 'goal'), ('modified', 'goal'), ('just', 'goal'), ('any', '_'), ('any', '_'))
    events = [
        Event(i, et)
        for i, et in enumerate(['goal', 'goal', 'goal', 'goal', 'goal'])
    ]
    templates = bundle.templates_modifier['sentences']
    one_possible_template_choice = \
        generate_one_possible_template_choice(events, templates, must_haves, bundle.has_template_attribute)
    for mh, (et, tc) in zip(must_haves, one_possible_template_choice):
        if mh:
            template = templates[et][tc]
            assert bundle.has_template_attribute(template, mh)
Exemple #6
0
 def generate_sentence(self, sentence_nr):
     logger.debug(f"Generating Sentence #{sentence_nr}")
     self.current_event = Event(sentence_nr)
     logger.debug("Setting Action...")
     self.set_action()
     logger.debug(f"Action: {self.current_event.event_type}")
     logger.debug("Setting Actor...")
     self.set_actor()
     logger.debug(f"Actor: {self.current_event.actor}")
     logger.debug("Setting Attributes...")
     self.set_attributes()
     logger.debug(f"Attributes: {self.current_event.attributes}")
     logger.debug("Setting Anything Else...")
     self.set_everything_else()
     logger.debug(f"Event so far: {self.current_event}")
     logger.debug("Done!")
     self.sentences.append(self.current_event)
        "1",
        "2",
        "3",
    ]
}

dollar = {
    "a": "a1 a2 a3".split(),  # flat
    'b': {  # nested
        "c": "bc1 bc2 bc3".split()
    },
    'c': ['$d cb $d'],
    'd': ['d1', 'd2']
}

test_events = [Event(event_type='t2') for _ in range(3)] + [Event(event_type='t1')] * 2


def test_num_permutations_works():
    num_permutations = calculate_num_of_permutations(test_events, sentences, ['t1'])
    assert num_permutations == 6
    num_permutations = calculate_num_of_permutations(test_events, sentences, ['t2'])
    assert num_permutations == 24
    num_permutations = calculate_num_of_permutations(test_events, sentences, ['t1', 't2'])
    assert num_permutations == 144


def test_generate_choices_works():
    for to_permute in (['t1'], ['t2'], ['t1', 't2']):
        choices = generate_all_possible_template_choices(test_events, sentences, to_permute)
        num_permutations = calculate_num_of_permutations(test_events, sentences, to_permute)