Beispiel #1
0
 def setUp(self):
     self.pairs = [
         (TimedAction('action_1', .1, .2), [
             TimedUtterance('blah blah', .0, .05),
             TimedUtterance('blah again', .06, .07)
         ]),
         (TimedAction('action_2', .3,
                      .4), [TimedUtterance('do action2', .25, .3)]),
         (TimedAction('action_3', .6,
                      .8), [TimedUtterance('nonsense', .25, .3)]),
     ]
     self.trial = Trial('A', self.pairs, .0)
Beispiel #2
0
 def setUp(self):
     self.pairs1 = [
         (TimedAction('action_1', .1, .2), [
             TimedUtterance('blah blah', .0, .05),
             TimedUtterance('blah again', .06, .07)
         ]),
         (TimedAction('action_2', .3,
                      .4), [TimedUtterance('do action2', .25, .3)]),
     ]
     self.pairs2 = [(TimedAction('action_3', 1.6, 1.8),
                     [TimedUtterance('nonsense', 1.25, 1.3)])]
     self.session = Session(
         [Trial('B', self.pairs1, .0),
          Trial('A', self.pairs2, 1.)])
 def setUp(self):
     self.pairs1 = [
         (TimedAction('a', .1, .2), []),
         (TimedAction('b', .3, .4), []),
         (TimedAction('c', .3, .4), []),
     ]
     self.pairs2 = [
         (TimedAction('c', 1.6, 1.8), []),
         (TimedAction('b', .3, .4), []),
         (TimedAction('a', .3, .4), []),
     ]
     self.trial1 = Trial('B', self.pairs1, .0)
     self.trial2 = Trial('A', self.pairs2, 1.)
     self.td = TrainData(
         OrderedDict([('P1', Session([self.trial1])),
                      ('P2', Session([self.trial2]))]))
Beispiel #4
0
 def setUp(self):
     self.pairs1 = [
         (TimedAction('action_1', .1, .2), [
             TimedUtterance('blah blah', .0, .05),
             TimedUtterance('blah again', .06, .07)
         ]),
         (TimedAction('action_2', .3,
                      .4), [TimedUtterance('do action2', .25, .3)]),
     ]
     self.pairs2 = [(TimedAction('action_3', 1.6, 1.8),
                     [TimedUtterance('nonsense', 1.25, 1.3)])]
     self.pairs3 = [(TimedAction('action_1', .2, .3),
                     [TimedUtterance('Hello robot', .1, .13)])]
     self.trial1 = Trial('B', self.pairs1, .0)
     self.trial2 = Trial('A', self.pairs2, 1.)
     self.trial3 = Trial('A', self.pairs3, 4.)
     self.td = TrainData(
         OrderedDict([('P1', Session([self.trial1, self.trial2])),
                      ('P2', Session([self.trial3]))]))
Beispiel #5
0
def rename_wrong_actions_in_first_sessions(data):
    """front_2 | foot_5 -> front_3"""
    def rename(action):
        l, ts, te = action
        if l in ('front_2', 'foot_5'):
            return ('front_3', ts, te)
        else:
            return action

    def rename_pair(action, utterances):
        return rename(action), utterances

    # Participants with errors in labels
    participants = [p for p in PARTICIPANTS if int(p.split('.')[0]) < 10]
    for participant in participants:
        data.data[participant] = Session([
            Trial(t.instruction, [rename_pair(*pair)
                                  for pair in t.pairs], t.initial_time)
            for t in data.data[participant]
        ])
Beispiel #6
0
def merge_duplicate_in_8(data):
    # BBC -> BC
    P8 = '8.BCA'
    session = data.data[P8]
    if session[0].instruction != 'B' or session[1].instruction != 'B':
        raise ValueError("Unexpected data.")
    delta = session[1].initial_time - session[0].initial_time

    def update_times(x, ts, te):
        return (x, ts + delta, te + delta)

    # Add time difference to actions and utterances in second bag
    new_pairs = [(update_times(*action),
                  [update_times(*u) for u in utterances])
                 for action, utterances in session[1].pairs]
    # Merge two first bags
    data.data[P8] = Session([
        Trial('B', session[0].pairs + new_pairs, session[0].initial_time),
        session[2]
    ])
Beispiel #7
0
def participant_to_session(path, participant, instructions):
    trials = []
    bags = participant_bags(path, participant)
    for b, instr in zip(bags, instructions):
        print('\nLoading: {} ({}: {})'.format(participant, instr,
                                              os.path.split(b.filename)[-1]))
        pairer = parse_bag(b)
        pairs = list(pairer.get_associations())
        trials.append(
            Trial(instruction=instr,
                  pairs=pairs,
                  initial_time=b.get_start_time()))
        print("Total: {} actions found with {} non-empty utterances.".format(
            len(pairs), sum([len(u) > 0 for a, u in pairs])))
    try:
        next(bags)
    except StopIteration:
        pass
    else:
        raise ValueError('Too many bag files for {} (expected {})'.format(
            participant, len(bags)))
    return Session(trials)
Beispiel #8
0
class TestTrial(TestCase):
    def setUp(self):
        self.pairs = [
            (TimedAction('action_1', .1, .2), [
                TimedUtterance('blah blah', .0, .05),
                TimedUtterance('blah again', .06, .07)
            ]),
            (TimedAction('action_2', .3,
                         .4), [TimedUtterance('do action2', .25, .3)]),
            (TimedAction('action_3', .6,
                         .8), [TimedUtterance('nonsense', .25, .3)]),
        ]
        self.trial = Trial('A', self.pairs, .0)

    def test_n_samples(self):
        self.assertEqual(self.trial.n_samples, 3)

    def test_utterances(self):
        utterances = ['blah blah blah again', 'do action2', 'nonsense']
        self.assertEqual(self.trial.utterances, utterances)

    def test_labels(self):
        self.assertEqual(self.trial.labels,
                         ['action_1', 'action_2', 'action_3'])

    def test_first_id_not_set(self):
        with self.assertRaises(ValueError):
            self.trial.first_id

    def test_first_id(self):
        self.trial.set_first_id(5)
        self.assertEqual(self.trial.first_id, 5)

    def test_ids(self):
        self.trial.set_first_id(5)
        self.assertEqual(self.trial.ids, [5, 6, 7])

    def test_get_pair_from_id(self):
        self.trial.set_first_id(5)
        self.assertEqual(self.trial.get_pair_from_id(6), self.pairs[1])
Beispiel #9
0
def _pairs_to_trial(pairs, name):
    return Trial(name, [((a, 0., 0.), [(u, 0., 0.) for u in uu])
                        for a, uu in pairs], 0.)