Skip to content

Commit

Permalink
Merge f5259fb into ca35743
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikP committed Mar 26, 2018
2 parents ca35743 + f5259fb commit d97d883
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/ahocorapy/keywordtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
Quite optimized, the code may not be as beautiful as you like,
since inlining and so on was necessary
This library is optimized for the cPython interpreter.
I will most likely run slower with pypy, etc.
Created on Jan 5, 2016
@author: Frederik Petersen (fp@abusix.com)
Expand Down Expand Up @@ -150,9 +147,6 @@ def search_lss_for_children(self, zero_state):
def search_lss(self, state):
if state.longest_strict_suffix is None:
parent = state.parent
if parent.longest_strict_suffix is None:
# Has not been done yet. Do early
self.search_lss(parent)
traversed = parent.longest_strict_suffix
while True:
if state.symbol in traversed.transitions and\
Expand All @@ -164,11 +158,10 @@ def search_lss(self, state):
state.longest_strict_suffix = self._zero_state
break
else:
if traversed.longest_strict_suffix is None:
self.search_lss(traversed)
traversed = traversed.longest_strict_suffix
suffix = state.longest_strict_suffix

if suffix.longest_strict_suffix is None:
self.search_lss(suffix)
for symbol, next_state in suffix.transitions.items():
if (symbol not in state.transitions and
suffix != self._zero_state):
Expand Down
15 changes: 15 additions & 0 deletions tests/ahocorapy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,20 @@ def test_search_all_issue_1_similar(self):

self.assertEqual(('bar', 5), next(results))

def test_search_all_issue_3_similar(self):
text = '/foo/bar'
words = ['foo/', 'foo', '/foo/', '/bar']
tree = KeywordTree(case_insensitive=True)
for word in words:
tree.add(word)
tree.finalize()

results = tree.search_all(text)

self.assertEqual(('foo', 1), next(results))
self.assertEqual(('/foo/', 0), next(results))
self.assertEqual(('foo/', 1), next(results))
self.assertEqual(('/bar', 4), next(results))

if __name__ == '__main__':
unittest.main()

0 comments on commit d97d883

Please sign in to comment.