def test_pipe(self): data = (3, 1, 1, 1, 1, 0.1, 0.1, 1000) expected = [1.0, 1.0, 0.7, 0.4] tester = self.numeric_evaluator(expected) coroutines = [co.sliding_window(3), co.transformer(np.mean), co.filterer(lambda x: 0 <= x <= 1), tester] pipe_tester = co.pipe(coroutines) for d in data: pipe_tester.send(d)
def test_pipe(self): data = (3, 1, 1, 1, 1, 0.1, 0.1, 1000) expected = [1.0, 1.0, 0.7, 0.4] tester = self.numeric_evaluator(expected) coroutines = [ co.sliding_window(3), co.transformer(np.mean), co.filterer(lambda x: 0 <= x <= 1), tester ] pipe_tester = co.pipe(coroutines) for d in data: pipe_tester.send(d)
Returns ------- bool A bool indicating whether to ask a question or not. """ randvalue = random.random() should_ask = randvalue < jsd_value rospy.logdebug("JSD: {}, Randval: {}, Going to Ask?: {}".format( jsd_value, randvalue, should_ask)) return should_ask pipe = co.pipe([ co.mapper(jensen_shannon_divergence), co.filterer(should_ask_question), co.do(lambda _: rospy.loginfo("Going to ask")), co.publisher("should_ask_question", Bool) ]) _DEFAULT_NAME = 'al_asker_node' if __name__ == '__main__': try: rospy.init_node(_DEFAULT_NAME) rospy.loginfo("Initializing {} Node".format(rospy.get_name())) co.PipedSubscriber('prediction_summary', PredictionSummary, pipe) rospy.spin() except rospy.ROSInterruptException: pass
""" import roslib roslib.load_manifest('ocular_interaction') from functools import partial import rospy from rospy_utils import coroutines as co from ocular_interaction import ocular_action_translators as tr from dialog_manager_msgs.msg import ActionMsg from etts_msgs.msg import Utterance is_action_valid = partial(tr.should_process_action, actor_name="etts", action_name="say_text") if __name__ == '__main__': try: rospy.init_node('ocular_etts_translator') rospy.loginfo("Initializing {} Node".format(rospy.get_name())) pipe = co.pipe([ co.filterer(is_action_valid), co.transformer(tr.action_to_etts), co.publisher('etts', Utterance) ]) co.PipedSubscriber('im_action', ActionMsg, pipe) rospy.spin() except rospy.ROSInterruptException: pass
def test_filterer_curried(self): expected, tester = self.__setup_filterer() test_filterer = co.filterer(is_even) test_filterer.send(tester) for i in self.data: test_filterer.send(i)
def parse_asr_msg(msg, commands): """Parse an ASR msg to found a command in it.""" try: return next(parse_sentence(msg.content, commands)) except StopIteration: pass def _log_msg(msg): """Log a msg to a rospy logger.""" rospy.loginfo(utils.colorize("ASR msg parsed to command: {}".format(msg))) if __name__ == '__main__': try: rospy.init_node('asr_command_parser') rospy.loginfo("Initializing {} Node".format(rospy.get_name())) commands = next(pu.load_params('asr_commands')) rospy.logdebug("Available commands are: {}".format(commands)) parsed_cmds = {utils.to_infinitive(k): v for k, v in commands.items()} parse_msg = partial(parse_asr_msg, commands=parsed_cmds) pipe = co.pipe([ co.transformer(parse_msg), co.do(_log_msg), co.filterer(bool), splitter ]) co.PipedSubscriber('open_grammar_results', ASRmsg, pipe) rospy.spin() except rospy.ROSInterruptException: pass