import os SCHEMA_DIR = "/Users/kempersc/apps/glam/schemas/20251121/linkml/modules/classes/" DUAL_CLASS_FILES = [ "IconographicArchives.yaml", "ReligiousArchive.yaml", "FoundationArchiveRecordSetType.yaml", "BankArchiveRecordSetType.yaml", "ArchivesForBuildingRecordsRecordSetType.yaml", "PressArchive.yaml", "PhotoArchiveRecordSetType.yaml", "MuseumArchiveRecordSetType.yaml", "NotarialArchiveRecordSetType.yaml", "ProvincialArchive.yaml", "SectorOfArchivesInSwedenRecordSetType.yaml", "AudiovisualArchive.yaml", "MediaArchive.yaml", "FreeArchive.yaml", "MuseumArchive.yaml" ] def remove_dual_class_link(filename): filepath = os.path.join(SCHEMA_DIR, filename) if not os.path.exists(filepath): print(f"File not found: {filename}") return print(f"Processing {filename}...") try: with open(filepath, 'r') as f: lines = f.readlines() new_lines = [] skip_block = False block_indent = 0 for line in lines: stripped = line.strip() # Remove imports if "dual_class_link" in stripped and stripped.startswith("-"): # Check if it's an import or a slot list item # Imports usually look like "- ../slots/dual_class_link" # Slots list looks like " - dual_class_link" continue # Remove references to class if "DualClassLink" in stripped and stripped.startswith("-"): continue # Remove slot usage key if stripped == "dual_class_link:": skip_block = True block_indent = len(line) - len(line.lstrip()) continue if skip_block: current_indent = len(line) - len(line.lstrip()) if current_indent > block_indent: continue else: skip_block = False new_lines.append(line) with open(filepath, 'w') as f: f.writelines(new_lines) except Exception as e: print(f"Error processing {filename}: {e}") if __name__ == "__main__": for f in DUAL_CLASS_FILES: remove_dual_class_link(f)