Example #1
0
def resolve_data_files(resource_name):
    # type: (str) -> [str]
    """Lists all data files of the resource name (might be a file or directory)."""

    try:
        return utils.recursively_find_files(resource_name)
    except ValueError as e:
        raise ValueError("Invalid training data file / folder specified. " + e.message)
Example #2
0
def resolve_data_files(resource_name):
    # type: (Text) -> List[Text]
    """Lists all data files of the resource name (might be a file or directory)."""

    try:
        return utils.recursively_find_files(resource_name)
    except ValueError as e:
        raise ValueError("Invalid training data file / folder specified. {}".format(e))
Example #3
0
def resolve_data_files(resource_name):
    # type: (Text) -> List[Text]
    """Lists all data files of the resource name (might be a file or directory)."""

    try:
        return utils.recursively_find_files(resource_name)
    except ValueError as e:
        raise ValueError(
            "Invalid training data file / folder specified. {}".format(e))
Example #4
0
def load_data(resource_name, language='en'):
    # type: (Text, Optional[Text]) -> TrainingData
    """Loads training data from disk and merges them if multiple files are found."""

    files = utils.recursively_find_files(resource_name)
    data_sets = [_load(f, language) for f in files]
    data_sets = [ds for ds in data_sets if ds]
    if len(data_sets) == 0:
        return TrainingData()
    elif len(data_sets) == 1:
        return data_sets[0]
    else:
        return data_sets[0].merge(*data_sets[1:])
Example #5
0
def load_data(resource_name, language='en'):
    # type: (Text, Optional[Text]) -> TrainingData
    """Loads training data from disk and merges them if multiple files are found."""

    files = utils.recursively_find_files(resource_name)
    data_sets = [_load(f, language) for f in files]
    # Dialogflow has files that we don't read directly, these return None
    data_sets = [ds for ds in data_sets if ds]
    if len(data_sets) == 0:
        return TrainingData()
    elif len(data_sets) == 1:
        return data_sets[0]
    else:
        return data_sets[0].merge(*data_sets[1:])
Example #6
0
def test_recursively_find_files_non_existing_dir():
    with pytest.raises(ValueError) as execinfo:
        recursively_find_files("my/made_up/path")
    assert "Could not locate the resource" in str(execinfo.value)
Example #7
0
def test_recursively_find_files_invalid_resource():
    with pytest.raises(ValueError) as execinfo:
        recursively_find_files(None)
    assert "must be an existing directory" in str(execinfo.value)
Example #8
0
def test_recursively_find_files_non_existing_dir():
    with pytest.raises(ValueError) as execinfo:
        recursively_find_files("my/made_up/path")
    assert "Could not locate the resource" in str(execinfo.value)
Example #9
0
def test_recursively_find_files_invalid_resource():
    with pytest.raises(ValueError) as execinfo:
        recursively_find_files(None)
    assert "must be an existing directory" in str(execinfo.value)