Пример #1
0
    def return_data(idx):
        """
        Return a cleaned-up version of the field content.

        Get the text, remove html, and return the field name, the
        clean text, and what we got when we tried to split into kanji
        and kana, when different from the text.
        """
        text = note[field_names[idx]]
        # This is taken from aqt/browser.py.
        text = text.replace(u'<br>', u' ')
        text = text.replace(u'<br />', u' ')
        if strip_interpunct:
            text = text.replace(u'・', u'')
        text = stripHTML(text)
        text = stripSounds(text)
        # Reformat so we have exactly one space between words.
        text = u' '.join(text.split())
        if not text and not get_empty:
            raise ValueError('Source field empty')
        # We pass the reading/plain on to the update dialog. We don't
        # look at the texts any more to decide what to do. So don't
        # set anything to empty here. Rather do the split even if it
        # is pointless.
        base = furigana.kanji(text)
        ruby = furigana.kana(text)
        return field_names[idx], fname, text, base, ruby, readings
Пример #2
0
    def return_data(idx):
        """
        Return a cleaned-up version of the field content.

        Get the text, remove html, and return the field name, the
        clean text, and what we got when we tried to split into kanji
        and kana, when different from the text.
        """
        text = note[field_names[idx]]
        # This is taken from aqt/browser.py.
        text = text.replace(u'<br>', u' ')
        text = text.replace(u'<br />', u' ')
        if strip_interpunct:
            text = text.replace(u'・', u'')
        text = stripHTML(text)
        text = stripSounds(text)
        # Reformat so we have exactly one space between words.
        text = u' '.join(text.split())
        if not text and not get_empty:
            raise ValueError('Source field empty')
        # We pass the reading/plain on to the update dialog. We don't
        # look at the texts any more to decide what to do. So don't
        # set anything to empty here. Rather do the split even if it
        # is pointless.
        base = furigana.kanji(text)
        ruby = furigana.kana(text)
        return field_names[idx], fname, text, base, ruby, readings
Пример #3
0
def correct_kana(res, right, typed, card):
    try:
        fld = re.search('\[\[type:([^\]]+)\]\]', card.a()).group(1)
    except AttributeError:
        # No typed answer to show at all.
        return res
    if not reading_field in fld.lower() or fld.startswith("cq:"):
        return res
    if not japanese_model in card.model()[u'name'].lower():
        return res
    return _correct(u'', kana(right), typed, card)
Пример #4
0
def correct_kana(reviewer, given, correct, showBad=True, _old=None):
    u"""Filter to compare the typed text to just the kana."""
    try:
        crd = reviewer.card
        fld = re.search(r'\[\[type:([^\]]+)\]\]', crd.a()).group(1)
    except AttributeError:
        # No typed answer to show at all.
        return _old(reviewer, given, correct, showBad)
    if not reading_field in fld.lower() or fld.startswith("cq:"):
        return _old(reviewer, given, correct, showBad)
    if not japanese_model in crd.model()[u'name'].lower():
        return _old(reviewer, given, correct, showBad)
    return _old(reviewer, given, kana(correct), showBad)
Пример #5
0
def correct_kana(reviewer, given, correct, showBad=True, _old=None):
    u"""Filter to compare the typed text to just the kana."""
    try:
        crd = reviewer.card
        fld = re.search(r'\[\[type:([^\]]+)\]\]', crd.a()).group(1)
    except AttributeError:
        # No typed answer to show at all.
        return _old(reviewer, given, correct, showBad)
    if not reading_field in fld.lower() or fld.startswith("cq:"):
        return _old(reviewer, given, correct, showBad)
    if not japanese_model in crd.model()[u'name'].lower():
        return _old(reviewer, given, correct, showBad)
    return _old(reviewer, given, kana(correct), showBad)
Пример #6
0
 def __init__(self, w_field, a_field, word):
     FieldData.__init__(self, w_field, a_field, word)
     self.kanji = furigana.kanji(self.word)
     self.kana = furigana.kana(self.word)
Пример #7
0
 def __init__(self, w_field, a_field, word):
     FieldData.__init__(self, w_field, a_field, word)
     self.kanji = furigana.kanji(self.word)
     self.kana = furigana.kana(self.word)