Esempio n. 1
0
def _get_core_nlu_files(
    paths: Optional[Union[Text, List[Text]]],
    skill_imports: Optional[SkillSelector] = None,
) -> Tuple[Set[Text], Set[Text]]:
    story_files = set()
    nlu_data_files = set()

    skill_imports = skill_imports or SkillSelector.all_skills()

    if not skill_imports.no_skills_selected():
        paths = skill_imports.training_paths()

    if paths is None:
        paths = []
    elif isinstance(paths, str):
        paths = [paths]

    for path in set(paths):
        if not path:
            continue

        if _is_valid_filetype(path) and skill_imports.is_imported(path):
            if _is_nlu_file(path):
                nlu_data_files.add(os.path.abspath(path))
            elif _is_story_file(path):
                story_files.add(os.path.abspath(path))
        else:
            new_story_files, new_nlu_data_files = _find_core_nlu_files_in_directory(
                path, skill_imports)

            story_files.update(new_story_files)
            nlu_data_files.update(new_nlu_data_files)

    return story_files, nlu_data_files
Esempio n. 2
0
    def load(
        cls,
        paths: Union[List[Text], Text],
        skill_imports: Optional[SkillSelector] = None,
    ) -> "Domain":
        skill_imports = skill_imports or SkillSelector.all_skills()

        if not skill_imports.no_skills_selected():
            paths = skill_imports.training_paths()

        if not paths:
            raise InvalidDomain(
                "No domain file was specified. Please specify a path "
                "to a valid domain file.")
        elif not isinstance(paths, list) and not isinstance(paths, set):
            paths = [paths]

        domain = Domain.empty()
        for path in paths:
            try:
                other = cls.from_path(path, skill_imports)
            except FileNotFoundError as error:
                # Skip missing file and continue with other files
                logger.warning(error)
            else:
                domain = domain.merge(other)

        return domain
Esempio n. 3
0
def get_core_nlu_files(
    paths: Optional[Union[Text, List[Text]]],
    skill_imports: Optional["SkillSelector"] = None,
) -> Tuple[Set[Text], Set[Text]]:
    """Recursively collects all training files from a list of paths.

    Args:
        paths: List of paths to training files or folders containing them.
        skill_imports: `SkillSelector` instance which determines which files
                        should be loaded.

    Returns:
        Tuple of paths to story and NLU files.
    """
    from rasa.skill import SkillSelector

    story_files = set()
    nlu_data_files = set()

    skill_imports = skill_imports or SkillSelector.all_skills()

    if not skill_imports.no_skills_selected():
        paths = skill_imports.training_paths()

    if paths is None:
        paths = []
    elif isinstance(paths, str):
        paths = [paths]

    for path in set(paths):
        if not path:
            continue

        if _is_valid_filetype(path) and skill_imports.is_imported(path):
            if _is_nlu_file(path):
                nlu_data_files.add(os.path.abspath(path))
            elif _is_story_file(path):
                story_files.add(os.path.abspath(path))
        else:
            new_story_files, new_nlu_data_files = _find_core_nlu_files_in_directory(
                path, skill_imports)

            story_files.update(new_story_files)
            nlu_data_files.update(new_nlu_data_files)

    return story_files, nlu_data_files
Esempio n. 4
0
    def from_directory(
        cls, path: Text, skill_imports: Optional[SkillSelector] = None
    ) -> "Domain":
        """Loads and merges multiple domain files recursively from a directory tree."""

        domain = Domain.empty()
        skill_imports = skill_imports or SkillSelector.all_skills()

        for root, _, files in os.walk(path):
            if not skill_imports.is_imported(root):
                continue

            for file in files:
                full_path = os.path.join(root, file)
                if data.is_domain_file(full_path):
                    other = Domain.from_file(full_path)
                    domain = other.merge(domain)

        return domain
Esempio n. 5
0
    def load(
        cls,
        paths: Union[List[Text], Text],
        skill_imports: Optional[SkillSelector] = None,
    ) -> "Domain":
        skill_imports = skill_imports or SkillSelector.all_skills()

        if not skill_imports.no_skills_selected():
            paths = skill_imports.training_paths()

        if not paths:
            raise InvalidDomain(
                "No domain file was specified. Please specify a path "
                "to a valid domain file.")
        elif not isinstance(paths, list) and not isinstance(paths, set):
            paths = [paths]

        domain = Domain.empty()
        for path in paths:
            other = cls.from_path(path, skill_imports)
            domain = domain.merge(other)

        return domain
Esempio n. 6
0
def test_load_from_none(input_dict):
    actual = SkillSelector._from_dict(input_dict, Path("."), SkillSelector.all_skills())

    assert actual._imports == set()