Skip to content
Snippets Groups Projects
Commit 903ce6b1 authored by Vriezen, E.C. (Emma)'s avatar Vriezen, E.C. (Emma)
Browse files

Added the mistake_enum.py (Enum for the type of mistakes, to mark words with)...

Added the mistake_enum.py (Enum for the type of mistakes, to mark words with) and added mistake properties/getters/setters in words.py.
parent 640940b9
No related branches found
No related tags found
1 merge request!44Emmas edits to master
from enum import Enum
class NoValue(Enum):
"""Enum class for which the value is not important. The __repr__ hides
the unimportant value, when a NoValue Enum is printed.
"""
def __repr__(self):
return '<%s.%s>' % (self.__class__.__name__, self.name)
class Mistake(Enum):
"""Enum for all types of mistakes that can be made in the shadow task."""
PHONETIC = "phonetic"
REPETITION = "repetition"
SEMANTIC = "semantic"
SKIPPED = "skipped" # For source words that are not shadowed
RANDOM = "random" # For shadow words that do not reflect a source word
from mistake_enum import Mistake
class Word:
def __init__(self, word, onset, offset):
self._word = word
self._onset = onset
self._offset = offset
self._anchor = None
self._mistake = None
def __str__(self):
return "%s | %f | %f" % (self._word, self._onset, self._offset)
......@@ -14,7 +18,6 @@ class Word:
def __eq__(self, word):
return self._word == word.word
@property
def word(self):
"""Getter for the word.
......@@ -51,6 +54,29 @@ class Word:
"""
return self._anchor
@property
def mistake(self):
"""Getter for the mistake.
Return:
mistake: Enum of the type of mistake that this word is. None if
not marked as a mistake.
"""
return self._mistake
@mistake.setter
def mistake(self, mistake):
"""Setter for the type of mistake.
Args:
mistake: Mistake Enum
"""
self._set_mistake(mistake)
def _set_mistake(self, mistake):
"""Mistake setter. Has to be overridden in the subclass."""
raise NotImplementedError
def is_anchor(self):
"""Whether this word is a anchor or not.
......@@ -61,7 +87,7 @@ class Word:
@anchor.setter
def anchor(self, anchor):
""" Anchor this Word object to another Word object.
"""Anchor this Word object to another Word object.
Args:
anchor: Word instance to anchor to
......@@ -127,6 +153,18 @@ class ShadowWord(Word):
"""
return self._source is not None
def _set_mistake(self, mistake):
"""Setter for the type of mistake. Only works if the word is not marked
as correct yet and if mistake is not SKIPPED.
Args:
mistake: Mistake Enum
"""
assert self._correct is False
assert mistake != Mistake.SKIPPED
self._mistake(mistake)
class SourceWord(Word):
def __init__(self, word, onset, offset):
super().__init__(word, onset, offset)
......@@ -150,6 +188,15 @@ class SourceWord(Word):
"""
self._shadowed = value
def _set_mistake(self, mistake):
"""Setter for the type of mistake. Only works if mistake is not RANDOM.
Args:
mistake: Mistake Enum
"""
assert mistake != Mistake.RANDOM
self._mistake(mistake)
class Sentence(list):
def __init__(self, words):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment