當前位置: 首頁>>代碼示例>>Python>>正文


Python Dialogue.recz方法代碼示例

本文整理匯總了Python中dialogueModule.Dialogue.recz方法的典型用法代碼示例。如果您正苦於以下問題:Python Dialogue.recz方法的具體用法?Python Dialogue.recz怎麽用?Python Dialogue.recz使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在dialogueModule.Dialogue的用法示例。


在下文中一共展示了Dialogue.recz方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: MyForm

# 需要導入模塊: from dialogueModule import Dialogue [as 別名]
# 或者: from dialogueModule.Dialogue import recz [as 別名]

#.........這裏部分代碼省略.........
	##CB30 ---
	def talkToRobot(self):
		if self.dialogue.getName():
			response = self.dialogue.youSay('my name is '+self.dialogue.getName())
			self.ui.textBrowserRobotResponse.append("<b><font color=blue>%s</font></b>" % (response))
		getUserInput = self.ui.lineEditUserDialogue.text()
		#print "Input: ", getUserInput, "type: ", type(str(getUserInput))
		getUserInput = str(getUserInput)
		response = self.dialogue.youSay(getUserInput)
		self.ui.textBrowserRobotResponse.append("> %s" % (str(getUserInput)))
		self.ui.textBrowserRobotResponse.append("<b><font color=blue>%s</font></b>" % (response))
		if not self.dialogueInit:
			self.updateDialogueContext(str(getUserInput))
			self.updateDialogueContextFields()
			if self.ui.lineEditAction.text() != '':
				self.updateDialogueContextAction(response)
			if not self.dialogueContext["personality"] == '':
				self.evaluateBasedOnInput(self.dialogueContext["personality"])
		#threading.Thread(target=self.jello(getUserInput)).start()

		self.dialogueInit = False
	   
		self.ui.lineEditUserDialogue.clear()

		# LOCOCONTEXT PART
		self.lcontext.lcKeywords(response, getUserInput)
		#self.lcontext.lcKeywords(getUserInput,response)
		self.lcontext.updateContext()
		#-motion = self.lcontext.executeAllMotion()
		#-if motion: print "motion ready:", motion
		#-else: print "meh."
		self.lcontext.wrongname()
		if self.lcontext.wrongname():
			self.dialogue.recz()
		#print self.dialogue.getName()
		#if self.dialogue.getName():
		#	response = self.dialogue.youSay('my name is '+self.dialogue.getName())
		#	self.ui.textBrowserRobotResponse.append("<b><font color=blue>%s</font></b>" % (response))
		try:
			motion = self.lcontext.executeAllMotion()
			if motion: print "motion ready:"#, motion
			else: print "meh."
			self.updateDialogueContextAction(response)
			khr1Interface("/dev/ttyUSB0", motion).start()
			#print "final motion:", motion
			#print "WOOOHOOO!!!"
		except:
			print "Sorry, try again! Fix your LocoContext.executeAllMotion() function!"
		
		try:
			self.ui.statusbar.showMessage("I see "+self.dialogue.facedetect.faces+" face(s)")
		except:
			self.ui.statusbar.showMessage("I can't see anything...")
	
	##CB31 ---
	def updateDialogueContext(self, inputstring):
		self.ui.lineEditAction.setText(self.dialogue.getValues("GET ACTION"))
		self.dialogueContext["topic"] = self.dialogue.getValues("GET TOPIC")
		self.dialogueContext["username"] = self.dialogue.getValues("GET USERNAME")
		self.dialogueContext["usermood"] = self.dialogue.getValues("GET USERMOOD")
		self.dialogueContext["it"] = self.dialogue.getValues("GET IT")
		self.dialogueContext["personality"] = self.dialogue.getValues("GET PERSONALITY")
		self.dialogueContext["robotmood"] = self.dialogue.getValues("GET ROBOTMOOD")
		self.dialogue.getValues(inputstring)

	##CB32 --- 
開發者ID:msunardi,項目名稱:soundmotion,代碼行數:70,代碼來源:pyLocoRobo_20b.py

示例2: MyForm

# 需要導入模塊: from dialogueModule import Dialogue [as 別名]
# 或者: from dialogueModule.Dialogue import recz [as 別名]

#.........這裏部分代碼省略.........
				self.ui.chatArea.append("<b><font color=green>%d.  %s</font></b>" % (i, scriptline[i]))
				self.chatoptions[str(i)] = scriptline[i]
		self.ui.chatArea.append("<b><font color=green>Or type anything ...</font></b><br>")
		
		# LOCOCONTEXT PART
		print "before lcontext...%s, %s" % (response, getUserInput)
		
		# LOCOCONTEXT: try to extract context from user's input (getUserInput) & AIML response (response)
		(keyverb,emotion) = self.lcontext.lcKeywords(response, getUserInput)
		self.updateChatContext(keyverb,emotion)
		print "after lcontext..."
		#self.lcontext.lcKeywords(getUserInput,response)
		#self.lcontext.updateContext()
		(update,action,emotion,willingness) = self.lcontext.updateContext2()
		
		# write to UI: 'Robot Action' field
		if action is None:
			self.ui.robotAction.setText('None')
		else:
			self.ui.robotAction.setText(action)	
		
		# write to UI: 'Willingness' field	
		self.ui.willingness.setText(str(willingness))
		
		# print emotion levels to Terminal
		print "emotion:", self.lcontext.showEmos()
		
		# write to UI: emotion level fields		
		self.updateEmoState(self.lcontext.showEmos(), self.dialogueInit)
		self.dialogueInit = False
	   		
		# If the user say the name was wrong, redo face recognition
		if self.lcontext.wrongname():
			self.dialogue.recz()
		try:
			motion = self.lcontext.executeAllMotion()
			
			if motion:
				print "motion ready:"#, motion
				
				# Run the resulting motion from LocoContext
				khr1Interface(self.khr1device, motion).start()
				
			else: print "meh."
			
			#~ self.updateDialogueContextAction(response)
						
		except:
			print "Sorry, try again! Fix your LocoContext.executeAllMotion() function, or trouble with khr1Interface!"
		
		try:
			self.ui.statusbar.showMessage("I see "+self.dialogue.facedetect.faces+" face(s)")
		except:
			self.ui.statusbar.showMessage("I can't see anything...")
			
		self.ui.chatInput.clear()
	
	# write to UI: Chat Context fields
	def updateChatContext(self, verb, emotion):
		self.ui.chatContextVerb.setText(str(verb))
		self.ui.chatContextEmo.setText(str(emotion))
			
	# write to UI: emotion level fields (called from talkToRobot(...))	
	def updateEmoState(self,emotions,init):
		self.ui.happyLevel.setText(str(emotions['happy']))
		self.ui.fearLevel.setText(str(emotions['fear']))
開發者ID:msunardi,項目名稱:soundmotion,代碼行數:70,代碼來源:runMiniUi_v0.4.7.py

示例3: MyForm

# 需要導入模塊: from dialogueModule import Dialogue [as 別名]
# 或者: from dialogueModule.Dialogue import recz [as 別名]

#.........這裏部分代碼省略.........
	
	def toggleStateVisible(self, value):
		if value: 
			self.ui.stateGroup.setVisible(True)
			self.writeToStatusBar("Displaying robot state")
		else:
			self.ui.stateGroup.setVisible(False)
			self.writeToStatusBar("Hiding robot state")
		#print value, self.affectProcessing
	
	# ---		
	def talkToRobot(self):
		if self.dialogue.getName():
			response = self.dialogue.youSay('my name is '+self.dialogue.getName())
			self.ui.chatArea.append("<b><font color=blue>%s</font></b>" % (response))
		getUserInput = self.ui.chatInput.text()
		#print "Input: ", getUserInput, "type: ", type(str(getUserInput))
		getUserInput = str(getUserInput)
		
		if getUserInput in self.chatoptions.keys():
			response = self.dialogue.youSay(self.chatoptions[getUserInput])
			self.ui.chatArea.append("> %s" % (self.chatoptions[getUserInput]))
			self.scriptindex +=1
		else:
			response = self.dialogue.youSay(getUserInput)
			self.ui.chatArea.append("> %s" % (str(getUserInput)))
		self.ui.chatArea.append("<b><font color=blue>>> %s</font></b>" % (response))
		
		self.ui.chatArea.append("<b><font color=green>Select your response:</font></b>")
		if self.scriptindex >= len(self.SCRIPT):
			self.scriptindex = 0
		
		scriptline = self.SCRIPT[self.scriptindex]
		
		for i in range(len(scriptline)):
			if scriptline[i] != '':
				self.ui.chatArea.append("<b><font color=green>%d.  %s</font></b>" % (i, scriptline[i]))
				self.chatoptions[str(i)] = scriptline[i]
		self.ui.chatArea.append("<b><font color=green>Or type anything ...</font></b><br>")
		

		self.dialogueInit = False
	   
		self.ui.chatInput.clear()
		

		# LOCOCONTEXT PART
		print "before lcontext...%s, %s" % (response, getUserInput)
		
		# LOCOCONTEXT: try to extract context from user's input (getUserInput) & AIML response (response)
		self.lcontext.lcKeywords(response, getUserInput)
		print "after lcontext..."
		#self.lcontext.lcKeywords(getUserInput,response)
		#self.lcontext.updateContext()
		(update,action,emotion,willingness) = self.lcontext.updateContext2()
		if action is None:
			self.ui.robotAction.setText('None')
		else:
			self.ui.robotAction.setText(action)	
		self.ui.willingness.setText(str(willingness))
		print "emotion:", self.lcontext.showEmos()
		self.updateEmoState(self.lcontext.showEmos())
		
		# If the user say the name was wrong, redo face recognition
		if self.lcontext.wrongname():
			self.dialogue.recz()
		try:
			motion = self.lcontext.executeAllMotion()
			
			if motion:
				print "motion ready:"#, motion
				
				# Run the resulting motion from LocoContext
				khr1Interface(self.khr1device, motion).start()
				
			else: print "meh."
			
			#~ self.updateDialogueContextAction(response)
						
		except:
			print "Sorry, try again! Fix your LocoContext.executeAllMotion() function!"
		
		try:
			self.ui.statusbar.showMessage("I see "+self.dialogue.facedetect.faces+" face(s)")
		except:
			self.ui.statusbar.showMessage("I can't see anything...")
	
	def updateEmoState(self,emotions):
		self.ui.happyLevel.setText(str(emotions['happy']))
		self.ui.fearLevel.setText(str(emotions['fear']))
		self.ui.sadnessLevel.setText(str(emotions['sad']))
		self.ui.angerLevel.setText(str(emotions['anger']))
		emolevel = [x for k,x in emotions.iteritems()]
		for k,x in emotions.iteritems():
			if x == max(emolevel):
				self.ui.robotMood.setText(k)
				self.setRobotPose(k)
				break
				
	def 
開發者ID:msunardi,項目名稱:soundmotion,代碼行數:104,代碼來源:runMiniUi_v0.4.5.py


注:本文中的dialogueModule.Dialogue.recz方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。