import os import yaml def flatten_ranges(path): with open(path, 'r') as f: lines = f.readlines() new_lines = [] primitives = ["string", "integer", "float", "boolean", "date", "datetime", "uriorcurie", "uri", "ncname", "objectidentifier", "time", "decimal", "double"] modified = False for line in lines: stripped = line.strip() if stripped.startswith("range:") and ":" in stripped: parts = stripped.split(":") if len(parts) >= 2: range_val = parts[1].strip() if range_val not in primitives and not range_val.startswith("string"): # handle string(...) print(f"Flattening range in {path}: {range_val} -> uriorcurie") new_lines.append(f" range: uriorcurie\n") new_lines.append(f" # range: {range_val}\n") modified = True continue new_lines.append(line) if modified: with open(path, 'w') as f: f.writelines(new_lines) def process_directory(directory): for root, dirs, files in os.walk(directory): for file in files: if file.endswith(".yaml"): flatten_ranges(os.path.join(root, file)) process_directory("schemas/20251121/linkml/modules/slots")