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)
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))
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))
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:])
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:])
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)
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)
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)
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)