def test_And(self): node = Tokenization.SentenceNode("abc") node.features.add(FeatureOntology.GetFeatureID('NN')) strtokenlist = Tokenization.SentenceLinkedList() strtokenlist.append(node) self.assertFalse(LogicMatchFeatures(strtokenlist, 0, "NN percent", [Rules.RuleToken()], 0)) node.features.add(FeatureOntology.GetFeatureID('percent')) self.assertTrue(LogicMatchFeatures(strtokenlist, 0, "NN percent", [Rules.RuleToken()], 0))
def test_LogicNotOr(self): """Logic And/Or""" node = Tokenization.SentenceNode('d') strtokenlist = Tokenization.SentenceLinkedList() strtokenlist.append(node) RuleTokenList = [Rules.RuleToken()] self.assertFalse(LogicMatchFeatures(strtokenlist, 0, "!c|d|e", RuleTokenList, 0)) node.text = "f" self.assertTrue(LogicMatchFeatures(strtokenlist, 0, "!c|d|e", RuleTokenList, 0)) node.text = "e" self.assertTrue(LogicMatchFeatures(strtokenlist, 0, "!c d|e", RuleTokenList, 0)) node.text = "f" self.assertFalse(LogicMatchFeatures(strtokenlist, 0, "!c d|e", RuleTokenList, 0)) node.text = "c" self.assertTrue(LogicMatchFeatures(strtokenlist, 0, "c|d !d|e", RuleTokenList, 0)) node.text = "d" self.assertFalse(LogicMatchFeatures(strtokenlist, 0, "c|d !d|e", RuleTokenList, 0)) node.text = "e" self.assertFalse(LogicMatchFeatures(strtokenlist, 0, "c|e !d|f|g|e", RuleTokenList, 0)) node.text = "e" self.assertFalse(LogicMatchFeatures(strtokenlist, 0, "c|d !d|c", RuleTokenList, 0)) node.text = "f" self.assertFalse(LogicMatchFeatures(strtokenlist, 0, "c|d !d|e", RuleTokenList, 0))
def test_LogicOr(self): """Logic Or""" node = Tokenization.SentenceNode('being') strtokenlist = Tokenization.SentenceLinkedList() strtokenlist.append(node) self.assertTrue(LogicMatchFeatures(strtokenlist, 0, "being|getting", [Rules.RuleToken()], 0))
def test_LogicAndOr(self): """Logic And/Or""" node = Tokenization.SentenceNode('d') strtokenlist = Tokenization.SentenceLinkedList() strtokenlist.append(node) ruletokenlist = [Rules.RuleToken()] self.assertFalse(LogicMatchFeatures(strtokenlist, 0, "c|d c", ruletokenlist, 0)) node.text = "c" self.assertTrue(LogicMatchFeatures(strtokenlist, 0, "c|d c", ruletokenlist, 0))
def test_LogicAnd(self): """Logic And""" node = Tokenization.SentenceNode("c") strtokenlist = Tokenization.SentenceLinkedList() strtokenlist.append(node) ruletokenlist = [Rules.RuleToken()] self.assertFalse(LogicMatchFeatures(strtokenlist, 0, "c d", ruletokenlist, 0)) self.assertTrue(LogicMatchFeatures(strtokenlist, 0, "c c", ruletokenlist, 0))
def test_LogicCombined(self): """Logic Combined""" blocks = SeparateOrBlocks("a|b|c") self.assertEqual(len(blocks), 3) blocks = SeparateOrBlocks("a") self.assertEqual(len(blocks), 1) blocks = SeparateOrBlocks("'a|b'|c") self.assertEqual(len(blocks), 2) strtokenlist = Tokenization.Tokenize('d') RuleTokenList = [Rules.RuleToken()] self.assertTrue(LogicMatch(strtokenlist, 0, 'd', RuleTokenList, 0)) #strtokenlist = Tokenization.Tokenize("notfeature|'d'|notfeature2") self.assertTrue(LogicMatch(strtokenlist, 0, "notfeature|'d'|notfeature2", RuleTokenList, 0))