예제 #1
0
from question_basics import uid, uidInv
from questions.kanjiQuestions import get_kanji

kanji = get_kanji()
kanji_heads = set(q.head for q in kanji)

old_record_copy = (r"C:\Users\Jasper Hugunin\Documents\JapTutor" +
                   r"\Quizzer\recordsCopyBeforeTransition.txt")
new_records = (r"C:\Users\Jasper Hugunin\Documents\JapTutor" +
               r"\Grammar\records\records.txt")
old, new = open(old_record_copy, 'r'), open(new_records, 'w')

def convert(in_file, out_file):
    complex_questions = 0
    pruned_questions = 0
    for line in in_file:
        assert line[-1] == '\n'
        line = line[:-1].split(' ')
        assert len(line) == 5
        if line[0].startswith("vocabKRS") or line[0].startswith("vocabKSR"):
            complex_questions += 1
            continue
        if (line[0].startswith("vocabKS.") and
            uidInv(line[0][8:]) in kanji_heads):
            pruned_questions += 1
            continue
        out_file.write("%s %s %s\n" % (uid(line[0]), line[1], line[3]))
    print("Complex:", complex_questions)
    print("Pruned:", pruned_questions)

convert(old, new)
예제 #2
0
from question_basics import uid, uidInv
from questions.kanjiQuestions import get_kanji

kanji = get_kanji()
kanji_heads = set(q.head for q in kanji)

old_record_copy = (r"C:\Users\Jasper Hugunin\Documents\JapTutor" +
                   r"\Quizzer\recordsCopyBeforeTransition.txt")
new_records = (r"C:\Users\Jasper Hugunin\Documents\JapTutor" +
               r"\Grammar\records\records.txt")
old, new = open(old_record_copy, 'r'), open(new_records, 'w')


def convert(in_file, out_file):
    complex_questions = 0
    pruned_questions = 0
    for line in in_file:
        assert line[-1] == '\n'
        line = line[:-1].split(' ')
        assert len(line) == 5
        if line[0].startswith("vocabKRS") or line[0].startswith("vocabKSR"):
            complex_questions += 1
            continue
        if (line[0].startswith("vocabKS.")
                and uidInv(line[0][8:]) in kanji_heads):
            pruned_questions += 1
            continue
        out_file.write("%s %s %s\n" % (uid(line[0]), line[1], line[3]))
    print("Complex:", complex_questions)
    print("Pruned:", pruned_questions)
예제 #3
0
def get_questions():
    records = get_freq()
    components = get_components()
    kana = kanjiq.get_kana()
    kanji = kanjiq.get_kanji()
    vocab = vocabq.get_vocab()
    grammar_words = grammarq.get_words()
    wordlist = get_wordlist()
    wordlist_rank = {r:i for i, r in enumerate(wordlist)}
    freq_rank = {r.word:r.count for r in records
                 if r.word not in grammarq.grammar_words}
    def rank(word):
        return (-wordlist_rank[word]
                if word in wordlist_rank
                else -len(wordlist),
                freq_rank[word]
                if word in freq_rank
                else 0)
    vocab.sort(key=lambda q:rank(q.head), reverse=True)
    kanji = {q.head:q for q in kanji}
    grammar_words = sorted(grammar_words,
                           key=lambda q:rank(q.primary_translation),
                           reverse=True)
    grammar_words = grammarq.get_grammar(grammar_words)
    grammar_words = {q.primary_translation:(q, concepts)
                     for q, concepts in grammar_words}
    #print("Got materials.")

    used = set()
    questions = []
    def add(q):
        used.add(q)
        questions.append(q)
    def dfs(c):
        if c not in kanji:
            return # skip non-kanji radicals
        if kanji[c] in used:
            return # done, or in progress
        used.add(kanji[c])
        if c in components:
            for c2 in components[c]:
                dfs(c2)
        questions.append(kanji[c])

    for q in kana:
        add(q)
    kana = set(q.head for q in kana)
    for q in vocab:
        if q.head in kanji and isinstance(q, vocabq.VocabKtoSQuestion):
            # prune duplicated kanji and vocabKtoS questions
            for value in q.verifier.values:
                if value not in kanji[q.head].answers:
                    kanji[q.head].answers.append(value)
            continue
        if not all(c in kana or c in kanji
                   for c in kanjiq.iterate_with_yoon(q.head)):
            # Uses characters we don't teach, so skip
            continue
        for c in kanjiq.iterate_with_yoon(q.head):
            if c in kanji:
                dfs(c) # teach kanji and components first
        add(q)
        if (q.head in grammar_words and
            (isinstance(q, vocabq.VocabKtoRQuestion) or
             isinstance(q, vocabq.VocabRtoSQuestion))):
            grammar_question, grammar_concepts = grammar_words[q.head]
            #print("Word", len(questions))
            add(grammar_question)
            for concept in grammar_concepts:
                #print("Concept", len(questions))
                add(concept)
    return questions