def test_prefill(self): # make sure the correct number of pronouns is there.. assert self.pdm.pronoun_set.count() == len(PronounType._generate_all_combinations()) # check the pronouns themselves... for comb in PronounType._generate_all_combinations(): queryset = Pronoun.objects.filter(pronountype=comb) assert len(queryset) == 1, 'Got {0} not one'.format(len(queryset))
def test_prefill(self): # make sure the correct number of pronouns is there.. combs = PronounType._generate_all_combinations() assert self.pdm.pronoun_set.count() == len(combs) # check the pronouns themselves... for comb in PronounType._generate_all_combinations(): count = Pronoun.objects.filter(pronountype=comb).count() assert count == 1, 'Got %d not one' % count
def test_partial_prefill(self): # create new pdm pdm = Paradigm.objects.create( language=self.lang, source=self.source, editor=self.editor, comment="test_partial_prefill" ) pdm._prefill_pronouns() # we should have a full complement. combs = PronounType._generate_all_combinations() assert pdm.pronoun_set.count() == len(combs) # Let's delete some... for pron in pdm.pronoun_set.all(): if pron.pronountype.person == '2': pron.delete() else: # modify the stored entries so we can identify them later. pron.entries.add(Lexicon.objects.create( editor=self.editor, source=self.source, language=self.lang, word=self.word, entry="old" )) pron.save() # how many should we have deleted combs = PronounType._generate_all_combinations() missing = [_ for _ in combs if _.person == '2'] assert len(missing) == 1 assert pdm.pronoun_set.count() == (len(combs) - len(missing)) # re-run prefill pdm._prefill_pronouns() # we should now have a full complement again. combs = PronounType._generate_all_combinations() assert pdm.pronoun_set.count() == len(combs) for pron in pdm.pronoun_set.all(): if pron.pronountype.person == '2': assert pron.entries.count() == 0 else: assert pron.entries.count() == 1 assert pron.entries.all()[0].entry == 'old'
def test_paradigm_creates_pronouns(self): count = Pronoun.objects.count() response = self.client.post(self.url, { 'language': self.lang.id, 'source': self.source.id, 'comment': 'foo' }, follow=True) self.assertEqual(Pronoun.objects.count(), count+len(PronounType._generate_all_combinations()))
def handle(self, *args, **options): pdm = Paradigm.objects.get(pk=args[0]) pf = PronounFinder() labels = [short_repr_row(p) for p in PronounType._generate_all_combinations()] data = {} for p1 in pdm.pronoun_set.all(): p1_id = short_repr_row(p1) for p2 in pdm.pronoun_set.all(): p2_id = short_repr_row(p2) data[(p1_id, p2_id)] = pf.compare(p1.form, p2.form) rows = [] for p1 in labels: row = [] for p2 in labels: row.append(data.get((p1,p2), 0.0)) rows.append(row) data = np.array(rows) # start plotting fig, axes = plt.subplots() heatmap = axes.pcolor(data, cmap=plt.cm.Blues) # put the major ticks at the middle of each cell axes.set_xticks(np.arange(data.shape[0])+0.5, minor=False) axes.set_yticks(np.arange(data.shape[1])+0.5, minor=False) # want a more natural, table-like display axes.invert_yaxis() # set labels axes.set_xticklabels(labels, minor=False, rotation=90, fontsize=5) axes.set_yticklabels(labels, minor=False, fontsize=5) plt.tick_params(direction="out") plt.tick_params(right="off") plt.tick_params(top="off") plt.suptitle(pdm.language) plt.savefig("%s-%d.png" % (pdm.language.slug, pdm.id)) print("Written to %s-%d.png" % (pdm.language.slug, pdm.id)) cols = ['-'] cols.extend(labels) x = PrettyTable(cols) for i, row in enumerate(data): row = row.round(3) newrow = [labels[i]] for r in row: newrow.append(round(r, 3)) x.add_row(newrow) with open("%s-%d.txt" % (pdm.language.slug, pdm.id), 'w+') as handle: handle.write(x.get_string()) print("Written to %s-%d.txt" % (pdm.language.slug, pdm.id))
def test_paradigm_create(self): pdm = Paradigm.objects.create(language=self.lang, source=self.source, editor=self.editor, comment="test") pdm._prefill_pronouns() # make sure the correct number of pronouns is there.. assert pdm.pronoun_set.count() == 2 # check the pronouns themselves... for comb in PronounType._generate_all_combinations(): queryset = Pronoun.objects.filter(pronountype=comb) assert len(queryset) == 1, 'Got {0} not one'.format(len(queryset))
def handle(self, *args, **options): pdm = Paradigm.objects.get(pk=args[0]) pf = PronounFinder() labels = [short_repr_row(p) for p in PronounType._generate_all_combinations()] data = {} for p1 in pdm.pronoun_set.all(): p1_id = short_repr_row(p1) for p2 in pdm.pronoun_set.all(): p2_id = short_repr_row(p2) if len(p1.form) == 0 or len(p2.form) == 0: continue part1 = u"%s (%s)" % (p1_id, p1.form) part2 = u"%s (%s)" % (p2_id, p2.form) print part1.ljust(20), '::', part2.ljust(20), "%0.2f" % pf.compare(p1.form, p2.form)
def test_partial_prefill(self): # we should have a full complement. assert self.pdm.pronoun_set.count() == len(PronounType._generate_all_combinations()) # Let's delete some... for pron in self.pdm.pronoun_set.all(): if pron.pronountype.person == '2': pron.delete() else: # modify the stored entries so we can identify them later. pron.entries.add(Lexicon.objects.create( editor=self.editor, source=self.source, language=self.lang, word=self.word, entry="old" )) pron.save() # how many should we have deleted missing = [_ for _ in PronounType ._generate_all_combinations() if _.person == '2'] assert len(missing) == 1 assert self.pdm.pronoun_set.count() == (len(PronounType._generate_all_combinations()) - len(missing)) # re-run prefill self.pdm._prefill_pronouns() # we should now have a full complement again. assert self.pdm.pronoun_set.count() == len(PronounType._generate_all_combinations()) for pron in self.pdm.pronoun_set.all(): if pron.pronountype.person == '2': assert pron.entries.count() == 0 else: assert pron.entries.count() == 1 assert pron.entries.all()[0].entry == 'old'
def test_no_errors(self): for row in PronounType._generate_all_combinations(): full_repr_row(row)
def test_generate_all_combinations(self): combinations = PronounType._generate_all_combinations() assert combinations[0] == PronounType.objects.filter(person=1).get() assert combinations[1] == PronounType.objects.filter(person=3).get()
def test_generate_all_combinations(self): combinations = PronounType._generate_all_combinations() assert combinations[0] == PronounType.objects.filter(person=1).get() assert combinations[1] == PronounType.objects.filter(person=2).get() assert combinations[2] == PronounType.objects.filter(person=3).get()