Skip to content

Commit

Permalink
Fix for #621
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmackie committed Dec 5, 2016
1 parent 0152bb0 commit 0122ec8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
10 changes: 8 additions & 2 deletions corpustools/corpus/classes/lexicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,11 @@ def update(self, old_word):
else:
setattr(self, attribute, default_value)

if hasattr(old_word, 'wordtokens'):
self.wordtokens = list()
for wt in old_word.wordtokens:
self.wordtokens.append(copy.copy(wt))

self.descriptors.extend([att for att in Word.word_attributes if not att.startswith('_')])
self.descriptors = list(set(self.descriptors))

Expand Down Expand Up @@ -2088,8 +2093,9 @@ def __iadd__(self, other):
sw.frequency += w.frequency
for a in self.attributes:
if getattr(sw, a.name) == a.default_value and getattr(w, a.name) != a.default_value:
setattr(sw, a.name, getattr(w, a.name))
sw.wordtokens += w.wordtokens
setattr(sw, a.name, copy.copy(getattr(w, a.name)))
for wt in w.wordtokens:
sw.wordtokens.append(copy.copy(wt))
except KeyError:
self.add_word(copy.copy(w))
if self.specifier is None and other.specifier is not None:
Expand Down
24 changes: 23 additions & 1 deletion corpustools/corpus/classes/spontaneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def keys(self):
def __len__(self):
return len(self.words.keys())


def __eq__(self, other):
if not isinstance(other,Discourse):
return False
Expand Down Expand Up @@ -426,7 +427,14 @@ class WordToken():
"""
def __init__(self,**kwargs):
wordtoken_attributes = {'wordtype': None, 'discourse': None, 'speaker': None, 'wavpath': None, 'begin': None,
'end': None, '_spelling': None, '_transcription': None, '_freq_names': None}
def __init__(self,update=False,**kwargs):

if update:
self.update(update)
return

self.wordtype = kwargs.pop('word',None)
self.discourse = None
self.speaker = None
Expand Down Expand Up @@ -493,6 +501,20 @@ def __init__(self,**kwargs):
else:
self._spelling = None

def __copy__(self):
return WordToken(update=self)

def update(self, old_token):

for attribute, value in old_token.__dict__.items():
if not hasattr(self, attribute):
setattr(self, attribute, value)

for attribute, default_value in WordToken.wordtoken_attributes.items():
if hasattr(old_token, attribute):
setattr(self, attribute, getattr(old_token, attribute))
else:
setattr(self, attribute, default_value)

def __getstate__(self):
state = self.__dict__.copy()
Expand Down

0 comments on commit 0122ec8

Please sign in to comment.