示例#1
0
 def test_gettingNextOfFirstInterpretationChangesOnlyTheLastWord(
         self, double_love_tree):
     next_of_none = double_love_tree.get_next_interpretation(None)
     next_of_first = double_love_tree.get_next_interpretation(next_of_none)
     assert len(next_of_first) == 2
     assert next_of_first[0] == Token("love", PartOfSpeech.NOUN)
     assert next_of_first[1] == Token("love", PartOfSpeech.V_IMP)
示例#2
0
 def test_completelyValidInterpretationIsReturnedFully(
         self, double_love_tree):
     interpretation = [
         Token("love", PartOfSpeech.NOUN),
         Token("love", PartOfSpeech.NOUN),
     ]
     sub_interpretation = double_love_tree.longest_legal_sub_interpretation(
         interpretation)
     assert sub_interpretation == interpretation
示例#3
0
 def test_gettingNextOfLastInterpretationReturnsNone(
         self, double_love_tree):
     last_interpretation = [
         Token("love", PartOfSpeech.V_IMP),
         Token("love", PartOfSpeech.V_IMP),
     ]
     next_of_last = double_love_tree.get_next_interpretation(
         last_interpretation)
     assert next_of_last is None
示例#4
0
 def test_canQueryInterpretationAndReceiveLongestMatchingSubsequence(
         self, double_love_tree):
     sub_interpretation = double_love_tree.longest_legal_sub_interpretation(
         [
             Token("love", PartOfSpeech.NOUN),
             Token("love", PartOfSpeech.PREPOSITION),
             Token("love", PartOfSpeech.OTHER),
         ])
     assert len(sub_interpretation) == 1
     assert sub_interpretation[0] == Token("love", PartOfSpeech.NOUN)
示例#5
0
 def test_whenProvidingIncompleteInterpretationNextInterpretationReturnedIsComplete(
         self, double_love_tree):
     last_interpretation = [
         Token("love", PartOfSpeech.V_IMP),
     ]
     next_of_first = double_love_tree.get_next_interpretation(
         last_interpretation)
     assert len(next_of_first) == 2
     assert next_of_first[0] == Token("love", PartOfSpeech.V_IMP)
     assert next_of_first[1] == Token("love", PartOfSpeech.NOUN)
示例#6
0
 def test_whenLastWordOptionsAreExhaustedNextInterpretationChangesPreviousWord(
         self, double_love_tree):
     last_interpretation = [
         Token("love", PartOfSpeech.NOUN),
         Token("love", PartOfSpeech.V_IMP),
     ]
     next_of_first = double_love_tree.get_next_interpretation(
         last_interpretation)
     assert len(next_of_first) == 2
     assert next_of_first[0] == Token("love", PartOfSpeech.V_IMP)
     assert next_of_first[1] == Token("love", PartOfSpeech.NOUN)
示例#7
0
 def test_gettingNextOfNoneReturnsAPossibleParsingForEachWord(
         self, double_love_tree):
     next_of_none = double_love_tree.get_next_interpretation(None)
     assert len(next_of_none) == 2
     assert next_of_none[0] == Token("love", PartOfSpeech.NOUN)
     assert next_of_none[1] == Token("love", PartOfSpeech.NOUN)
示例#8
0
 def token(self):
     return Token.from_tuple(self._stack.pop())