From 1fa54e4fd227be362db75da0ee4ea2a06d786ff5 Mon Sep 17 00:00:00 2001 From: Anton Bobrov Date: Sat, 29 Jan 2011 17:29:48 +1000 Subject: [PATCH] ignore non word chars --- typetrainer/generator.py | 5 ++++- typetrainer/tutors/common.py | 10 +++++++++- typetrainer/ui/main.py | 6 ++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/typetrainer/generator.py b/typetrainer/generator.py index 460b1a4..1498b9b 100644 --- a/typetrainer/generator.py +++ b/typetrainer/generator.py @@ -92,10 +92,13 @@ def reset(self): def make_char_chain(words, seq_len, dist): first, other = {'any':Parts(dist)}, {} + word_chars = set() for t, w in words: if t != 'w': continue + map(word_chars.add, w) + wlen = len(w) if wlen <= seq_len: if not wlen in first: @@ -117,7 +120,7 @@ def make_char_chain(words, seq_len, dist): pc = next pos += seq_len - return first, other + return first, other, word_chars def chain_traversor(choices, other, length): copied = False diff --git a/typetrainer/tutors/common.py b/typetrainer/tutors/common.py index b31862c..b419b7c 100644 --- a/typetrainer/tutors/common.py +++ b/typetrainer/tutors/common.py @@ -7,7 +7,7 @@ class Filler(object): def __init__(self, words, make_lengths_seq): self.dist = {} - self.first, self.other = make_char_chain(words, 3, self.dist) + self.first, self.other, self.word_chars = make_char_chain(words, 3, self.dist) self.lengths = list(make_lengths_seq(words)) self.old_generated = collections.deque([], 100) @@ -48,3 +48,11 @@ def reset_parts(self): for p in self.first.values(): p.reset() + + def strip_non_word_chars(self, string): + result = '' + for c in string: + if c in self.word_chars: + result += c + + return result \ No newline at end of file diff --git a/typetrainer/ui/main.py b/typetrainer/ui/main.py index dcbf0ed..b086ee1 100644 --- a/typetrainer/ui/main.py +++ b/typetrainer/ui/main.py @@ -113,12 +113,14 @@ def add_error(self, pos, typed, idx, wfactor): if char == ' ': return - if typed[idx][0] and pos > 0 and self.totype_text[pos-1] != ' ': + if typed[idx][0] and pos > 0: key = self.totype_text[pos-1:pos+1] else: key = self.totype_text[pos] - self.errors[key] += wfactor / self.totype_text.count(char) + key = self.filler.strip_non_word_chars(key) + if key: + self.errors[key] += wfactor / self.totype_text.count(char) def sink_errors(self): for k in self.errors: