- Added `id`, `name`, `title`, and `description` fields to multiple LinkML class YAML files. - Standardized prefixes across all class definitions. - Introduced a new script `fix_linkml_metadata.py` to automate the addition of metadata to class files. - Updated existing class files to ensure compliance with the new metadata structure.
85 lines
3 KiB
Python
85 lines
3 KiB
Python
import os
|
|
import re
|
|
|
|
# Directory containing class files
|
|
CLASSES_DIR = "/Users/kempersc/apps/glam/schemas/20251121/linkml/modules/classes/"
|
|
|
|
# Fix for was_generated_by
|
|
def fix_was_generated_by(filepath):
|
|
print(f"Checking {filepath} for was_generated_by...")
|
|
try:
|
|
with open(filepath, 'r') as f:
|
|
content = f.read()
|
|
|
|
new_content = content
|
|
|
|
# Replace usage in slots list
|
|
# - was_generated_by -> - is_or_was_generated_by
|
|
new_content = re.sub(r"(\s+)-\s+was_generated_by\n", r"\1- is_or_was_generated_by\n", new_content)
|
|
|
|
# Replace slot usage keys
|
|
# was_generated_by: -> is_or_was_generated_by:
|
|
new_content = re.sub(r"(\s+)was_generated_by:", r"\1is_or_was_generated_by:", new_content)
|
|
|
|
# Replace imports
|
|
# - ../slots/was_generated_by -> - ../slots/is_or_was_generated_by
|
|
new_content = new_content.replace("- ../slots/was_generated_by", "- ../slots/is_or_was_generated_by")
|
|
|
|
# Fix inline descriptions
|
|
new_content = new_content.replace("`was_generated_by`", "`is_or_was_generated_by`")
|
|
new_content = new_content.replace("was_generated_by link", "is_or_was_generated_by link")
|
|
|
|
if new_content != content:
|
|
print(f"Updating {filepath}...")
|
|
with open(filepath, 'w') as f:
|
|
f.write(new_content)
|
|
|
|
except Exception as e:
|
|
print(f"Error processing {filepath}: {e}")
|
|
|
|
# Fix for was_last_updated_at -> is_or_was_last_updated_at
|
|
def fix_was_last_updated_at(filepath):
|
|
print(f"Checking {filepath} for was_last_updated_at...")
|
|
try:
|
|
with open(filepath, 'r') as f:
|
|
content = f.read()
|
|
|
|
new_content = content
|
|
|
|
# Replace usage in slots list
|
|
new_content = re.sub(r"(\s+)-\s+was_last_updated_at\n", r"\1- is_or_was_last_updated_at\n", new_content)
|
|
|
|
# Replace slot usage keys
|
|
new_content = re.sub(r"(\s+)was_last_updated_at:", r"\1is_or_was_last_updated_at:", new_content)
|
|
|
|
# Replace imports
|
|
new_content = new_content.replace("- ../slots/was_last_updated_at", "- ../slots/is_or_was_last_updated_at")
|
|
|
|
# Fix inline descriptions
|
|
new_content = new_content.replace("`was_last_updated_at`", "`is_or_was_last_updated_at`")
|
|
|
|
if new_content != content:
|
|
print(f"Updating {filepath}...")
|
|
with open(filepath, 'w') as f:
|
|
f.write(new_content)
|
|
|
|
except Exception as e:
|
|
print(f"Error processing {filepath}: {e}")
|
|
|
|
# Get all class files
|
|
def get_class_files():
|
|
files = []
|
|
for root, _, filenames in os.walk(CLASSES_DIR):
|
|
for filename in filenames:
|
|
if filename.endswith(".yaml"):
|
|
files.append(os.path.join(root, filename))
|
|
return files
|
|
|
|
def main():
|
|
files = get_class_files()
|
|
for f in files:
|
|
fix_was_generated_by(f)
|
|
fix_was_last_updated_at(f)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|