コード例 #1
0
ファイル: interactive.py プロジェクト: tgalery/rasa_nlu
async def _write_domain_to_file(
    domain_path: Text,
    evts: List[Dict[Text, Any]],
    endpoint: EndpointConfig
) -> None:
    """Write an updated domain file to the file path."""

    domain = await retrieve_domain(endpoint)
    old_domain = Domain.from_dict(domain)

    messages = _collect_messages(evts)
    actions = _collect_actions(evts)

    # TODO for now there is no way to distinguish between action and form
    intent_properties = Domain.collect_intent_properties(
        _intents_from_messages(messages))

    collected_actions = list({e["name"]
                              for e in actions
                              if e["name"] not in default_action_names()})

    new_domain = Domain(
        intent_properties=intent_properties,
        entities=_entities_from_messages(messages),
        slots=[],
        templates={},
        action_names=collected_actions,
        form_names=[])

    old_domain.merge(new_domain).persist_clean(domain_path)
コード例 #2
0
async def test_import_nlu_training_data_with_default_actions(project: Text):
    config_path = os.path.join(project, DEFAULT_CONFIG_PATH)
    domain_path = os.path.join(project, DEFAULT_DOMAIN_PATH)
    default_data_path = os.path.join(project, DEFAULT_DATA_PATH)
    importer = TrainingDataImporter.load_from_dict({}, config_path,
                                                   domain_path,
                                                   [default_data_path])

    assert isinstance(importer, E2EImporter)
    importer_without_e2e = importer.importer

    # Check additional NLU training data from domain was added
    nlu_data = await importer.get_nlu_data()

    assert len(nlu_data.training_examples) > len(
        (await importer_without_e2e.get_nlu_data()).training_examples)

    from rasa.core.actions import action

    extended_training_data = await importer.get_nlu_data()
    assert all(
        Message(data={
            ACTION_NAME: action_name,
            ACTION_TEXT: ""
        }) in extended_training_data.training_examples
        for action_name in action.default_action_names())
コード例 #3
0
    def _add_actions_to_domain(
        self,
        domain: Domain,
        project_id: Text,
        actions: Optional[Iterable[Text]],
        origin: Optional[Text] = None,
    ) -> List[DomainAction]:
        domain_actions = self.get_actions_from_domain(project_id) or set()
        actions_to_add = set(actions) - domain_actions
        if not actions_to_add:
            logger.debug("Actions '{}' are already contained in domain for "
                         "project_id '{}'.".format(list(actions), project_id))
            return []

        # exclude default actions from `actions_to_add`
        actions_to_add = [
            a for a in actions_to_add if a not in default_action_names()
        ]

        new_actions = [
            DomainAction(action=action) for action in actions_to_add
        ]
        domain.actions.extend(new_actions)
        self._print_domain_change_info("actions", origin, actions_to_add)

        return new_actions
コード例 #4
0
ファイル: importer.py プロジェクト: pranavdurai10/rasa
def _additional_training_data_from_default_actions() -> TrainingData:
    from rasa.core.actions import action

    additional_messages_from_default_actions = [
        Message.build_from_action(action_name=action_name)
        for action_name in action.default_action_names()
    ]

    return TrainingData(additional_messages_from_default_actions)
コード例 #5
0
ファイル: domain.py プロジェクト: zhiyuxzh/rasa
    def _actions_for_domain_warnings(self) -> List[Text]:
        """Fetch names of actions that are used in domain warnings.

        Includes user and form actions, but excludes those that are default actions.
        """

        from rasa.core.actions.action import default_action_names

        return [
            a for a in self.user_actions_and_forms if a not in default_action_names()
        ]
コード例 #6
0
    async def _fetch_domain_items_from_story(
        self, story_id: Text
    ) -> Optional[Tuple[Set[Text], Set[Text], Set[Text], Set[Text]]]:
        from rasax.community.services.domain_service import DomainService

        domain_service = DomainService(self.session)
        domain = domain_service.get_domain()

        story = self.fetch_story(story_id)

        if not story:
            return None

        steps = await self.get_story_steps(story["story"], domain)
        story_actions = set()
        story_intents = set()
        story_entities = set()
        story_slots = set()
        for step in steps:
            for e in step.events:
                if (isinstance(e, ActionExecuted)
                        # exclude default actions and utter actions
                        and e.action_name not in default_action_names() and
                        not e.action_name.startswith(UTTER_PREFIX)):
                    story_actions.add(e.action_name)
                elif isinstance(e, UserUttered):
                    intent = e.intent
                    entities = e.entities
                    if intent:
                        story_intents.add(intent.get("name"))
                    if entities:
                        entity_names = [e["entity"] for e in entities]
                        story_entities.update(entity_names)
                elif isinstance(e, SlotSet):
                    slot = e.key
                    if slot:
                        story_slots.add(slot)

        return story_actions, story_intents, story_slots, story_entities