Пример #1
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
Пример #2
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
Пример #3
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
Пример #4
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
Пример #5
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
Пример #6
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
Пример #7
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
Пример #8
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
Пример #9
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
Пример #10
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
Пример #11
0
def was_there_similar_duration_ordinal(dataset, narrative, rel_diff=0.1):
    questions = [
        'Were there any sounds [roughly,approximately] as <D> as the <O> sound?',  # noqa: E501
        'Were there any sounds that were [roughly,approximately] as <D> as the <O> sound?',  # noqa: E501
        'Were there any sounds that were [roughly,approximately] the same duration as the <O> sound?',  # noqa: E501
        'Was there any sound [roughly,approximately] as <D> as the <O> sound?',  # noqa: E501
        'Was there any sound that was [roughly,approximately] as <D> as the <O> sound?',  # noqa: E501
        'Was there any sound that was [roughly,approximately] the same duration as the <O> sound?',  # noqa: E501
        'Was there at least a sound [roughly,approximately] as <D> as the <O> sound?',  # noqa: E501
        'Was there at least a sound that was [roughly,approximately] as <D> as the <O> sound?',  # noqa: E501
        'Was there at least a sound that was [roughly,approximately] the same duration as the <O> sound?',  # noqa: E501
        'Was there at least [one,a single] sound that was [roughly,approximately] as <D> as the <O> sound?',  # noqa: E501
        'Was there at least [one,a single] sound [roughly,approximately] as <D> as the <O> sound?',  # noqa: E501
        'Was there at least [one,a single] sound that was [roughly,approximately] the same duration as the <O> sound?',  # 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 duration
    assert np.sum(np.logical_and(rel_durations_diff > rel_diff,
                                 rel_durations_diff < (2 * rel_diff))) <= 0, \
        'Question (was_there_similar_duration_ordinal) illposed.'
    answer = 'yes' if np.sum(rel_durations_diff <= rel_diff) >= 1 else 'no'

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

    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]))
    action = str(np.random.choice(dataset['actions'][event]))
    preposition = sample_preposition()
    lst_events = get_lst_events(narrative)
    number, ordinal = sample_number(len(lst_events))

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

    if 'before' in question:
        assert number > 1, 'Question (how_many_event_relative_ordinal) illposed.'
        lst_events_e = lst_events[:(number - 1)]
    elif 'after' in question:
        assert number < (len(lst_events) - 1), \
            'Question (how_many_event_relative_ordinal) illposed.'
        lst_events_e = lst_events[number:]
    else:
        assert False, \
            'Relative preposition illdefined in Question (how_many_event_relative_ordinal).'   # noqa: E501
    answer = numbers_to_words(lst_events_e.count(event))

    return question, answer