Beispiel #1
0
def is_nlu_file(file_path: Text) -> bool:
    """Checks if a file is a Rasa compatible nlu file.

    Args:
        file_path: Path of the file which should be checked.

    Returns:
        `True` if it's a nlu file, otherwise `False`.
    """
    return loading.guess_format(file_path) != loading.UNK
 def _get_train_files_cmd():
     """Get the raw train data by fetching the train file given in the
     command line arguments to the train script. When training the NLU model
     explicitly, the training data will be in the "nlu" argument, otherwise
     it will be in the "data" argument.
     """
     cmdline_args = create_argument_parser().parse_args()
     try:
         files = list_files(cmdline_args.nlu)
     except AttributeError:
         files = list(get_core_nlu_files(cmdline_args.data)[1])
     return [file for file in files if guess_format(file) == RASA_NLU]
Beispiel #3
0
def get_file_format(resource_name: Text) -> Text:
    from rasa.nlu.training_data import loading

    if resource_name is None or not os.path.exists(resource_name):
        raise AttributeError(f"Resource '{resource_name}' does not exist.")

    files = io_utils.list_files(resource_name)

    file_formats = list(map(lambda f: loading.guess_format(f), files))

    if not file_formats:
        return "json"

    fformat = file_formats[0]
    if fformat == "md" and all(f == fformat for f in file_formats):
        return fformat

    return "json"
Beispiel #4
0
def test_guess_format_from_non_existing_file_path():
    assert guess_format("not existing path") == UNK
Beispiel #5
0
def _is_nlu_file(file_path: Text) -> bool:
    """Checks whether a file is an NLU file."""
    return loading.guess_format(file_path) != loading.UNK