def test_resolution_nonempty(self): atom_needs = [ AtomNeed('the type', 'word_for_the'), AtomNeed('shop type', 'word_for_shop'), AtomNeed('old type', 'word_for_old'), AtomNeed('you type', 'word_for_you') ] templates = { 'order' : 'Come to $word_for_the $word_for_old $word_for_shop!', 'question' : 'Have $word_for_you gone to $word_for_the $word_for_shop?' } pattern = PhrasePattern('shop_stuff', atom_needs, templates) modern_english_atoms = [ Atom('the type', 'the'), Atom('shop type', 'shop'), Atom('old type', 'old'), Atom('you type', 'you') ] old_english_atoms = [ Atom('the type', 'ye'), Atom('shop type', 'shoppe'), Atom('old type', 'olde'), Atom('you type', 'thou') ] modern_phrases = pattern.resolve(modern_english_atoms) self.assertEqual(len(modern_phrases), 1) modern_phrase = modern_phrases[0] self.assertEqual(modern_phrase.get_snippet('order'), 'Come to the old shop!') self.assertEqual(modern_phrase.get_snippet('question'), 'Have you gone to the shop?') self.assertEqual(modern_phrase.get_atoms(), modern_english_atoms) old_phrases = pattern.resolve(old_english_atoms) self.assertEqual(len(old_phrases), 1) old_phrase = old_phrases[0] self.assertEqual(old_phrase.get_snippet('order'), 'Come to ye olde shoppe!') self.assertEqual(old_phrase.get_snippet('question'), 'Have thou gone to ye shoppe?') self.assertEqual(old_phrase.get_atoms(), old_english_atoms) combined_phrases = pattern.resolve(modern_english_atoms + old_english_atoms) self.assertEqual(len(combined_phrases), 16)
def test_resolution_empty(self): pattern = PhrasePattern('the type') phrases = pattern.resolve({}) self.assertEqual(phrases, [Phrase('the type', {}, [])])
def test_construction(self): atom_needs = [AtomNeed('a', 'a'), AtomNeed('b', 'b')] pattern = PhrasePattern('foo', atom_needs, {}) self.assertEqual(pattern.get_atom_needs(), atom_needs)