def _getCombo(word, morphs): #ans - combo for ans in aho(word, morphs.keys()): #list of sets of morph types for every morph in combo lst = [morphs[sub] for i, sub in ans] #p is potentional path in graph for p in product(*lst): #if path is acceptable if MorphSM.check(p): yield ans, p
def test_aho0(self): ass = [[(0, 'м'), (1, 'а'), (2, 'м'), (3, 'а')], [(0, 'м'), (1, 'а'), (2, 'ма')], [(0, 'м'), (1, 'ам'), (3, 'а')], [(0, 'ма'), (2, 'м'), (3, 'а')], [(0, 'ма'), (2, 'ма')], [(0, 'мам'), (3, 'а')], [(0, 'мама')]] res = sorted( list( aho(('мам', 'ами', 'мама', 'ми', 'и', 'ам', 'а', 'ма', 'м'), 'мама'))) self.assertEqual(res, ass)
def test_aho0(self): ass = [[(0, 'a'), (1, 'b')], [(0, 'ab')]] res = sorted(list(aho(('a','b','cde','ab','abc'), 'abcde'))) self.assertEqual(ass, res)
def test_aho2(self): ass = [[(0, 'дым'), (3, 'ок')], [(0, 'дымок')]] res = sorted(list(aho(('дым', 'ок', 'дымок'), 'дымок'))) self.assertEqual(ass, res)