Example #1
0
def distribution_of_improvement(patterns,
                                base_patterns=ortho_matching.default_patterns,
                                n=5,
                                removed=False):
    ignore_n = 200
    consider_n = 10000
    top_effects = []
    total_freq = 0
    total_effect = 0
    for freq, word in freqs[ignore_n:ignore_n + consider_n]:
        base_result = ortho_matching.match_text(word.upper(),
                                                patterns=base_patterns)
        result = ortho_matching.match_text(word.upper(), patterns=patterns)
        if result is not None and base_result is not None:
            if removed:
                effect_size = (len(result) - len(base_result)) * freq
            else:
                effect_size = (len(base_result) - len(result)) * freq
            if effect_size < 0:
                effect_size = 0
            if len(top_effects) < n:
                top_effects.append((effect_size, freq, word))
            elif effect_size > top_effects[0][0]:
                top_effects[0] = (effect_size, freq, word)
                top_effects.sort()
            total_effect += effect_size
            total_freq += freq
    improvements = []
    for effect_size, freq, word in top_effects:
        improvements.append(float(total_effect) / total_freq)
        total_effect -= effect_size
        total_freq -= freq
    words = [w for e, f, w in top_effects]
    return improvements, words
Example #2
0
def get_avg_strokes(patterns=ortho_matching.default_patterns,
                    assume_one_n=200):
    consider_n = 10000
    count = 0
    l_count = 0
    index = 0
    total_count = 0
    fail_count = 0
    for freq, word in freqs[:consider_n]:
        result = ortho_matching.match_text(word.upper(), patterns=patterns)
        old_strokes = ortho_matching.match_text(word.upper())
        if old_strokes is not None:
            for chord in old_strokes:
                if chord['end'] == TESTEND:
                    if len(old_strokes) < len(result):
                        print(word, freq, len(result), len(old_strokes))
        if old_strokes is not None and result is not None:
            if len(old_strokes) > len(result):
                pass
        index += 1
        total_count += freq
        if result is not None:
            if index < assume_one_n:
                n_chords = 1
            else:
                n_chords = len(result)
        else:
            n_chords = None  #1000000
            fail_count += freq
        if n_chords is not None:
            count += freq
            l_count += freq * n_chords
    return (float(l_count) / count, float(fail_count) / total_count)
Example #3
0
def get_avg_strokes(patterns=ortho_matching.default_patterns, assume_one_n=200):
    consider_n = 10000
    count = 0
    l_count = 0
    index = 0
    total_count = 0
    fail_count = 0
    for freq, word in freqs[:consider_n]:
        result = ortho_matching.match_text(word.upper(), patterns=patterns)
        old_strokes = ortho_matching.match_text(word.upper())
        if old_strokes is not None:
            for chord in old_strokes:
                if chord["end"] == TESTEND:
                    if len(old_strokes) < len(result):
                        print(word, freq, len(result), len(old_strokes))
        if old_strokes is not None and result is not None:
            if len(old_strokes) > len(result):
                pass
        index += 1
        total_count += freq
        if result is not None:
            if index < assume_one_n:
                n_chords = 1
            else:
                n_chords = len(result)
        else:
            n_chords = None  # 1000000
            fail_count += freq
        if n_chords is not None:
            count += freq
            l_count += freq * n_chords
    return (float(l_count) / count, float(fail_count) / total_count)
Example #4
0
def distribution_of_improvement(patterns, base_patterns=ortho_matching.default_patterns, n=5, removed=False):
    ignore_n = 200
    consider_n = 10000
    top_effects = []
    total_freq = 0
    total_effect = 0
    for freq, word in freqs[ignore_n : ignore_n + consider_n]:
        base_result = ortho_matching.match_text(word.upper(), patterns=base_patterns)
        result = ortho_matching.match_text(word.upper(), patterns=patterns)
        if result is not None and base_result is not None:
            if removed:
                effect_size = (len(result) - len(base_result)) * freq
            else:
                effect_size = (len(base_result) - len(result)) * freq
            if effect_size < 0:
                effect_size = 0
            if len(top_effects) < n:
                top_effects.append((effect_size, freq, word))
            elif effect_size > top_effects[0][0]:
                top_effects[0] = (effect_size, freq, word)
                top_effects.sort()
            total_effect += effect_size
            total_freq += freq
    improvements = []
    for effect_size, freq, word in top_effects:
        improvements.append(float(total_effect) / total_freq)
        total_effect -= effect_size
        total_freq -= freq
    words = [w for e, f, w in top_effects]
    return improvements, words
Example #5
0
def get_change(text, patterns, base_patterns=ortho_matching.default_patterns):
    base_result = ortho_matching.match_text(text.upper(), patterns=base_patterns)
    result = ortho_matching.match_text(text.upper(), patterns=patterns)
    if result is None and base_result is None:
        effect_size = None
    else:
        effect_size = len(result) - len(base_result)
    return effect_size
Example #6
0
def get_change(text, patterns, base_patterns=ortho_matching.default_patterns):
    base_result = ortho_matching.match_text(text.upper(),
                                            patterns=base_patterns)
    result = ortho_matching.match_text(text.upper(), patterns=patterns)
    if result is None and base_result is None:
        effect_size = None
    else:
        effect_size = len(result) - len(base_result)
    return effect_size
Example #7
0
def test_first():
    n = 0
    for f, w in freqs[:200]:
        result = ortho_matching.match_text(w.upper())
        if result is None or len(result) > 1:
            print(w)
            n += 1
    print(n)
Example #8
0
def test_first():
    n = 0
    for f, w in freqs[:200]:
        result = ortho_matching.match_text(w.upper())
        if result is None or len(result) > 1:
            print(w)
            n += 1
    print(n)
Example #9
0
def main():
    data = DataStorage()
    while True:
        possible_questions = get_words(data)
        data.save()
        p_random = 0.5
        if random.random() < p_random:
            random_int = random.randint(0, len(possible_questions) - 1)
        else:
            random_int = 0
        score, question, answer = possible_questions[random_int]
        clear()
        attempt = input('Type {}: '.format(question))
        data.answer(question, attempt == answer)
        if attempt == answer:
            print('Correct!')
        else:
            print('Incorrect!')
            chords = None
            if question[-1] == '-':
                raise Exception('Unimplemented')
                #keys = ortho_keys.chord_to_keys(answer.upper(), None, None)
            elif question[0] == '-':
                raise Exception('Unimplemented')
                #keys = ortho_keys.chord_to_keys(None, None, answer.upper())
            else:
                chords = ortho_matching.match_text(answer.upper())
            if not chords:
                raise Exception('Could not match text {}'.format(
                    answer.upper()))
            for chord in chords:
                keys = ortho_keys.chord_to_keys(chord['start'], chord['vowel'],
                                                chord['end'])
                vchord = visualize.visualize_keys(keys)
                print(vchord)
            while attempt != answer:
                attempt = input('Type {}: '.format(question))
                if attempt == answer:
                    print('Correct!')
                else:
                    print('Incorrect!')