def receive_request(self, msg, content): """ If a "request" message is received, decode the task and the content and call the appropriate function to prepare the response. A reply "tell" message is then sent back. """ if self.tra is None: reply_content = KQMLList.from_string("(FAILURE :reason KAPPA_FAILURE)") reply_msg = KQMLPerformative("reply") reply_msg.set_parameter(":content", reply_content) self.reply(msg, reply_msg) return content_list = content task_str = content_list[0].to_string().upper() if task_str == "SATISFIES-PATTERN": try: reply_content = self.respond_satisfies_pattern(content_list) except Exception as e: self.error_reply(msg, "Error in performing satisfies " + "pattern task.") return else: self.error_reply(msg, "Unknown request task " + task_str) return reply_msg = KQMLPerformative("reply") reply_msg.set_parameter(":content", reply_content) self.reply(msg, reply_msg)
def respond_dont_know(self, msg, content_string): resp = '(ONT::TELL :content (ONT::DONT-KNOW :content %s))' %\ content_string resp_list = KQMLList.from_string(resp) reply_msg = KQMLPerformative('reply') reply_msg.set_parameter(':content', resp_list) self.reply(msg, reply_msg)
def receive_request(self, msg, content): ''' If a "request" message is received, decode the task and the content and call the appropriate function to prepare the response. A reply message is then sent back. ''' content_list = content task_str = content_list[0].to_string().upper() if task_str == 'IS-DRUG-TARGET': reply_content = self.respond_is_drug_target(content_list) elif task_str == 'FIND-TARGET-DRUG': reply_content = self.respond_find_target_drug(content_list) elif task_str == 'FIND-DISEASE-TARGETS': reply_content = self.respond_find_disease_targets(content_list) elif task_str == 'FIND-TREATMENT': reply_content = self.respond_find_treatment(content_list) if reply_content is None: self.respond_dont_know(msg, '(ONT::A X1 :instance-of ONT::DRUG)') return else: self.error_reply(msg, 'unknown request task ' + task_str) return reply_msg = KQMLPerformative('reply') reply_msg.set_parameter(':content', reply_content) self.reply(msg, reply_msg)
def receive_request(self, msg, content): ''' If a "request" message is received, decode the task and the content and call the appropriate function to prepare the response. A reply "tell" message is then sent back. ''' content_list = content task_str = content_list[0].to_string().upper() arguments = self.request_arguments(content_list) if task_str == 'KAPPA-VERSION': try: reply_content = self.respond_version() except Exception as e: message = 'Could not get Kappa version: (%s)' % e self.error_reply(msg, message) return elif task_str == 'KAPPA-PARSE': try: reply_content = self.respond_parse(arguments) except Exception as e: message = 'Could not parse Kappa model: (%s)' % e self.error_reply(msg, message) return elif task_str == 'KAPPA-START': try: reply_content = self.respond_start(arguments) except Exception as e: message = 'Could not start Kappa simulation: (%s)' % e self.error_reply(msg, message) return elif task_str == 'KAPPA-STATUS': try: reply_content = self.respond_status(arguments) except Exception as e: message = 'Could not get Kappa status: (%s)' % e self.error_reply(msg, message) return elif task_str == 'KAPPA-STOP': try: reply_content = self.respond_stop(arguments) except Exception as e: message = 'Could not stop Kappa simulation: (%s)' % e self.error_reply(msg, message) return else: message = '"unknown request task ' + task_str + '"' self.error_reply(msg, message) return reply_msg = KQMLPerformative('reply') reply_msg.set_parameter(':content', reply_content) logger.debug(reply_content.to_string()) self.reply(msg, reply_msg)
def receive_request(self, msg, content): """ If a "request" message is received, decode the task and the content and call the appropriate function to prepare the response. A reply "tell" message is then sent back. """ try: task_str = content[0].to_string().upper() except Exception as e: logger.error("Could not get task string from request.") logger.error(e) self.error_reply(msg, "Invalid task") if task_str == "BUILD-MODEL": try: reply_content = self.respond_build_model(content) except InvalidModelDescriptionError as e: logger.error("Invalid model description.") logger.error(e) fail_msg = "(FAILURE :reason INVALID_DESCRIPTION)" reply_content = KQMLList.from_string(fail_msg) elif task_str == "EXPAND-MODEL": try: reply_content = self.respond_expand_model(content) except InvalidModelIdError as e: logger.error("Invalid model ID.") logger.error(e) fail_msg = "(FAILURE :reason INVALID_MODEL_ID)" reply_content = KQMLList.from_string(fail_msg) except InvalidModelDescriptionError as e: logger.error("Invalid model description.") logger.error(e) fail_msg = "(FAILURE :reason INVALID_DESCRIPTION)" reply_content = KQMLList.from_string(fail_msg) elif task_str == "MODEL-HAS-MECHANISM": reply_content = self.respond_has_mechanism(content) else: self.error_reply(msg, "Unknown task " + task_str) return reply_msg = KQMLPerformative("reply") reply_msg.set_parameter(":content", reply_content) self.reply(msg, reply_msg)
def receive_request(self, msg, content): """ If a "request" message is received, decode the task and the content and call the appropriate function to prepare the response. A reply "tell" message is then sent back. """ content_list = content task_str = content_list[0].to_string().upper() if task_str == "SIMULATE-MODEL": try: reply_content = self.respond_simulate_model(content_list) except Exception as e: self.error_reply(msg, "Error in performing simulation task.") return else: self.error_reply(msg, "Unknown request task " + task_str) return reply_msg = KQMLPerformative("reply") reply_msg.set_parameter(":content", reply_content) self.reply(msg, reply_msg)