Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main():
logger = logging.getLogger()
confidence_threshold = .5
nlu = NaturalLanguageUnderstander(confidence_threshold, logger)
# Register the NLU messages we want
nlu.register_message(YesNoMessage)
nlu.register_message(SearchMessage)
nlu.register_message(SystemMessage)
fil = open('INGREDIENTS.txt', 'r')
# Skip comments and empty lines
input_messages = (l.strip() for l in fil if not re.search('^\s*($|#)', l))
for line in islice(input_messages, 0, LIMIT):
messages = nlu.parse_input(line)
print line
for message in messages:
print message.__class__
print pprint.pformat(message.frame)
Create a new instance of the chatbot application.
>>> from database import Database
>>> db = Database('sqlite:///:memory:')
>>> bot = Chatbot(db, logging.getLogger())
>>> response = bot.handle_input("Hi!")
"""
self.prompt = '-> '
self.creative_mode = False # enables creative mode, temporarilly.
# creative mode allows concurrent activity
# between creative subgroup and lev1, lev2
self.enable_debug = enable_debug
self.db = db
self.log = logger
self.nlg = NaturalLanguageGenerator(logger.getChild('nlg'))
self.nlu = NaturalLanguageUnderstander(0.5, logger.getChild('nlu'))
self.dm = DialogueManager(db, logger.getChild('dm'))
#
self.creative_nlp = CreativeManager(db, logger.getChild('creative'), self.nlu, self.nlg, self.dm)
#
self.log.debug("Chatbot instantiated")
self.last_bot_output = ""
# Register the NLU messages we want
self.nlu.register_message(YesNoMessage)
self.nlu.register_message(SearchMessage)
self.nlu.register_message(SystemMessage)
startup(self.nlg)