Exemplo n.º 1
0
def pickSimilarKana(kana):
    row, col = getRowAndCol(kana)
    while True:
        newCol = weightedSample(range(5), lambda c: 5 - abs(min(col - c, col + 5 - c)), 1)[0]
        newKana = Hiraganas[row * 5 + newCol]
        if row in [1, 2, 3, 4, 5, 6, 8, 9 ,10]:
            # TO-DO: 增加選擇清濁的功能
            pass
        if newKana in 'ゃゅょっんを':
            continue
        return newKana
Exemplo n.º 2
0
def generateKanaQuestion(word):
    candidates = []
    for w in Word.objects.all():
        length = len(getLcs(word.kana, w.kana))
        if min(len(word.kana) - 1, 1) <= length < len(word.kana):
            candidates.append([w, length])
    candidateFilter = list(filter(lambda e: e[1] / len(e[0].kana) > 0.4, candidates))
    if len(candidateFilter) > 0:
        candidates = candidateFilter
    options = [word] + [e[0] for e in weightedSample(candidates, lambda e: e[1], 5)]
    random.shuffle(options)
    for i in range(len(options)):
        if options[i] == word:
            return { 'options': options, 'answer': i }