Пример #1
0
def was_there_source_two_or(dataset, narrative, _):
    questions = [
        'Did you [hear,listen to] [a,an] <S1> or [a,an] <S2>?',
        'Have you [heard,listened to] [a,an] <S1> or [a,an] <S2>?'
        'Did you [hear,listen to] any <S1> or any <S2>?',
        'Have you [heard,listened to] any <S1> or any <S2>?',
        'Was there a sound [produced,made] by [a,an] <S1> or a sound [produced,made] by [a,an] <S2>?',  # noqa: E501
        'Were there any sounds [produced,made] by [a,an] <S1> or any sounds [produced,made] by [a,an] <S2>?',  # noqa: E501
    ]

    question = str(np.random.choice(questions))  # sample question
    event_1 = str(np.random.choice(dataset['events']))  # sample event
    source_1 = str(np.random.choice(
        dataset['sources'][event_1]))  # sample source
    lst_events = [e for e in dataset['events'] if e != event_1]
    event_2 = str(np.random.choice(lst_events))  # sample event
    source_2 = str(np.random.choice(
        dataset['sources'][event_2]))  # sample source

    question = question.replace('<S1>', source_1)  # insert source
    question = question.replace('<S2>', source_2)  # insert source
    question = sanitize_question(question)  # correct grammar

    lst_sources = get_lst_all_sources(dataset, narrative)
    answer = 'yes' if (source_1 in lst_sources
                       or source_2 in lst_sources) else 'no'

    return question, answer
Пример #2
0
def more_than(dataset, narrative, _):
    questions = [
        'Were there more <S1>s <A1> than <S2>s <A2>?',
        'Was the number of [times,instances,occurrences] [a,an] <S1> <A1> more than the number of [times,instances,occurrences] [a,an] <S2> <A2>?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the sounds of [a,an] <S1> <A1> and [a,an] <S2> <A2>, were there more [times,instances,occurrences] of the former?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the sounds of [a,an] <S2> <A2> and [a,an] <S1> <A1>, were there more [times,instances,occurrences] of the latter?',  # noqa: E501
    ]

    question = str(np.random.choice(questions))  # sample question
    lst_events = get_lst_events(narrative)
    event_1 = str(np.random.choice(lst_events))  # sample event
    source_1 = str(np.random.choice(dataset['sources'][event_1]))
    action_1 = str(np.random.choice(dataset['actions'][event_1]))
    x_lst_events = [e for e in lst_events if e != event_1]
    assert len(x_lst_events) > 0, 'Question (more_than) illposed.'
    event_2 = str(np.random.choice(x_lst_events))  # sample event
    source_2 = str(np.random.choice(dataset['sources'][event_2]))
    action_2 = str(np.random.choice(dataset['actions'][event_2]))

    assert event_1 != event_2, 'Question (more_than) illposed.'

    question = question.replace('<S1>', source_1)  # insert source
    question = question.replace('<A1>', action_1)  # insert action
    question = question.replace('<S2>', source_2)  # insert source
    question = question.replace('<A2>', action_2)  # insert action
    question = sanitize_question(question)

    answer = 'yes' \
        if lst_events.count(event_1) > lst_events.count(event_2) \
        else 'no'

    return question, answer
Пример #3
0
def equal_to(dataset, narrative, _):
    questions = [
        'Was the number of times [a,an] <S1> <A1> equal to the number of times [a,an] <S2> <A2>?',  # noqa: E501
        'Was the number of times [a,an] <S1> <A1> the same as the number of times [a,an] <S2> <A2>?',  # noqa: E501
        'Was there an equal number of times [a,an] <S1> <A1> and [a,an] <S2> <A2>?',  # noqa: E501
        'Was there the same number of <S1> <A1> and <S2> <A2>?',
    ]

    question = str(np.random.choice(questions))  # sample question
    lst_events = get_lst_events(narrative)
    event_1 = str(np.random.choice(lst_events))  # sample event
    source_1 = str(np.random.choice(dataset['sources'][event_1]))
    action_1 = str(np.random.choice(dataset['actions'][event_1]))
    x_lst_events = [e for e in lst_events if e != event_1]
    assert len(x_lst_events) > 0, 'Question (equal_to) illposed.'
    event_2 = str(np.random.choice(x_lst_events))  # sample event
    source_2 = str(np.random.choice(dataset['sources'][event_2]))
    action_2 = str(np.random.choice(dataset['actions'][event_2]))

    assert event_1 != event_2, 'Question (equal_to) illposed.'

    question = question.replace('<S1>', source_1)  # insert source
    question = question.replace('<A1>', action_1)  # insert action
    question = question.replace('<S2>', source_2)  # insert source
    question = question.replace('<A2>', action_2)  # insert action
    question = sanitize_question(question)

    answer = 'yes' \
        if lst_events.count(event_1) == lst_events.count(event_2) \
        else 'no'

    return question, answer
Пример #4
0
def compare_same_duration_ordinal(dataset, narrative, rel_diff=0.1):
    questions = [
        'Was the <O1> [sound event,sound] [roughly,approximately] as <D> as the <O2> [sound event,sound]?',  # noqa: E501
        'Was the <O1> and <O2> [sound events,sounds] [roughly,approximately] as <D>?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the <O1> [sound event,sound] and the <O2> [sound event,sound], were they [roughly,approximately] as <D>?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the <O1> [sound event,sound] and the <O2> [sound event,sound], did they [roughly,approximately] have the same duration?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the <O1> and <O2> [sound events,sounds], were they [roughly,approximately] as <D>?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the <O1> and <O2> [sound events,sounds], did they [roughly,approximately] have the same duration?',  # noqa: E501
    ]

    question = str(np.random.choice(questions))  # sample question
    lst_events = get_lst_events(narrative)
    number_1, ordinal_1 = sample_number(len(lst_events))
    duration = sample_duration()
    number_2, ordinal_2 = sample_second_number(len(lst_events), number_1)

    assert number_1 != number_2, 'Question (compare_same_duration_ordinal) illposed.'

    question = question.replace('<O1>', ordinal_1)  # insert ordinal
    question = question.replace('<D>', duration)  # insert duration
    question = question.replace('<O2>', ordinal_2)  # insert ordinal
    question = sanitize_question(question)  # correct grammar

    lst_duration = get_lst_durations(narrative)
    e_1_duration = lst_duration[number_1 - 1]
    e_2_duration = lst_duration[number_2 - 1]
    rel_duration_diff = compute_rel_diff(np.array(e_1_duration),
                                         np.array(e_2_duration))
    # Assert a good margin in relative duration
    assert np.sum(np.logical_and(rel_duration_diff > rel_diff,
                                 rel_duration_diff < (2 * rel_diff))) <= 0, \
        'Question (compare_same_duration_ordinal) illposed.'
    answer = 'yes' if rel_duration_diff <= rel_diff else 'no'

    return question, answer
Пример #5
0
def what_was_loudness(dataset, narrative, rel_diff=0.1):
    questions = [
        'What was the <AL> sound?',
        'What was the <AL> sound you [heard,listened to]?',
        'What was the <AL> sound that you [heard,listened to]?',
        'What was the <AL> sound that was heard?',
    ]

    question = str(np.random.choice(questions))  # sample question
    loudness = sample_absolute_loudness()

    question = question.replace('<AL>', loudness)  # insert loudness
    question = sanitize_question(question)  # correct grammar

    lst_events = get_lst_events(narrative)
    lst_loudness = get_lst_loudness(narrative)
    if 'loud' in question:
        est = np.argmax(lst_loudness)
    elif 'quiet' in question:
        est = np.argmin(lst_loudness)
    else:
        assert False, \
            'Loudness illdefined in Question (what_was_loudness).'
    # Assert a good margin in relative loudness
    evt_loudness = lst_loudness[est]
    x_loudness = [j for i, j in enumerate(lst_loudness) if i != est]
    rel_loudness_diff = compute_rel_diff(np.array(x_loudness),
                                         np.array(evt_loudness))
    assert np.sum(rel_loudness_diff < rel_diff) <= 0, \
        'Question (what_was_loudness) illposed.'
    e = lst_events[est]
    answer = (str(np.random.choice(dataset['sources'][e])) + ' ' +
              str(np.random.choice(dataset['actions'][e])))

    return question, answer
Пример #6
0
def how_many_event_two(dataset, narrative, _):
    questions = ['How many times was [a,an] <S1> <A1> [or,and] [a,an] <S2> <A2>?',
                 'How many times did you [hear,listen to] [a,an] <S1> <A1> [or,and] [a,an] <S2> <A2>?',  # noqa: E501
                 'How many times have you [heard,listened to] [a,an] <S1> <A1> [or,and] [a,an] <S2> <A2>?',  # noqa: E501
                 'What is the number of times [a,an] <S1> <A1> [or,and] [a,an] <S2> <A2>?',  # noqa: E501
                 'What is the number of times did you [hear,listen to] [a,an] <S1> <A1> [or,and] [a,an] <S2> <A2>?',  # noqa: E501
                 'What is the number of times you [heard,listened to] [a,an] <S1> <A1> [or,and] [a,an] <S2> <A2>?',  # noqa: E501
                 ]

    question = str(np.random.choice(questions))  # sample question
    event_1 = str(np.random.choice(dataset['events']))  # sample event
    source_1 = str(np.random.choice(dataset['sources'][event_1]))
    action_1 = str(np.random.choice(dataset['actions'][event_1]))
    x_lst_events = [e for e in dataset['events'] if e != event_1]
    event_2 = str(np.random.choice(x_lst_events))  # sample event
    source_2 = str(np.random.choice(dataset['sources'][event_2]))
    action_2 = str(np.random.choice(dataset['actions'][event_2]))

    assert event_1 != event_2, 'Question (how_many_event_two) illposed.'

    question = question.replace('<S1>', source_1)  # insert source
    question = question.replace('<A1>', action_1)  # insert action
    question = question.replace('<S2>', source_2)  # insert source
    question = question.replace('<A2>', action_2)  # insert action
    question = sanitize_question(question)  # correct grammar

    lst_events = get_lst_events(narrative)
    answer = numbers_to_words(lst_events.count(event_1)
                              + lst_events.count(event_2))

    return question, answer
Пример #7
0
def what_was_duration_relative(dataset, narrative, rel_diff=0.1):
    questions = [
        'What was the <AD> sound <RO> the <S> <A>?',
        'What was the <AD> sound <RO> [hearing,listening to] the <S> <A>?',
        'What was the <AD> sound <RO> the <S> <A> was heard?',
    ]

    question = str(np.random.choice(questions))  # sample question
    duration = sample_absolute_duration()
    preposition = sample_preposition()
    lst_events = get_lst_events(narrative)
    unique_lst_events = [e for e in lst_events if lst_events.count(e) == 1]
    assert len(unique_lst_events) > 0, \
        'Question (what_was_duration_relative) illposed.'
    event = str(np.random.choice(unique_lst_events))
    source = str(np.random.choice(dataset['sources'][event]))  # sample source
    action = str(np.random.choice(dataset['actions'][event]))  # sample action

    question = question.replace('<AD>', duration)  # insert duration
    question = question.replace('<RO>', preposition)  # insert preposition
    question = question.replace('<S>', source)  # insert source
    question = question.replace('<A>', action)  # insert action
    question = sanitize_question(question)  # correct grammar

    assert lst_events.count(event) == 1, \
        'Question (what_was_duration_relative) illposed.'

    lst_durations = get_lst_durations(narrative)
    event_idx = lst_events.index(event)
    if 'before' in question:
        lst_events_e = lst_events[:event_idx]
        lst_events_d = lst_durations[:event_idx]
    elif 'after' in question:
        lst_events_e = lst_events[(event_idx + 1):]
        lst_events_d = lst_durations[(event_idx + 1):]
    else:
        assert False, \
            'Preposition illdefined in Question (what_was_duration_relative).'
    assert len(lst_events_e) > 0, \
        'Question (what_was_duration_relative) illposed.'
    if 'long' in question:
        est = np.argmax(lst_events_d)
    elif 'short' in question:
        est = np.argmin(lst_events_d)
    else:
        assert False, \
            'Duration illdefined in Question (what_was_duration_relative).'
    # Assert a good margin in relative duration
    evt_duration = lst_events_d[est]
    x_durations = [j for i, j in enumerate(lst_events_d) if i != est]
    rel_duration_diff = compute_rel_diff(np.array(x_durations),
                                         np.array(evt_duration))
    assert np.sum(rel_duration_diff < rel_diff) <= 0, \
        'Question (what_was_duration_relative) illposed.'
    e = lst_events_e[est]
    answer = (str(np.random.choice(dataset['sources'][e])) + ' ' +
              str(np.random.choice(dataset['actions'][e])))

    return question, answer
Пример #8
0
def what_was_duration_relative_ordinal(dataset, narrative, rel_diff=0.1):
    questions = [
        'What was the <AD> sound <RO> the <O> sound?',
        'What was the <AD> sound <RO> [hearing,listening to] the <O> sound?',
        'What was the <AD> sound <RO> the <O> sound was heard?',
    ]

    question = str(np.random.choice(questions))  # sample question
    duration = sample_absolute_duration()
    preposition = sample_preposition()
    lst_events = get_lst_events(narrative)
    number, ordinal = sample_number(len(lst_events))

    question = question.replace('<AD>', duration)  # insert duration
    question = question.replace('<RO>', preposition)  # insert preposition
    question = question.replace('<O>', ordinal)  # insert ordinal
    question = sanitize_question(question)  # correct grammar

    lst_durations = get_lst_durations(narrative)
    event_idx = (number - 1)
    answer = None
    if 'before' in question:
        if (event_idx - 1) < 0:
            answer = 'nothing'
        else:
            lst_events_e = lst_events[:event_idx]
            lst_events_d = lst_durations[:event_idx]
    elif 'after' in question:
        if (event_idx + 1) >= len(lst_events):
            answer = 'nothing'
        else:
            lst_events_e = lst_events[(event_idx + 1):]
            lst_events_d = lst_durations[(event_idx + 1):]
    else:
        assert False, \
            'Preposition illdefined in Question (what_was_duration_relative_ordinal).'
    if answer is None:
        assert len(lst_events_e) > 0, \
            'Question (what_was_duration_relative_ordinal) illposed.'
        if 'long' in question:
            est = np.argmax(lst_events_d)
        elif 'short' in question:
            est = np.argmin(lst_events_d)
        else:
            assert False, \
                'Duration illdefined in Question (what_was_duration_relative_ordinal).'
        # Assert a good margin in relative duration
        evt_duration = lst_events_d[est]
        x_durations = [j for i, j in enumerate(lst_events_d) if i != est]
        rel_duration_diff = compute_rel_diff(np.array(x_durations),
                                             np.array(evt_duration))
        assert np.sum(rel_duration_diff < rel_diff) <= 0, \
            'Question (what_was_duration_relative_ordinal) illposed.'
        e = lst_events_e[est]
        answer = (str(np.random.choice(dataset['sources'][e])) + ' ' +
                  str(np.random.choice(dataset['actions'][e])))

    return question, answer
Пример #9
0
def was_there_immediate_relative(dataset, narrative, _):
    questions = [
        'Did you [hear,listen to] [a,an] <S1> <A1> <IO> the <S2> <A2>?',  # noqa: E501
        'Have you [heard,listened to] [a,an] <S1> <A1> <IO> the <S2> <A2>?',  # noqa: E501
        'Did you [hear,listen to] any <S1> <A1> <IO> the <S2> <A2>?',
        'Have you [heard,listened to] any <S1> <A1> <IO> the <S2> <A2>?',
        'Was there [a,an] <S1> <A1> <IO> the <S2> <A2>?',
        'Were there any <S1>s <A1> <IO> the <S2> <A2>?',
        'Did you [hear,listen to] a sound that [sounds like,sounded like,is,was] [a,an] <S1> <A1> <IO> the <S2> <A2>?',  # noqa: E501
        '<IO> the <S2> <A2>, did you [hear,listen to] [a,an] <S1> <A1> ?',  # noqa: E501
        '<IO> the <S2> <A2>, did you [hear,listen to] any <S1> <A1>?',
        '<IO> the <S2> <A2>, was there [a,an] <S1> <A1>?',
        '<IO> the <S2> <A2>, were there any <S1>s <A1>?',
        '<IO> the <S2> <A2>, did you [hear,listen to] a sound that [sounds like,sounded like,is,was] [a,an] <S1> <A1>?',  # noqa: E501
    ]

    question = str(np.random.choice(questions))  # sample question
    event_1 = str(np.random.choice(dataset['events']))  # sample event
    source_1 = str(np.random.choice(dataset['sources'][event_1]))
    action_1 = str(np.random.choice(dataset['actions'][event_1]))
    preposition = sample_immediate_preposition()
    lst_events = get_lst_events(narrative)
    unique_lst_events = [e for e in lst_events if lst_events.count(e) == 1]
    unique_lst_events = [e for e in unique_lst_events if e != event_1]
    assert len(unique_lst_events) > 0, \
        'Question (was_there_immediate_relative) illposed.'
    event_2 = str(np.random.choice(unique_lst_events))
    source_2 = str(np.random.choice(dataset['sources'][event_2]))
    action_2 = str(np.random.choice(dataset['actions'][event_2]))

    question = question.replace('<S1>', source_1)  # insert source
    question = question.replace('<A1>', action_1)  # insert action
    question = question.replace('<IO>', preposition)  # insert preposition
    question = question.replace('<S2>', source_2)  # insert source
    question = question.replace('<A2>', action_2)  # insert action
    question = sanitize_question(question)  # correct grammar

    assert lst_events.count(event_2) == 1, \
        'Question (was_there_immediate_relative) illposed.'

    event_2_idx = lst_events.index(event_2)
    if 'before' in preposition:
        if (event_2_idx - 1) < 0:
            target_event = []
        else:
            target_event = lst_events[event_2_idx - 1]
    elif 'after' in preposition:
        if (event_2_idx + 1) >= len(lst_events):
            target_event = []
        else:
            target_event = lst_events[event_2_idx + 1]
    else:
        assert False, \
            'Preposition illdefined in Question (was_there_immediate_relative).'
    answer = 'yes' if event_1 == target_event else 'no'

    return question, answer
Пример #10
0
def what_was_relative(dataset, narrative, _):
    questions = [
        'What was the sound <RO> the <S> <A>?',
        'What was the sound <RO> [hearing,listening to] the <S> <A>?',
        'What was the sound <RO> the <S> <A> was heard?',
        'What did you [hear,listen to] <RO> the <S> <A>?',
        'What did you [hear,listen to] <RO> [hearing,listening to] the <S> <A>?',  # noqa: E501
        'What did you [hear,listen to] <RO> the <S> <A> was heard?',
        'What was the sound <IO> the <S> <A>?',
        'What was the sound <IO> [hearing,listening to] the <S> <A>?',
        'What was the sound <IO> the <S> <A> was heard?',
        'What did you [hear,listen to] <IO> the <S> <A>?',
        'What did you [hear,listen to] <IO> [hearing,listening to] the <S> <A>?',  # noqa: E501
        'What did you [hear,listen to] <IO> the <S> <A> was heard?',
    ]

    question = str(np.random.choice(questions))  # sample question
    preposition = sample_preposition()
    immediate_preposition = sample_immediate_preposition()
    lst_events = get_lst_events(narrative)
    unique_lst_events = [e for e in lst_events if lst_events.count(e) == 1]
    assert len(unique_lst_events) > 0, \
        'Question (what_was_relative) illposed.'
    event = str(np.random.choice(unique_lst_events))
    source = str(np.random.choice(dataset['sources'][event]))  # sample source
    action = str(np.random.choice(dataset['actions'][event]))  # sample action

    # Only one of the following two lines will have an effect
    question = question.replace('<RO>', preposition)  # insert preposition
    question = question.replace('<IO>', immediate_preposition)
    question = question.replace('<S>', source)  # insert source
    question = question.replace('<A>', action)  # insert action
    question = sanitize_question(question)  # correct grammar

    assert lst_events.count(event) == 1, \
        'Question (what_was_relative) illposed.'

    event_idx = lst_events.index(event)
    if 'before' in question:
        if (event_idx - 1) < 0:
            answer = 'nothing'
        else:
            e = lst_events[event_idx - 1]
            answer = (str(np.random.choice(dataset['sources'][e])) + ' ' +
                      str(np.random.choice(dataset['actions'][e])))
    elif 'after' in question:
        if (event_idx + 1) >= len(lst_events):
            answer = 'nothing'
        else:
            e = lst_events[event_idx + 1]
            answer = (str(np.random.choice(dataset['sources'][e])) + ' ' +
                      str(np.random.choice(dataset['actions'][e])))
    else:
        assert False, 'Preposition illdefined in Question (what_was_relative).'

    return question, answer
Пример #11
0
def compare_duration(dataset, narrative, rel_diff=0.1):
    questions = [
        'Was the <S1> <A1> <RD> than the <S2> <A2>?',
        'Was the sound of the <S1> <A1> <RD> than the sound of the <S2> <A2>?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the sound of the <S1> <A1> and the sound of the <S2> <A2>, was the former <RD>?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the sounds of the <S1> <A1> and the <S2> <A2>, was the former <RD>?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the sound of the <S2> <A2> and the sound of the <S1> <A1>, was the latter <RD>?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the sounds of the <S2> <A2> and the <S1> <A1>, was the latter <RD>?',  # noqa: E501
    ]

    question = str(np.random.choice(questions))  # sample question
    lst_events = get_lst_events(narrative)
    unique_lst_events = [e for e in lst_events if lst_events.count(e) == 1]
    assert len(unique_lst_events) > 0, \
        'Question (compare_duration) illposed.'
    event_1 = str(np.random.choice(unique_lst_events))  # sample event
    source_1 = str(np.random.choice(dataset['sources'][event_1]))
    action_1 = str(np.random.choice(dataset['actions'][event_1]))
    rel_duration = sample_rel_duration()
    x_unique_lst_events = [e for e in unique_lst_events if e != event_1]
    assert len(x_unique_lst_events) > 0, \
        'Question (compare_duration) illposed.'
    event_2 = str(np.random.choice(x_unique_lst_events))  # sample event
    source_2 = str(np.random.choice(dataset['sources'][event_2]))
    action_2 = str(np.random.choice(dataset['actions'][event_2]))

    assert lst_events.count(event_1) == 1, \
        'Question (compare_duration) illposed.'
    assert lst_events.count(event_2) == 1, \
        'Question (compare_duration) illposed.'
    assert event_1 != event_2, 'Question (compare_duration) illposed.'

    question = question.replace('<S1>', source_1)  # insert source
    question = question.replace('<A1>', action_1)  # insert action
    question = question.replace('<RD>', rel_duration)  # insert duration
    question = question.replace('<S2>', source_2)  # insert source
    question = question.replace('<A2>', action_2)  # insert action
    question = sanitize_question(question)

    lst_duration = get_lst_durations(narrative)
    e_1_duration = lst_duration[lst_events.index(event_1)]
    e_2_duration = lst_duration[lst_events.index(event_2)]
    # Assert a good margin in relative duration
    rel_duration_diff = compute_rel_diff(np.array(e_1_duration),
                                         np.array(e_2_duration))
    assert np.sum(rel_duration_diff < rel_diff) <= 0, \
        'Question (compare_duration) illposed.'
    if 'short' in question:
        answer = 'yes' if e_1_duration < e_2_duration else 'no'
    elif 'long' in question:
        answer = 'yes' if e_1_duration > e_2_duration else 'no'
    else:
        assert False, 'Duration illdefined in Question (compare_duration).'

    return question, answer
Пример #12
0
def compare_same_duration(dataset, narrative, rel_diff=0.1):
    questions = [
        'Was the <S1> <A1> [roughly,approximately] as <D> as the <S2> <A2>?',  # noqa: E501
        'Was the sound of the <S1> <A1> [roughly,approximately] as <D> as the sound of the <S2> <A2>?',  # noqa: E501
        'Was the sound of the <S1> <A1> [roughly,approximately] the same duration as the sound of the <S2> <A2>?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the sound of the <S1> <A1> and the sound of the <S2> <A2>, did they [roughly,approximately] have the same duration?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the sounds of the <S1> <A1> and the <S2> <A2>, did they [roughly,approximately] have the same duration?',  # noqa: E501
    ]

    question = str(np.random.choice(questions))  # sample question
    lst_events = get_lst_events(narrative)
    unique_lst_events = [e for e in lst_events if lst_events.count(e) == 1]
    assert len(unique_lst_events) > 0, \
        'Question (compare_same_duration) illposed.'
    event_1 = str(np.random.choice(unique_lst_events))  # sample event
    source_1 = str(np.random.choice(dataset['sources'][event_1]))
    action_1 = str(np.random.choice(dataset['actions'][event_1]))
    duration = sample_duration()
    x_unique_lst_events = [e for e in unique_lst_events if e != event_1]
    assert len(x_unique_lst_events) > 0, \
        'Question (compare_same_duration) illposed.'
    event_2 = str(np.random.choice(x_unique_lst_events))  # sample event
    source_2 = str(np.random.choice(dataset['sources'][event_2]))
    action_2 = str(np.random.choice(dataset['actions'][event_2]))

    assert lst_events.count(event_1) == 1, \
        'Question (compare_same_duration) illposed.'
    assert lst_events.count(event_2) == 1, \
        'Question (compare_same_duration) illposed.'
    assert event_1 != event_2, 'Question (compare_same_duration) illposed.'

    question = question.replace('<S1>', source_1)  # insert source
    question = question.replace('<A1>', action_1)  # insert action
    question = question.replace('<D>', duration)  # insert duration
    question = question.replace('<S2>', source_2)  # insert source
    question = question.replace('<A2>', action_2)  # insert action
    question = sanitize_question(question)

    lst_duration = get_lst_durations(narrative)
    e_1_duration = lst_duration[lst_events.index(event_1)]
    e_2_duration = lst_duration[lst_events.index(event_2)]
    rel_duration_diff = compute_rel_diff(np.array(e_1_duration),
                                         np.array(e_2_duration))
    # Assert a good margin in relative duration
    assert np.sum(np.logical_and(rel_duration_diff > rel_diff,
                                 rel_duration_diff < (2 * rel_diff))) <= 0, \
        'Question (compare_same_duration) illposed.'
    answer = 'yes' if rel_duration_diff <= rel_diff else 'no'

    return question, answer
Пример #13
0
def compare_same_duration_event_ordinal(dataset, narrative, rel_diff=0.1):
    questions = [
        'Was the <S> <A> [roughly,approximately] as <D> as the <O> [sound event,sound]?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the <S> <A> and the <O> [sound event,sound], were they [roughly,approximately] as <D>?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the sound of the <S> <A> and the <O> [sound event,sound], were they [roughly,approximately] as <D>?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the <S> <A> and the <O> [sound event,sound], did they [roughly,approximately] have the same duration?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the sound of the <S> <A> and the <O> [sound event,sound], did they [roughly,approximately] have the same duration?',  # noqa: E501
        'Was the <O> [sound event,sound] [roughly,approximately] as <D> as the <S> <A>?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the <O> [sound event,sound] and the <S> <A>, were they [roughly,approximately] as <D>?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the <O> [sound event,sound] and the sound of the <S> <A>, were they [roughly,approximately] as <D>?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the <O> [sound event,sound] and the <S> <A>, did they [roughly,approximately] have the same duration?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the <O> [sound event,sound] and the sound of the <S> <A>, did they [roughly,approximately] have the same duration?',  # noqa: E501
    ]

    question = str(np.random.choice(questions))  # sample question
    lst_events = get_lst_events(narrative)
    unique_lst_events = [e for e in lst_events if lst_events.count(e) == 1]
    assert len(unique_lst_events) > 0, \
        'Question (compare_same_duration_event_ordinal) illposed.'
    event = str(np.random.choice(unique_lst_events))  # sample event
    source = str(np.random.choice(dataset['sources'][event]))
    action = str(np.random.choice(dataset['actions'][event]))
    duration = sample_duration()
    number, ordinal = sample_second_number(len(lst_events),
                                           lst_events.index(event) + 1)

    assert lst_events.count(event) == 1, \
        'Question (compare_same_duration_event_ordinal) illposed.'
    assert lst_events.index(event) != (number - 1), \
        'Question (compare_same_duration_event_ordinal) illposed.'

    question = question.replace('<S>', source)  # insert source
    question = question.replace('<A>', action)  # insert action
    question = question.replace('<D>', duration)  # insert duration
    question = question.replace('<O>', ordinal)  # insert ordinal
    question = sanitize_question(question)  # correct grammar

    lst_duration = get_lst_durations(narrative)
    e_1_duration = lst_duration[lst_events.index(event)]
    e_2_duration = lst_duration[number - 1]
    rel_duration_diff = compute_rel_diff(np.array(e_1_duration),
                                         np.array(e_2_duration))
    # Assert a good margin in relative duration
    assert np.sum(np.logical_and(rel_duration_diff > rel_diff,
                                 rel_duration_diff < (2 * rel_diff))) <= 0, \
        'Question (compare_same_duration_event_ordinal) illposed.'
    answer = 'yes' if rel_duration_diff <= rel_diff else 'no'

    return question, answer
Пример #14
0
def how_many_sounds_duration_event(dataset, narrative, rel_diff=0.1):
    questions = ['How many [sound events,sounds] [roughly,approximately] as <D> as the <S> <A>?',  # noqa: E501
                 'How many [sound events,sounds] that are [roughly,approximately] as <D> as the <S> <A> [did,could] you [hear,listen to]?',  # noqa: E501
                 'How many [sound events,sounds] that are [roughly,approximately] as <D> as the <S> <A> have you heard?',  # noqa: E501
                 'How many [sound events,sounds] that have [roughly,approximately] the same duration as the <S> <A>?',  # noqa: E501
                 'How many [sound events,sounds] that have [roughly,approximately] the same duration as the <S> <A> [did,could] you [hear,listen to]?',  # noqa: E501
                 'How many [sound events,sounds] that have [roughly,approximately] the same duration as the <S> <A> have you heard?',  # noqa: E501
                 'What is the number of [sound events,sounds] [roughly,approximately] as <D> as the <S> <A>?',  # noqa: E501
                 'What is the number of [sound events,sounds] that are [roughly,approximately] as <D> as the <S> <A> [did,could] you [hear,listen to]?',  # noqa: E501
                 'What is the number of [sound events,sounds] that are [roughly,approximately] as <D> as the <S> <A> have you heard?',  # noqa: E501
                 'What is the number of [sound events,sounds] that have [roughly,approximately] the same duration as the <S> <A>?',  # noqa: E501
                 'What is the number of [sound events,sounds] that have [roughly,approximately] the same duration as the <S> <A> [did,could] you [hear,listen to]?',  # noqa: E501
                 'What is the number of [sound events,sounds] that have [roughly,approximately] the same duration as the <S> <A> have you heard?',  # noqa: E501
                 'There is [a,an] <S> <A>; how many [sound events,sounds] that are [roughly,approximately] as <D>?',  # noqa: E501
                 'There is [a,an] <S> <A>; what is the number of [sound events,sounds] that are [roughly,approximately] as <D>?',  # noqa: E501
                 ]

    question = str(np.random.choice(questions))  # sample question
    duration = sample_duration()  # sample duration
    lst_events = get_lst_events(narrative)
    unique_lst_events = [e for e in lst_events if lst_events.count(e) == 1]
    assert len(unique_lst_events) > 0, \
        'Question (how_many_sounds_duration_event) illposed.'
    event = str(np.random.choice(unique_lst_events))
    source = str(np.random.choice(dataset['sources'][event]))  # sample source
    action = str(np.random.choice(dataset['actions'][event]))  # sample action

    question = question.replace('<D>', duration)  # insert duration
    question = question.replace('<S>', source)  # insert source
    question = question.replace('<A>', action)  # insert action
    question = sanitize_question(question)  # correct grammar

    assert lst_events.count(event) == 1, \
        'Question (how_many_sounds_duration_event) illposed.'

    lst_durations = get_lst_durations(narrative)
    event_idx = lst_events.index(event)
    evt_duration = lst_durations[event_idx]
    x_durations = [j for i, j in enumerate(lst_durations) if i != event_idx]
    rel_durations_diff = compute_rel_diff(np.array(x_durations),
                                          np.array(evt_duration))
    # Assert a good margin in relative loudness
    assert np.sum(np.logical_and(rel_durations_diff > rel_diff,
                                 rel_durations_diff < (2 * rel_diff))) <= 0, \
        'Question (how_many_sounds_duration_event) illposed.'
    answer = numbers_to_words(np.sum(rel_durations_diff <= rel_diff))

    return question, answer
Пример #15
0
def compare_duration_ordinal_event(dataset, narrative, rel_diff=0.1):
    questions = [
        'Was the <O> [sound event,sound] <RD> than the <S> <A>?',
        'Was the <O> [sound event,sound] <RD> than the sound of the <S> <A>?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the <O> [sound event,sound] and the <S> <A>, was the former <RD>?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the <S> <A> and the <O> [sound event,sound], was the latter <RD>?',  # noqa: E501
    ]

    question = str(np.random.choice(questions))  # sample question
    lst_events = get_lst_events(narrative)
    unique_lst_events = [e for e in lst_events if lst_events.count(e) == 1]
    assert len(unique_lst_events) > 0, \
        'Question (compare_duration_ordinal_event) illposed.'
    event = str(np.random.choice(unique_lst_events))  # sample event
    source = str(np.random.choice(dataset['sources'][event]))
    action = str(np.random.choice(dataset['actions'][event]))
    rel_duration = sample_rel_duration()
    number, ordinal = sample_second_number(len(lst_events),
                                           lst_events.index(event) + 1)

    assert lst_events.count(event) == 1, \
        'Question (compare_duration_ordinal_event) illposed.'
    assert lst_events.index(event) != (number - 1), \
        'Question (compare_duration_ordinal_event) illposed.'

    question = question.replace('<S>', source)  # insert source
    question = question.replace('<A>', action)  # insert action
    question = question.replace('<RD>', rel_duration)  # insert duration
    question = question.replace('<O>', ordinal)  # insert ordinal
    question = sanitize_question(question)  # correct grammar

    lst_duration = get_lst_durations(narrative)
    e_1_duration = lst_duration[number - 1]
    e_2_duration = lst_duration[lst_events.index(event)]
    # Assert a good margin in relative duration
    rel_duration_diff = compute_rel_diff(np.array(e_1_duration),
                                         np.array(e_2_duration))
    assert np.sum(rel_duration_diff < rel_diff) <= 0, \
        'Question (compare_duration_ordinal_event) illposed.'
    if 'short' in question:
        answer = 'yes' if e_1_duration < e_2_duration else 'no'
    elif 'long' in question:
        answer = 'yes' if e_1_duration > e_2_duration else 'no'
    else:
        assert False, \
            'Duration illdefined in Question (compare_duration_ordinal_event).'

    return question, answer
Пример #16
0
def was_there_similar_duration(dataset, narrative, rel_diff=0.1):
    questions = [
        'Were there any sounds [roughly,approximately] as <D> as the <S> <A>?',  # noqa: E501
        'Were there any sounds that were [roughly,approximately] as <D> as the <S> <A>?',  # noqa: E501
        'Were there any sounds that were [roughly,approximately] the same duration as the <S> <A>?',  # noqa: E501
        'Was there any sound [roughly,approximately] as <D> as the <S> <A>?',  # noqa: E501
        'Was there any sound that was [roughly,approximately] as <D> as the <S> <A>?',  # noqa: E501
        'Was there any sound that was [roughly,approximately] the same duration as the <S> <A>?',  # noqa: E501
        'Was there at least a sound [roughly,approximately] as <D> as the <S> <A>?',  # noqa: E501
        'Was there at least a sound that was [roughly,approximately] as <D> as the <S> <A>?',  # noqa: E501
        'Was there at least a sound that was [roughly,approximately] the same duration as <S> <A>?',  # noqa: E501
        'Was there at least [one,a single] sound [roughly,approximately] as <D> as the <S> <A>?',  # noqa: E501
        'Was there at least [one,a single] sound that was [roughly,approximately] as <D> as the <S> <A>?',  # noqa: E501
        'Was there at least [one,a single] sound that was [roughly,approximately] the same duration as <S> <A>?',  # noqa: E501
    ]

    question = str(np.random.choice(questions))  # sample question
    duration = sample_duration()  # sample duration
    lst_events = get_lst_events(narrative)
    unique_lst_events = [e for e in lst_events if lst_events.count(e) == 1]
    assert len(unique_lst_events) > 0, \
        'Question (was_there_similar_duration) illposed.'
    event = str(np.random.choice(unique_lst_events))
    source = str(np.random.choice(dataset['sources'][event]))  # sample source
    action = str(np.random.choice(dataset['actions'][event]))  # sample action

    question = question.replace('<D>', duration)  # insert duration
    question = question.replace('<S>', source)  # insert source
    question = question.replace('<A>', action)  # insert action
    question = sanitize_question(question)  # correct grammar

    assert lst_events.count(event) == 1, \
        'Question (was_there_similar_duration) illposed.'

    lst_durations = get_lst_durations(narrative)
    event_idx = lst_events.index(event)
    evt_duration = lst_durations[event_idx]
    x_durations = [j for i, j in enumerate(lst_durations) if i != event_idx]
    rel_durations_diff = compute_rel_diff(np.array(x_durations),
                                          np.array(evt_duration))
    # Assert a good margin in relative duration
    assert np.sum(np.logical_and(rel_durations_diff > rel_diff,
                                 rel_durations_diff < (2 * rel_diff))) <= 0, \
        'Question (was_there_similar_duration) illposed.'
    answer = 'yes' if np.sum(rel_durations_diff <= rel_diff) >= 1 else 'no'

    return question, answer
Пример #17
0
def how_many_event_relative(dataset, narrative, _):
    questions = ['How many <S1>s <A1> <RO> the <S2> <A2> were there?',
                 'How many <S1>s <A1> <RO> the <S2> <A2> [did,could] you [hear,listen to]?',  # noqa: E501
                 'How many <S1>s <A1> <RO> the <S2> <A2> have you [heard,listened to]?',  # noqa: E501
                 'What is the number of <S1>s <A1> <RO> the <S2> <A2>?',
                 'What is the number of <S1>s <A1> <RO> the <S2> <A2> [did,could] you [hear,listen to]?',  # noqa: E501
                 'What is the number of <S1>s <A1> <RO> the <S2> <A2> have you [heard,listened to]?',  # noqa: E501
                 'There is [a,an] <S2> <A2>; how many <S1>s <A1> [did,could] you hear <RO>?',  # noqa: E501
                 'There is [a,an] <S2> <A2>; how many <S1>s <A1> have you heard <RO>?',  # noqa: E501
                 'There is [a,an] <S2> <A2>; what is the number of <S1>s <A1> [did,could] you hear <RO>?',  # noqa: E501
                 ]

    question = str(np.random.choice(questions))  # sample question
    event_1 = str(np.random.choice(dataset['events']))  # sample event
    source_1 = str(np.random.choice(dataset['sources'][event_1]))
    action_1 = str(np.random.choice(dataset['actions'][event_1]))
    preposition = sample_preposition()
    lst_events = get_lst_events(narrative)
    unique_lst_events = [e for e in lst_events if lst_events.count(e) == 1]
    unique_lst_events = [e for e in unique_lst_events if e != event_1]
    assert len(unique_lst_events) > 0, \
        'Question (how_many_event_relative) illposed.'
    event_2 = str(np.random.choice(unique_lst_events))
    source_2 = str(np.random.choice(dataset['sources'][event_2]))
    action_2 = str(np.random.choice(dataset['actions'][event_2]))

    question = question.replace('<S1>', source_1)  # insert source
    question = question.replace('<A1>', action_1)  # insert action
    question = question.replace('<RO>', preposition)  # insert preposition
    question = question.replace('<S2>', source_2)  # insert source
    question = question.replace('<A2>', action_2)  # insert action
    question = sanitize_question(question)  # correct grammar

    assert lst_events.count(event_2) == 1, \
        'Question (how_many_event_relative) illposed.'

    event_2_idx = lst_events.index(event_2)
    if 'before' in question:
        lst_events_e = lst_events[:event_2_idx]
    elif 'after' in question:
        lst_events_e = lst_events[(event_2_idx + 1):]
    else:
        assert False, \
            'Relative preposition illdefined in Question (how_many_event_relative).'
    answer = numbers_to_words(lst_events_e.count(event_1))

    return question, answer
Пример #18
0
def how_many(dataset, narrative, _):
    questions = ['How many [sound events,sounds] were there?',
                 'How many [sound events,sounds] [did,could] you [hear,listen to]?',
                 'How many [sound events,sounds] have you [heard,listened to]?',
                 'What is the number of [sound events,sounds]?',
                 'What is the number of [sound events,sounds] [did,could] you [hear,listen to]?',  # noqa: E501
                 'What is the number of [sound events,sounds] have you [heard,listened to]?',  # noqa: E501
                 ]

    question = str(np.random.choice(questions))  # sample question

    question = sanitize_question(question)  # correct grammar

    lst_events = get_lst_events(narrative)
    answer = numbers_to_words(len(lst_events))

    return question, answer
Пример #19
0
def how_many_ordinal(dataset, narrative, _):
    questions = ['How many times did you [hear,listen to] a sound that [sounded,seemed] like the <O> [sound event,sound]?',  # noqa: E501
                 'What is the number of times did you [hear,listen to] a sound that [sounded,seemed] like the <O> [sound event,sound]?',  # noqa: E501
                 '[Hearing,Listening to] the <O> [sound event,sound], how many sounds were [the same, similar]?',  # noqa: E501
                 '[Hearing,Listening to] the <O> [sound event,sound], what is the number of sounds that were [the same, similar]?',  # noqa: E501
                 ]

    question = str(np.random.choice(questions))  # sample question
    lst_events = get_lst_events(narrative)
    number, ordinal = sample_number(len(lst_events))

    question = question.replace('<O>', ordinal)  # insert ordinal
    question = sanitize_question(question)  # correct grammar

    event = lst_events[number - 1]
    answer = numbers_to_words(lst_events.count(event) - 1)  # -1 for base event

    return question, answer
Пример #20
0
def what_was(dataset, narrative, _):
    questions = [
        'What was the <O> sound you [heard,listened to]?',
        'What was the <O> sound?',
        'What did the <O> sound [sound,seem] like?',
    ]

    question = str(np.random.choice(questions))  # sample question
    lst_events = get_lst_events(narrative)
    number, ordinal = sample_number(len(lst_events))

    question = question.replace('<O>', ordinal)  # insert ordinal
    question = sanitize_question(question)  # correct grammar

    event = lst_events[number - 1]
    answer = (str(np.random.choice(dataset['sources'][event])) + ' ' +
              str(np.random.choice(dataset['actions'][event])))

    return question, answer
Пример #21
0
def how_many_sounds_relative(dataset, narrative, _):
    questions = ['How many [sound events,sounds] <RO> the <S> <A> were there?',
                 'How many [sound events,sounds] <RO> the <S> <A> [did,could] you [hear,listen to]?',  # noqa: E501
                 'How many [sound events,sounds] <RO> the <S> <A> have you [heard,listened to]?',  # noqa: E501
                 'What is the number of [sound events,sounds] <RO> the <S> <A>?',
                 'What is the number of [sound events,sounds] <RO> the <S> <A> [did,could] you [hear,listen to]?',  # noqa: E501
                 'What is the number of [sound events,sounds] <RO> the <S> <A> have you [heard,listened to]?',  # noqa: E501
                 'There is [a,an] <S> <A>; how many [sound events,sounds] [did,could] you hear <RO>?',  # noqa: E501
                 'There is [a,an] <S> <A>; how many [sound events,sounds] have you heard <RO>?',  # noqa: E501
                 'There is [a,an] <S> <A>; what is the number of [sound events,sounds] [did,could] you hear <RO>?',  # noqa: E501
                 ]

    question = str(np.random.choice(questions))  # sample question
    preposition = sample_preposition()
    lst_events = get_lst_events(narrative)
    unique_lst_events = [e for e in lst_events if lst_events.count(e) == 1]
    assert len(unique_lst_events) > 0, \
        'Question (how_many_sounds_relative) illposed.'
    event = str(np.random.choice(unique_lst_events))
    source = str(np.random.choice(dataset['sources'][event]))  # sample source
    action = str(np.random.choice(dataset['actions'][event]))  # sample action

    question = question.replace('<RO>', preposition)  # insert preposition
    question = question.replace('<S>', source)  # insert source
    question = question.replace('<A>', action)  # insert action
    question = sanitize_question(question)  # correct grammar

    assert lst_events.count(event) == 1, \
        'Question (how_many_sounds_relative) illposed.'

    event_idx = lst_events.index(event)
    if 'before' in question:
        lst_events_e = lst_events[:event_idx]
    elif 'after' in question:
        lst_events_e = lst_events[(event_idx + 1):]
    else:
        assert False, \
            'Preposition illdefined in Question (how_many_sounds_relative).'
    answer = numbers_to_words(len(lst_events_e))

    return question, answer
Пример #22
0
def was_there_similar_ordinal(dataset, narrative, _):
    questions = [
        'Were there any similar sounds to the <O> sound?',
        'Were there any sounds that were similar to the <O> sound?',
        'Was there at least a sound similar to the <O> sound?',
        'Was there at least a sound that was similar to the <O> sound?',  # noqa: E501
        'Was there at least [one,a single] sound similar to the <O> sound?',
        'Was there at least [one,a single] sound that was similar to the <O> sound?',  # noqa: E501
    ]

    question = str(np.random.choice(questions))  # sample question
    lst_events = get_lst_events(narrative)
    number, ordinal = sample_number(len(lst_events))

    question = question.replace('<O>', ordinal)  # insert ordinal
    question = sanitize_question(question)  # correct grammar

    event = lst_events[number - 1]
    answer = 'yes' if lst_events.count(event) > 1 else 'no'  # 1 for reference

    return question, answer
Пример #23
0
def was_there_source(dataset, narrative, _):
    questions = [
        'Did you [hear,listen to] [a,an] <S>?',
        'Have you [heard,listened to] [a,an] <S>?'
        'Did you [hear,listen to] any <S>?',
        'Have you [heard,listened to] any <S>?',
        'Was there a sound [produced,made] by [a,an] <S>?',
        'Were there any sounds [produced,made] by [a,an] <S>?',
    ]

    question = str(np.random.choice(questions))  # sample question
    event = str(np.random.choice(dataset['events']))  # sample event
    source = str(np.random.choice(dataset['sources'][event]))  # sample source

    question = question.replace('<S>', source)  # insert source
    question = sanitize_question(question)  # correct grammar

    answer = 'yes' if source in get_lst_all_sources(dataset,
                                                    narrative) else 'no'

    return question, answer
Пример #24
0
def how_many_sounds_relative_ordinal(dataset, narrative, _):
    questions = ['How many [sound events,sounds] after the <O> [sound event,sound] were there?',  # noqa: E501
                 'How many [sound events,sounds] after the <O> [sound event,sound] [did,could] you [hear,listen to]?',  # noqa: E501
                 'How many [sound events,sounds] after the <O> [sound event,sound] have you [heard,listened to]?',  # noqa: E501
                 'What is the number of [sound events,sounds] after the <O> [sound event,sound]?',  # noqa: E501
                 'What is the number of [sound events,sounds] after the <O> [sound event,sound] [did,could] you [hear,listen to]?',  # noqa: E501
                 'What is the number of [sound events,sounds] after the <O> [sound event,sound] have you [heard,listened to]?',  # noqa: E501
                 ]

    question = str(np.random.choice(questions))  # sample question
    lst_events = get_lst_events(narrative)
    number, ordinal = sample_number(len(lst_events))

    question = question.replace('<O>', ordinal)  # insert ordinal
    question = sanitize_question(question)  # correct grammar

    assert number < (len(lst_events) - 1), \
        'Question (how_many_sounds_relative_ordinal) illposed.'
    lst_events_e = lst_events[number:]
    answer = numbers_to_words(len(lst_events_e))

    return question, answer
Пример #25
0
def how_many_event(dataset, narrative, _):
    questions = ['How many times was [a,an] <S> <A>?',
                 'How many times did you [hear,listen to] [a,an] <S> <A>?',
                 'How many times have you [heard,listened to] [a,an] <S> <A>?',
                 'What is the number of times [a,an] <S> <A>?',
                 'What is the number of times did you [hear,listen to] [a,an] <S> <A>?',  # noqa: E501
                 'What is the number of times you [heard,listened to] [a,an] <S> <A>?',  # noqa: E501
                 ]

    question = str(np.random.choice(questions))  # sample question
    lst_events = get_lst_events(narrative)
    event = str(np.random.choice(lst_events))
    source = str(np.random.choice(dataset['sources'][event]))  # sample source
    action = str(np.random.choice(dataset['actions'][event]))  # sample action

    question = question.replace('<S>', source)  # insert source
    question = question.replace('<A>', action)  # insert action
    question = sanitize_question(question)  # correct grammar

    answer = numbers_to_words(lst_events.count(event))

    return question, answer
Пример #26
0
def compare_ordinal(dataset, narrative, _):
    questions = [
        'Was the <O1> [sound event,sound] [the same as,similar to] the <O2> [sound event,sound]?',  # noqa: E501
        'Was the <O1> [sound event,sound] and <O2> [sound event,sound] [the same,similar]?',  # noqa: E501
        'Were the <O1> and <O2> [sound events,sounds] [the same,similar]?',
    ]

    question = str(np.random.choice(questions))  # sample question
    lst_events = get_lst_events(narrative)
    number_1, ordinal_1 = sample_number(len(lst_events))
    number_2, ordinal_2 = sample_second_number(len(lst_events), number_1)

    assert number_1 != number_2, 'Question (compare_ordinal) illposed.'

    question = question.replace('<O1>', ordinal_1)  # insert ordinal
    question = question.replace('<O2>', ordinal_2)  # insert ordinal
    question = sanitize_question(question)  # correct grammar

    answer = 'yes' if lst_events[number_1 - 1] == lst_events[number_2 - 1] \
        else 'no'

    return question, answer
Пример #27
0
def was_there_two_or(dataset, narrative, _):
    questions = [
        'Did you [hear,listen to] [a,an] <S1> <A1> or [a,an] <S2> <A2>?',
        'Have you [heard,listened to] [a,an] <S1> <A1> or [a,an] <S2> <A2>?',
        'Did you [hear,listen to] any <S1> <A1> or any <S2> <A2>?',
        'Have you [heard,listened to] any <S1> <A1> or any <S2> <A2>?',
        'Did you [hear,listen to] a sound that [sounds like,is] [a,an] <S1> <A1> or a sound [sounds like,is] [a,an] <S2> <A2>?',  # noqa: E501
        'Did you [hear,listen to] a sound that [sounded like,was] [a,an] <S1> <A1> or a sound [sounded like,was] [a,an] <S2> <A2>?',  # noqa: E501
        'Have you [heard,listened to] a sound that [sounds like,is] [a,an] <S1> <A1> or a sound [sounds like,is] [a,an] <S2> <A2>?',  # noqa: E501
        'Have you [heard,listened to] a sound that [sounded like,was] [a,an] <S1> <A1> or a sound [sounded like,was] [a,an] <S2> <A2>?',  # noqa: E501
        'Was there [a,an] <S1> <A1> or [a,an] <S2> <A2>?',
        'Were there any <S1>s <A1> or any <S2>s <A2>?',
    ]

    question = str(np.random.choice(questions))  # sample question
    event_1 = str(np.random.choice(dataset['events']))  # sample event
    source_1 = str(np.random.choice(
        dataset['sources'][event_1]))  # sample source
    action_1 = str(np.random.choice(
        dataset['actions'][event_1]))  # sample action
    lst_events = [e for e in dataset['events'] if e != event_1]
    event_2 = str(np.random.choice(lst_events))  # sample event
    source_2 = str(np.random.choice(
        dataset['sources'][event_2]))  # sample source
    action_2 = str(np.random.choice(
        dataset['actions'][event_2]))  # sample action

    question = question.replace('<S1>', source_1)  # insert source
    question = question.replace('<A1>', action_1)  # insert action
    question = question.replace('<S2>', source_2)  # insert source
    question = question.replace('<A2>', action_2)  # insert action
    question = sanitize_question(question)  # correct grammar

    lst_events = get_lst_events(narrative)
    answer = 'yes' if (event_1 in lst_events
                       or event_2 in lst_events) else 'no'

    return question, answer
Пример #28
0
def how_many_sounds_duration_ordinal(dataset, narrative, rel_diff=0.1):
    questions = ['How many [sound events,sounds] [roughly,approximately] as <D> as the <O> sound?',  # noqa: E501
                 'How many [sound events,sounds] that are [roughly,approximately] as <D> as the <O> sound?',  # noqa: E501
                 'How many [sound events,sounds] that are [roughly,approximately] as <D> as the <O> sound [did,could] you [hear,listen to]?',  # noqa: E501
                 'How many [sound events,sounds] that are [roughly,approximately] as <D> as the <O> sound have you heard?',  # noqa: E501
                 'How many [sound events,sounds] that have [roughly,approximately] the same duration as the <O> sound?',  # noqa: E501
                 'How many [sound events,sounds] that have [roughly,approximately] the same duration as the <O> sound [did,could] you [hear,listen to]?',  # noqa: E501
                 'How many [sound events,sounds] that have [roughly,approximately] the same duration as the <O> sound have you heard?',  # noqa: E501
                 'What is the number of [sound events,sounds] [roughly,approximately] as <D> as the <O> sound?',  # noqa: E501
                 'What is the number of [sound events,sounds] that are [roughly,approximately] as <D> as the <O> sound?',  # noqa: E501
                 'What is the number of [sound events,sounds] that are [roughly,approximately] as <D> as the <O> sound [did,could] you [hear,listen to]?',  # noqa: E501
                 'What is the number of [sound events,sounds] that are [roughly,approximately] as <D> as the <O> sound have you heard?',  # noqa: E501
                 'What is the number of [sound events,sounds] that have [roughly,approximately] the same duration as the <O> sound?',  # noqa: E501
                 'What is the number of [sound events,sounds] that have [roughly,approximately] the same duration as the <O> sound [did,could] you [hear,listen to]?',  # noqa: E501
                 'What is the number of [sound events,sounds] that have [roughly,approximately] the same duration as the <O> sound have you heard?',  # noqa: E501
                 ]

    question = str(np.random.choice(questions))  # sample question
    duration = sample_duration()  # sample duration
    lst_events = get_lst_events(narrative)
    number, ordinal = sample_number(len(lst_events))

    question = question.replace('<D>', duration)  # insert duration
    question = question.replace('<O>', ordinal)  # insert ordinal
    question = sanitize_question(question)  # correct grammar

    lst_durations = get_lst_durations(narrative)
    evt_duration = lst_durations[number - 1]
    x_durations = [j for i, j in enumerate(lst_durations) if i != (number - 1)]
    rel_durations_diff = compute_rel_diff(np.array(x_durations),
                                          np.array(evt_duration))
    # Assert a good margin in relative loudness
    assert np.sum(np.logical_and(rel_durations_diff > rel_diff,
                                 rel_durations_diff < (2 * rel_diff))) <= 0, \
        'Question (how_many_sounds_duration_ordinal) illposed.'
    answer = numbers_to_words(np.sum(rel_durations_diff <= rel_diff))

    return question, answer
Пример #29
0
def compare_duration_ordinal(dataset, narrative, rel_diff=0.1):
    questions = [
        'Was the <O1> [sound event,sound] <RD> than the <O2> [sound event,sound]?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the <O1> [sound event,sound] and the <O2> [sound event,sound], was the former <RD>?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the <O1> and <O2> [sound events,sounds], was the former <RD>?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the <O2> [sound event,sound] and the <O1> [sound event,sound], was the latter <RD>?',  # noqa: E501
        '[Comparing,Listening to,Hearing] the <O2> and <O1> [sound events,sounds], was the latter <RD>?',  # noqa: E501
    ]

    question = str(np.random.choice(questions))  # sample question
    lst_events = get_lst_events(narrative)
    number_1, ordinal_1 = sample_number(len(lst_events))
    rel_duration = sample_rel_duration()
    number_2, ordinal_2 = sample_second_number(len(lst_events), number_1)

    assert number_1 != number_2, 'Question (compare_duration_ordinal) illposed.'

    question = question.replace('<O1>', ordinal_1)  # insert ordinal
    question = question.replace('<RD>', rel_duration)  # insert duration
    question = question.replace('<O2>', ordinal_2)  # insert ordinal
    question = sanitize_question(question)  # correct grammar

    lst_duration = get_lst_durations(narrative)
    e_1_duration = lst_duration[number_1 - 1]
    e_2_duration = lst_duration[number_2 - 1]
    # Assert a good margin in relative duration
    rel_duration_diff = compute_rel_diff(np.array(e_1_duration),
                                         np.array(e_2_duration))
    assert np.sum(rel_duration_diff < rel_diff) <= 0, \
        'Question (compare_duration_ordinal) illposed.'
    if 'short' in question:
        answer = 'yes' if e_1_duration < e_2_duration else 'no'
    elif 'long' in question:
        answer = 'yes' if e_1_duration > e_2_duration else 'no'
    else:
        assert False, 'Duration illdefined in Question (compare_duration_ordinal).'

    return question, answer
Пример #30
0
def compare_ordinal_event(dataset, narrative, _):
    questions = [
        'Was the <O> [sound event,sound] [a,an] <S> <A>?',  # noqa: E501
        'Did the <O> [sound event,sound] [sound,seem] like [a,an] <S> <A>?',  # noqa: E501
        '[Listening to,Hearing] the <O> [sound event,sound], was it [a,an] <S> <A>?',  # noqa: E501
        '[Listening to,Hearing] the <O> [sound event,sound], did it [sound,seem] like [a,an] <S> <A>?',  # noqa: E501
    ]

    question = str(np.random.choice(questions))  # sample question
    lst_events = get_lst_events(narrative)
    number, ordinal = sample_number(len(lst_events))
    event = str(np.random.choice(dataset['events']))  # sample event
    source = str(np.random.choice(dataset['sources'][event]))  # sample source
    action = str(np.random.choice(dataset['actions'][event]))  # sample action

    question = question.replace('<O>', ordinal)  # insert ordinal
    question = question.replace('<S>', source)  # insert source
    question = question.replace('<A>', action)  # insert action
    question = sanitize_question(question)  # correct grammar

    answer = 'yes' if lst_events[number - 1] == event else 'no'

    return question, answer