jweinst1
12/10/2015 - 12:04 AM

trie that can look up statements.

trie that can look up statements.

#statement trie

class strie (object):
	
	def __init__(self):
		self.trie = {}
	def __repr__(self):
		return str(self.trie)
	def __str__(self):
		return str(self.trie)
	def statement(self, phrase):
		words = phrase.split()
		current = self.trie
		while len(words) > 0:
			word = words.pop(0)
			if word in current.keys():
				current = current[word]
			else:
				current[word] = {}
				current = current[word]
	def istrue(self, phrase):
	    words = phrase.split()
	    current = self.trie
	    while len(words) > 0:
	        word = words.pop(0)
	        if word in current.keys():
	            current = current[word]
	        else:
	            return False
	    return True