Beispiel #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
Beispiel #2
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
Beispiel #3
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
Beispiel #4
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
Beispiel #5
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
Beispiel #6
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
Beispiel #7
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
Beispiel #8
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
Beispiel #9
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
Beispiel #10
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
Beispiel #11
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
Beispiel #12
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
Beispiel #13
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