Navigation Menu

Skip to content

Commit

Permalink
ignore non word chars
Browse files Browse the repository at this point in the history
  • Loading branch information
baverman committed Jan 29, 2011
1 parent 6252c49 commit 1fa54e4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 4 additions & 1 deletion typetrainer/generator.py
Expand Up @@ -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:
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion typetrainer/tutors/common.py
Expand Up @@ -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)

Expand Down Expand Up @@ -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
6 changes: 4 additions & 2 deletions typetrainer/ui/main.py
Expand Up @@ -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:
Expand Down

0 comments on commit 1fa54e4

Please sign in to comment.