Ejemplo n.º 1
0
 def _state_features_for_attribute(self, sub_state: SubState,
                                   attribute: Text) -> Dict[Text, int]:
     if attribute in {INTENT, ACTION_NAME}:
         return {sub_state[attribute]: 1}
     elif attribute == ENTITIES:
         return {entity: 1 for entity in sub_state.get(ENTITIES, [])}
     elif attribute == ACTIVE_LOOP:
         return {sub_state["name"]: 1}
     elif attribute == SLOTS:
         return {
             f"{slot_name}_{i}": value
             for slot_name, slot_as_feature in sub_state.items()
             for i, value in enumerate(slot_as_feature)
         }
     else:
         raise ValueError(
             f"Given attribute '{attribute}' is not supported. "
             f"It must be one of '{self._default_feature_states.keys()}'.")
Ejemplo n.º 2
0
 def _state_features_for_attribute(self, sub_state: SubState,
                                   attribute: Text) -> Dict[Text, int]:
     # FIXME: the code below is not type-safe, but fixing it
     #        would require more refactoring, for instance using
     #        data classes in our states
     if attribute in {INTENT, ACTION_NAME}:
         return {sub_state[attribute]: 1}  # type: ignore[dict-item]
     elif attribute == ENTITIES:
         return {entity: 1 for entity in sub_state.get(ENTITIES, [])}
     elif attribute == ACTIVE_LOOP:
         return {sub_state["name"]: 1}  # type: ignore[dict-item]
     elif attribute == SLOTS:
         return {
             f"{slot_name}_{i}": value
             for slot_name, slot_as_feature in sub_state.items()
             for i, value in enumerate(slot_as_feature)
         }
     else:
         raise ValueError(
             f"Given attribute '{attribute}' is not supported. "
             f"It must be one of '{self._default_feature_states.keys()}'.")