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)
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
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
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)
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)
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)
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)
def token(self): return Token.from_tuple(self._stack.pop())