def _resolve_intent_response_key( self, label: Dict[Text, Optional[Text]]) -> Optional[Text]: """Given a label, return the response key based on the label id. Args: label: predicted label by the selector Returns: The match for the label that was found in the known responses. It is always guaranteed to have a match, otherwise that case should have been caught earlier and a warning should have been raised. """ for key, responses in self.responses.items(): # First check if the predicted label was the key itself search_key = util.template_key_to_intent_response_key(key) if hash(search_key) == label.get("id"): return search_key # Otherwise loop over the responses to check if the text has a direct match for response in responses: if hash(response.get(TEXT, "")) == label.get("id"): return search_key return None
def test_template_key_to_intent_response_key(): intent_response_key = "chitchat/ask_name" template_key = "utter_chitchat/ask_name" assert template_key_to_intent_response_key(template_key) == intent_response_key