#!/usr/bin/env python3
"""
Standalone test for rapid_fix_missing_properties - no dependencies
"""
import re
from typing import Optional, List
# Sample invalid RDF
SAMPLE_INVALID_RDF = """
Incomplete Title
"""
# Validation errors
SAMPLE_VALIDATION_ERRORS = """
=== Module: MonographDCTAP/Monograph_Work_Text.tsv ===
Message: Less than 1 values on Work->bf:language
Message: Less than 1 values on Work->bf:content
Message: Less than 1 values on Work->bf:adminMetadata
"""
# Copy of the rapid_fix function
def rapid_fix_missing_properties(rdf_content: str, validation_results: str, template: str, steps_log: Optional[List[str]] = None) -> Optional[str]:
"""Ultra-fast fix for simple missing property errors - no AI needed."""
# Quick pattern match for missing properties
missing = re.findall(r"Less than \d+ values on.*->bf:(\w+)", validation_results)
if not missing:
if steps_log:
steps_log.append("โ Rapid fix: No missing properties detected in validation results")
return None
if steps_log:
steps_log.append(f"๐ Rapid fix detected {len(missing)} missing properties: {', '.join(set(missing))}")
# Pre-compiled property templates
INSTANT_FIXES = {
"title": 'Untitled',
"language": 'Englisheng',
"content": 'texttxt',
"adminMetadata": '''
new
n
2024-01-01
Library of Congress
Library of Congress
''',
}
# Find insertion point
work_match = re.search(r'(]*>)(.*?)()', rdf_content, re.DOTALL)
instance_match = re.search(r'(]*>)(.*?)()', rdf_content, re.DOTALL)
if not work_match and not instance_match:
if steps_log:
steps_log.append("โ Rapid fix: No bf:Work or bf:Instance found in RDF")
return None
match = work_match or instance_match
target_type = "Work" if work_match else "Instance"
opening_tag = match.group(1)
content = match.group(2)
closing_tag = match.group(3)
if steps_log:
steps_log.append(f"๐ Rapid fix target: bf:{target_type}")
has_admin = "" in content or "" in content
steps_log.append(f"๐ Current state: AdminMetadata {'EXISTS' if has_admin else 'MISSING'}")
# Build fixes
fixes = []
for prop in missing[:10]:
prop_lower = prop.lower()
if steps_log:
steps_log.append(f"๐ Processing property: '{prop}' (lowercase: '{prop_lower}')")
steps_log.append(f" Check: Is '{prop_lower}' in INSTANT_FIXES? {prop_lower in INSTANT_FIXES}")
steps_log.append(f" Check: Is '" in result:
print("โ
Added bf:language")
if "" in result:
print("โ
Added bf:content")
if "" in result:
print("โ
Added bf:adminMetadata")
if "" in result:
print(" โ
AdminMetadata includes bf:assigner")
else:
print(" โ AdminMetadata MISSING bf:assigner!")
else:
print("โ RAPID FIX RETURNED None")