Пример #1
0
def recite(button):
    # TODO: randomly select unique Snippet
    # TODO: show reference
    # TODO: if practice, show contents
    global g_verse
    g_verse = Snippet.random()

    verse.set_text(g_verse.contents)
    reference.set_text(g_verse.reference)

    user_input.set_edit_text(u"")
Пример #2
0
import urwid
from difflib import SequenceMatcher

from snippet import Snippet

g_verse = None  # placeholder for currently selected verse
g_verse = Snippet.random()


def do_diff(text, n_text):
    seqm = SequenceMatcher(None, text, n_text)
    output_orig = []
    output_new = []
    for opcode, a0, a1, b0, b1 in seqm.get_opcodes():
        orig_seq = seqm.a[a0:a1]
        new_seq = seqm.b[b0:b1]
        if opcode == 'equal':
            output_orig.append(orig_seq)
            output_new.append(orig_seq)
        elif opcode == 'insert':
            output_new.append(('extra_text', new_seq))
        elif opcode == 'delete':
            output_orig.append(('missing_text', orig_seq))
        elif opcode == 'replace':
            output_new.append(('wrong_text', new_seq))
            output_orig.append(('wrong_text', orig_seq))
        else:
            raise ('Error')
    return output_orig, output_new, seqm.quick_ratio()