def METHOD_NAME(entity, name, pattern, level, directory=False):
    if directory and entity not in DIR_ENTITIES:
        return ""
    label = _capture_regex(entity, pattern, not directory and entity in DIR_ENTITIES)
    post = "/" if directory else "_"
    return _optional_regex(f"{name}-{label}{post}", level != "required")