glam/flatten_slot_ranges.py
kempersc fc405445c6 Refactor and update schema definitions
- Removed obsolete slots: `has_or_had_custodian_observation`, `provider`, and `specificity_annotation`.
- Updated `has_or_had_score` slot to use `SpecificityScore` class and modified its description and examples.
- Added new slots: `end_seconds`, `end_time`, `has_archive_path`, `has_or_had_custodian_name`, `protocol_name`, and `protocol_version`.
- Introduced a script `check_annotation_types.py` to validate the presence and structure of `custodian_types` in YAML files.
- Added a script `update_specificity.py` to automate updates related to `SpecificityAnnotation` to `SpecificityScore`.
2026-02-01 19:55:38 +01:00

37 lines
1.3 KiB
Python

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")