Пример #1
0
	def __init__(self, verbose = False):
		# load modules 
		#     NLU, DB connection test
		
		
		self.nlu = NLparser(verbose)
		
		# verbose true for DM and NLG
		verbose = True
		
		self.dm  = DialogManager(verbose)
		self.nlg = NLgenerator(verbose)
		self.sessionid = date.strftime(date.today(),"%y%m%d") + "_" + time.strftime("%H%M%S")
		self.logger = utils.ConsoleAndFileLogger(self.sessionid)
Пример #2
0
class Agent:
	def __init__(self, verbose = False):
		# load modules 
		#     NLU, DB connection test
		
		
		self.nlu = NLparser(verbose)
		
		# verbose true for DM and NLG
		verbose = True
		
		self.dm  = DialogManager(verbose)
		self.nlg = NLgenerator(verbose)
		self.sessionid = date.strftime(date.today(),"%y%m%d") + "_" + time.strftime("%H%M%S")
		self.logger = utils.ConsoleAndFileLogger(self.sessionid)
	
	
	def run(self):
		self.logger.log("Hello. I am YARB (Yet Another Recommendation Bot).")
		self.logger.log("Please tell me your name.")
		usermsg = raw_input("> ")
		self.logger.logtofile("> " + usermsg)
		if (self.dm.processUserName(usermsg) == 1):
			self.logger.log("Welcome back, " + usermsg + ".")
		else: 
			self.logger.log("Nice to meet you, " + usermsg + ".")
		self.logger.log("If you'd like a recommendation, please tell\nme about what you like or dislike.")
		
		self.dm.loadOptions()

		while not self.dm.sessionclosed():
			usermsg = raw_input("> ")
			self.logger.logtofile("> " + usermsg)
			
			if usermsg == "":
				continue

			nluoutput = self.nlu.process(usermsg)            # NLU
			
			for output in nluoutput:
				dmoutput  = self.dm.process(output)           # DM
			#dmoutput  = self.dm.process(nluoutput)
				
			response  = self.nlg.process(dmoutput)           # NLG
			
			self.logger.log(response)
			
		self.dm.saveUserPreferences()
		self.logger.log("Session closed [id = {0:s}].".format(self.sessionid))

	def test(self, inputfilename):
		print 'reading: ' + inputfilename
		infile = open(inputfilename, 'r')
		
		num = 1
		breakpoint = 29
		
		print 'processing... classifier: trivia'
		for line in infile:
			# NLU process
			input = line.strip()
				#print input
			nluoutput = self.nlu.process(input)            # NLU
			
			#if num != breakpoint and nluoutput.get_classifier() != "userPreference":
			#	num = num + 1
			#	continue
				
			#if breakpoint == num:
				#print str(num) + ". " + line.replace('\\','') + " --> " + nluoutput.get_classifier() + " , [", nluoutput.tostr_entities(), "]"
					
			#if nluoutput.get_classifier() == "trivia":
			print str(num) + ". " + input
			dmoutput = self.dm.process(nluoutput)
			msg = self.nlg.process(dmoutput)
			print "> " + msg
			print 
		
			num = num + 1