Varible change Detection
In the python script for my robot, I'm searching for a way to detect a variable change. After doing a search, I found this example in VB.NET.
http://www.daniweb.com/forums/post610941.html#post610941
I've tried to translate it into a python bit, but with no success.
What I want my robot to do is this:
When talking to the robot, the robot ought to detect a change in topic. For instance, if I talk to my robot about, say Dinosaurs, and all of the sudden I say a string that has to do with another topic, have the robot say something like, "That's cool, but aren't we talking about Dinosaurs?"
Like so in this psuedo code:
class Topic:
OnTopic = 'Dinosaurs'
if OnTopic changes #Or tries to change? This is the main part I'm stumped on
GetVariable(OnTopic)
speaker.Speak('Thats cool, but arent we talking about', OnTopic)
if "yes we are"
speaker.Speak('Okay')
Set OnTopic to 'Dinorsaurs'
elif "No, now we're talking about movies"
speaker.Speak('Okay, lets talk about movies')
Set OnTopic to 'movies'
I'll continue to search for a solution myself. Thanks.
Seagull One
Junior Poster in Training
61 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
what about
class MySpeechParser(...):
self.topic = "Dinosaurs"
sentence = self.GetSentence()
topic = self.DiscernTopic(sentence)
if topic != self.topic:
speaker.Speak("You wanna stay on topic, yo?")
if response == "No":
self.topic = topic
jrcagle
Practically a Master Poster
608 posts since Jul 2006
Reputation Points: 92
Solved Threads: 156
There's a second way to think about this as well, and it's well adapted to real-time operating systems (read: robotics).
Suppose you have a speaker object, a listener object, and a thinker object that coordinates the two.
Then, the thinker object could have a property called .currentTopic
And when the listener object receives a sentence, it could parse the sentence and decide on its topic. Then the messaging could work like this:
class Listener(...):
def parser(self, sentence):
...
topic = DecideTopic(sentence)
thinker.CompareTopic(topic)
class Thinker(...):
def CompareTopic(self, topic):
if topic != self.currentTopic:
self.askNewTopic()
This is very similar to what was happening in post #2 except that Listener and Thinker are now discrete objects that signal one another by calling each others' methods.
The advantage is that Thinker can, for example, maintain a list of recent topics and only call askNewTopic after a certain percentage of recent sentences have been off topic ... or, if Thinker is really busy, he can blow off the whole askNewTopic thing.
Jeff
jrcagle
Practically a Master Poster
608 posts since Jul 2006
Reputation Points: 92
Solved Threads: 156