it ca en en en cv en en en en en en en en en en ceb en en en en en en en en en en fr en en en it en en en en en en en en en en en en az eu en en en en en en en en it en
Warning: This document is for an old version of Rasa Core.
[docs] def parse(self, text, message_id=None): """Parse a text message. Return a default value if the parsing of the text failed.""" default_return = {"intent": {"name": "", "confidence": 0.0}, "entities": [], "text": ""} result = self._rasa_http_parse(text, message_id) return result if result is not None else default_return
def _rasa_http_parse(self, text, message_id=None): """Send a text message to a running rasa NLU http server. Return `None` on failure.""" if not self.endpoint: logger.error( "Failed to parse text '{}' using rasa NLU over http. " "No rasa NLU server specified!".format(text)) return None params = { "token": self.endpoint.token, "model": self.model_name, "project": self.project_name, "q": text, "message_id": message_id } url = "{}/parse".format(self.endpoint.url) try: result = requests.get(url, params=params) if result.status_code == 200: return result.json() else: logger.error( "Failed to parse text '{}' using rasa NLU over http. " "Error: {}".format(text, result.text)) return None except Exception as e: logger.error( "Failed to parse text '{}' using rasa NLU over http. " "Error: {}".format(text, e)) return None
[docs]class RasaNLUInterpreter(NaturalLanguageInterpreter): def __init__(self, model_directory, config_file=None, lazy_init=False): self.model_directory = model_directory self.lazy_init = lazy_init self.config_file = config_file if not lazy_init: self._load_interpreter() else: self.interpreter = None
[docs] def parse(self, text): """Parse a text message. Return a default value if the parsing of the text failed.""" if self.lazy_init and self.interpreter is None: self._load_interpreter() result = self.interpreter.parse(text) # TODO: hotfix to append attributes that NLU is adding as a server # but where the interpreter does not add them if result: result["model"] = "current" result["project"] = "default" return result
def _load_interpreter(self): from rasa_nlu.model import Interpreter self.interpreter = Interpreter.load(self.model_directory)