changing the way sense editing works, now general

This commit is contained in:
2019-11-13 23:20:34 +01:00
parent b7b91fa6d6
commit daa56ba7ac
6 changed files with 33 additions and 13 deletions

25
src/model/editable.py Normal file
View File

@@ -0,0 +1,25 @@
class Editable:
def make_copy(self):
# delete old copy
if hasattr(self, "_copy"):
if self._copy is not None:
self._copy = None
# make new copy
self._copy = JSON.parse(JSON.stringify(self))
def copy(self):
# check if even initialized
if hasattr(self, "_copy"):
return self._copy
else:
return None
def overwrite_with_copy(self):
for key, value in dict(self._copy).items():
if key == "_copy":
continue
setattr(self, key, value)
self._copy = None

View File

@@ -1,8 +1,9 @@
from model.example import Example
from model.translation import Translation
from model.editable import Editable
class Sense:
class Sense(Editable):
def __init__(self, sense_xml):
definition = sense_xml.querySelector("definitionList definition")
@@ -23,7 +24,4 @@ class Sense:
self.translations = [[] for _ in range(max_num_cluster)]
for clusterNum, translation in translations:
self.translations[clusterNum - 1].append(translation)
# useful for editing
self.temporary_labels = None