changing the way sense editing works, now general
This commit is contained in:
25
src/model/editable.py
Normal file
25
src/model/editable.py
Normal 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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user