def get_word_question(self, partial_lexeme, user): "See parent." try: surface = partial_lexeme.random_kanji_surface except ObjectDoesNotExist: raise plugin_api.UnsupportedItem(partial_lexeme) answer = partial_lexeme.reading_set.all().order_by('?')[0].reading question = self.build_question(pivot=surface, pivot_type='w', pivot_id=partial_lexeme.id, stimulus=surface, annotation=u'|'.join(surface)) segments = list(surface) # [339] Include homographs in real reading set real_readings = set([ r.reading for r in lexicon_models.LexemeReading.objects.filter( lexeme__surface_set__surface=surface) ]) error_dist = usermodel_models.ErrorDist.objects.get(user=user, tag=self.uses_dist) distractor_values, annotation_map = support.build_word_options( segments, error_dist, adaptive=self.is_adaptive, exclude_set=real_readings) annotation_map[answer] = u'|'.join(answer) question.add_options(distractor_values, answer, annotation_map) return question
def get_word_question(self, partial_lexeme, user): lexeme = partial_lexeme.lexeme try: surface = partial_lexeme.random_kanji_surface except ObjectDoesNotExist: raise plugin_api.UnsupportedItem(partial_lexeme) # Assume the first sense is the most frequent gloss = lexeme.sense_set.get(is_first_sense=True).gloss error_dist = user.errordist_set.get(tag=self.uses_dist) distractors, _annotations = support.build_word_options(list(surface), error_dist, exclude_set=set([surface])) question = self.build_question(pivot=surface, pivot_id=partial_lexeme.id, pivot_type="w", stimulus=gloss) question.add_options(distractors, surface) return question
def get_word_question(self, partial_lexeme, user): lexeme = partial_lexeme.lexeme try: surface = partial_lexeme.random_kanji_surface except ObjectDoesNotExist: raise plugin_api.UnsupportedItem(partial_lexeme) # Assume the first sense is the most frequent gloss = lexeme.sense_set.get(is_first_sense=True).gloss error_dist = user.errordist_set.get(tag=self.uses_dist) distractors, _annotations = support.build_word_options(list(surface), error_dist, exclude_set=set( [surface])) question = self.build_question(pivot=surface, pivot_id=partial_lexeme.id, pivot_type='w', stimulus=gloss) question.add_options(distractors, surface) return question
def get_word_question(self, partial_lexeme, user): "See parent." try: surface = partial_lexeme.random_kanji_surface except ObjectDoesNotExist: raise plugin_api.UnsupportedItem(partial_lexeme) answer = partial_lexeme.reading_set.all().order_by("?")[0].reading question = self.build_question( pivot=surface, pivot_type="w", pivot_id=partial_lexeme.id, stimulus=surface, annotation=u"|".join(surface) ) segments = list(surface) # [339] Include homographs in real reading set real_readings = set( [r.reading for r in lexicon_models.LexemeReading.objects.filter(lexeme__surface_set__surface=surface)] ) error_dist = usermodel_models.ErrorDist.objects.get(user=user, tag=self.uses_dist) distractor_values, annotation_map = support.build_word_options( segments, error_dist, adaptive=self.is_adaptive, exclude_set=real_readings ) annotation_map[answer] = u"|".join(answer) question.add_options(distractor_values, answer, annotation_map) return question
def _add_distractors(self, question, user): """ Builds distractors for the question with appropriate annotations so that we can easily update the error model afterwards. Note that the segments used here are simplistic, one per character, since the richer GP segments need not be supported by this error distribution. """ error_dist = user.errordist_set.get(tag=self.uses_dist) pivot = question.pivot segments = list(pivot) # Simple segments if question.pivot_type == 'w': distractors, annotation_map = support.build_word_options( segments, error_dist, exclude_set=set([pivot])) else: distractors, annotation_map = support.build_kanji_options( question.pivot, error_dist, exclude_set=set([pivot])) annotation_map[pivot] = u'|'.join(segments) question.add_options(distractors, question.pivot, annotation_map=annotation_map) question.annotation = u'|'.join(segments) question.save() return
def get_word_question(self, partial_lexeme, user): "See parent." try: alignment = partial_lexeme.alignments.order_by('?')[0] except IndexError: raise drill_api.UnsupportedItem(partial_lexeme) error_dist = usermodel_models.ErrorDist.objects.get(user=user, tag=self.uses_dist) surface = alignment.surface.surface # [339] Include homographs in real reading set exclude_set = set([ r.reading for r in lexicon_models.LexemeReading.objects.filter( lexeme__surface_set__surface=surface) ]) answer_reading = alignment.reading.reading pivot = alignment.surface.surface assert answer_reading in exclude_set question = self.build_question( pivot=pivot, pivot_id=partial_lexeme.id, pivot_type='w', stimulus=surface, ) alignment_obj = alignment.alignment_obj distractors, annotation_map = support.build_word_options( alignment_obj.g_segs, error_dist, exclude_set=exclude_set) annotation_map[answer_reading] = u'|'.join(alignment_obj.p_segs) question.add_options(distractors, answer_reading, annotation_map=annotation_map) question.annotation = u'|'.join(alignment_obj.g_segs) question.save() return question