glam/check_annotation_types.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

50 lines
2.1 KiB
Python

import yaml
import os
def check_file(path):
try:
with open(path, 'r') as f:
data = yaml.safe_load(f)
except Exception as e:
print(f"Error parsing {path}: {e}")
return
if 'classes' in data:
for class_name, class_def in data['classes'].items():
if 'custodian_types' in class_def:
print(f"Misplaced custodian_types found in {path} Class {class_name} (root level)")
if 'slot_usage' in class_def and class_def['slot_usage']:
for slot_name, slot_def in class_def['slot_usage'].items():
if slot_def and 'custodian_types' in slot_def:
print(f"Misplaced custodian_types found in {path} Class {class_name} SlotUsage {slot_name}")
if 'annotations' in class_def:
ann = class_def['annotations']
if ann and 'custodian_types' in ann:
val = ann['custodian_types']
if isinstance(val, list):
print(f"List value found in {path} Class {class_name}: {val}")
elif not isinstance(val, str):
print(f"Non-string value found in {path} Class {class_name}: {val} (type: {type(val)})")
if 'slots' in data:
for slot_name, slot_def in data['slots'].items():
if 'custodian_types' in slot_def:
print(f"Misplaced custodian_types found in {path} Slot {slot_name} (root level)")
if 'annotations' in slot_def:
ann = slot_def['annotations']
if ann and 'custodian_types' in ann:
val = ann['custodian_types']
if isinstance(val, list):
print(f"List value found in {path} Slot {slot_name}: {val}")
def process_directory(directory):
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(".yaml"):
check_file(os.path.join(root, file))
process_directory("schemas/20251121/linkml/modules/classes")
process_directory("schemas/20251121/linkml/modules/slots")