def __init__(self, word): self.word = Word(word) self.total_score = 0.0 self.senses_profiles = [] for sense in self.word: self.senses_profiles.append(SenseProfile(sense, self)) self.n = len(self.senses_profiles)
class WordProfile: # Word profile is made up of all the word senses # Each sense has an individual score associated with it # There's an overall word score as well def __init__(self, word): self.word = Word(word) self.total_score = 0.0 self.senses_profiles = [] for sense in self.word: self.senses_profiles.append(SenseProfile(sense, self)) self.n = len(self.senses_profiles) # Makes the WordProfile iterable def __iter__(self): return self.senses_profiles.__iter__() def __next__(self): return self.senses_profiles.__next__() def __eq__(self, other): return self.word.word == self.other.word and self.word.cefr == self.other.cefr def __hash__(self): return self.word.__hash__() def __repr__(self): result = "" result += "The word profile for {} is {:.4f}: \n\t".format(self.word, self.total_score) for sense_profile in self.senses_profiles: result += str(sense_profile) + '\n\t' return result # Total Score is the average of all sense scores def update_score(self): self.total_score = (sum([x.score for x in self.senses_profiles])/self.n)