diff --git a/umbra/model.py b/umbra/model.py index 288ba80128a4086d17422e28c1f7bb0590a09e14..c87e19116f3ae0213a3dbb560e76594e426450e8 100644 --- a/umbra/model.py +++ b/umbra/model.py @@ -36,6 +36,7 @@ class Model: for trial in self._shadow_tasks: self._stats.analyze(trial) self._analysed = True + self.create_delay_frame() def add_task(self, pnr, vnr, condition, source, shadow): """ Add a task specifying all the necessary information @@ -50,7 +51,23 @@ class Model: self._shadow_tasks.append( ShadowTask(pnr, vnr, condition, source, shadow)) - def create_output_frame(self): + def create_delay_frame(self): + delay_frame = ({'participant': [], + 'assignment': [], + 'video': [], + 'words': [], + 'delays': []}) + for trial in self._shadow_tasks: + for result in trial.delays: + delay_frame['participant'].append(result[0]) + delay_frame['assignment'].append(result[1]) + delay_frame['video'].append(result[2]) + delay_frame['words'].append(result[3]) + delay_frame['delays'].append(result[4]) + + return pd.DataFrame(data=delay_frame) + + def create_mistake_frame(self): """ Create the frame for the output Returns: diff --git a/umbra/needleman_wunsch.py b/umbra/needleman_wunsch.py index c910c882cf89ee185e234bbadb2cd1718caf07fa..b7a333fef14736ced43d71fe42ea36c19d7f7b2a 100644 --- a/umbra/needleman_wunsch.py +++ b/umbra/needleman_wunsch.py @@ -187,14 +187,16 @@ class NeedlemanWunsch(AlignmentStrategy): if source == shadow: source.shadowed = True shadow.correct = True - shadow.source = source + source.shadow = shadow elif self._seman_checker.semantically_related(source.word, shadow.word): source.shadowed = True source.mistake = Mistake.SEMANTIC shadow.mistake = Mistake.SEMANTIC + source.shadow = shadow elif self._form_checker.form_related(source.word, shadow.word): source.shadowed = True + source.shadow = shadow source.mistake = Mistake.FORM shadow.mistake = Mistake.FORM return source, shadow diff --git a/umbra/shadow_task.py b/umbra/shadow_task.py index be1b57f73d94215b3da4f1f2ebc42e29b04d298d..892df0773880d63284c3eda04a6dbb9f94d91791 100644 --- a/umbra/shadow_task.py +++ b/umbra/shadow_task.py @@ -10,6 +10,7 @@ class ShadowTask: self._source = source self._shadow = shadow self._results = None + self._delays = None @property def participant(self): @@ -39,6 +40,14 @@ class ShadowTask: def results(self, results): self._results = results + @property + def delays(self): + return self._delays + + @delays.setter + def delays(self, delays): + self._delays = delays + def __str__(self): return "participant: %s video: %s condition: %s " \ "result: %s" % (self._participant, self._video, diff --git a/umbra/statistics.py b/umbra/statistics.py index c27b0d949922caa304c34e88683a5db99ad8871b..2c3814d027740b6baa7276ed15fe695c68925f9a 100644 --- a/umbra/statistics.py +++ b/umbra/statistics.py @@ -60,9 +60,6 @@ class Statistics: self._strategy = NeedlemanWunsch(self._seman_checker, self._form_checker) source_align, shadow_align = self._strategy.align(source, shadow) - for s_word in shadow_align: - if s_word.has_source(): - results += f'source: {s_word.source} shadow: {s_word}\n' correctness = self._strategy.correctly_shadowed(source) discrete_time = time.time() - discrete_start_time results += f'taken time:{discrete_time}\n' @@ -75,9 +72,6 @@ class Statistics: self._strategy = AnchorAlgorithm() source_align_em, shadow_align_em = self._strategy.align(source_em, shadow_em) - for s_word in shadow_align_em: - if s_word.has_source(): - results += f'source: {s_word.source} shadow: {s_word}\n' correctness = self._strategy.correctly_shadowed(source_em) self._mistake_finder.start(source_align_em, shadow_align_em) discrete_time = time.time() - discrete_start_time @@ -87,4 +81,12 @@ class Statistics: trial.results = self._mistake_counter.\ calculate_accuracy(source_em, shadow_em) + delays_per_word = [] + for source_word in source: + if source_word.has_shadow(): + delays_per_word.append([trial.participant, trial.condition, + trial.video, source_word.word, + source_word.get_difference + (source_word.shadow)]) + trial.delays = delays_per_word return correctness diff --git a/umbra/words.py b/umbra/words.py index 4ebd26686d92ac416c016af57ba3cdb7378f724d..5208f9733a8c28769290ea6e08f64574716ad0bb 100644 --- a/umbra/words.py +++ b/umbra/words.py @@ -98,14 +98,6 @@ class Word: """Anchor setter. Has to be overridden in the subclass.""" raise NotImplementedError - def get_difference(self, other): - """Get the difference between the onset of this word and the other. - - Args: - other: the other Word instance - """ - return other.onset - self._onset - class ShadowWord(Word): def __init__(self, word, onset, offset): @@ -177,6 +169,7 @@ class SourceWord(Word): def __init__(self, word, onset, offset): super().__init__(word, onset, offset) self._shadowed = False + self._shadow = None @property def shadowed(self): @@ -208,6 +201,39 @@ class SourceWord(Word): def _set_anchor(self, anchor): self._anchor = anchor + @property + def shadow(self): + """Getter for Shadow attribute + + Return: + The shadow word. + """ + return self._shadow + + @shadow.setter + def shadow(self, shadow): + """Setter for Source attribute + + Args: + shadow: the source word, presumably of type Word. + """ + self._shadow = shadow + + def has_shadow(self): + """Check whether this word has a shadow word that it is matched with + + Returns: + shadow: True if this word is matched, False otherwise. + """ + return self._shadow is not None + + def get_difference(self, other): + """Get the difference between the onset of this word and the other. + + Args: + other: the other Word instance + """ + return other.onset - self._onset class Sentence(list): def __init__(self, words):