Skip to content

Commit 5296869

Browse files
committed
moved db commit statement to improve performance with large text files, updated test
1 parent 52a373e commit 5296869

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

parse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ def parse(self, txt):
3131
for n in range(0, len(words) - depth + 1):
3232
self.db.add_word(words[n:n+depth])
3333

34-
self.db.commit()
3534
i += 1
3635
if i % 1000 == 0:
3736
print i
3837
sys.stdout.flush()
3938

39+
self.db.commit()
4040

test/parse_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def setUp(self):
77

88
def test_db_updated_correctly_from_input_with_depth_2_and_extra_whitespace(self):
99
Parser('name', self.db, '\n', ' ').parse(' the cat sat on the mat \n good cat ')
10-
self.assertEqual(self.db.commit_count, 2)
10+
self.assertEqual(self.db.commit_count, 1)
1111
self.assertEqual(self.db.added_word_list, [['^', 'the'], ['the', 'cat'], ['cat', 'sat'], ['sat', 'on'], ['on', 'the'], ['the', 'mat'], ['mat', '$'], ['^', 'good'], ['good', 'cat'], ['cat', '$']])
1212

1313
def test_db_updated_correctly_from_input_with_depth_4(self):

0 commit comments

Comments
 (0)