import os import yaml # Check FinancialStatement.yaml for duplicate has_or_had_format filepath = 'schemas/20251121/linkml/modules/classes/FinancialStatement.yaml' with open(filepath, 'r') as f: lines = f.readlines() new_lines = [] seen_keys = set() in_slot_usage = False slot_usage_indent = -1 for line in lines: stripped = line.strip() indent = len(line) - len(line.lstrip()) if stripped.startswith('slot_usage:'): in_slot_usage = True slot_usage_indent = indent new_lines.append(line) continue if in_slot_usage: if stripped and indent <= slot_usage_indent: in_slot_usage = False seen_keys.clear() else: # Check for keys at level 6 (slot usage items) if indent == slot_usage_indent + 2: key = stripped.split(':')[0] if key in seen_keys: print(f"Skipping duplicate key {key} in slot_usage") # Skip this line AND subsequent lines until next key continue # This logic is too simple, need to skip block. seen_keys.add(key) new_lines.append(line) # Since simple skipping is hard line-by-line, let's use the fix_duplicate_keys.py approach again.