mcp4rdf / test_rapid_fix.py
RDF Validation Deployment
improved
a40763c
#!/usr/bin/env python3
"""
Test script to debug the rapid fix logic with detailed step logging
"""
# Sample invalid RDF - your example
SAMPLE_INVALID_RDF = """<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:bf="http://id.loc.gov/ontologies/bibframe/">
<bf:Work rdf:about="http://example.org/work/invalid-1">
<rdf:type rdf:resource="http://id.loc.gov/ontologies/bibframe/Text"/>
<bf:title>Incomplete Title</bf:title>
</bf:Work>
</rdf:RDF>"""
# Simulated validation results (what your validation showed)
SAMPLE_VALIDATION_ERRORS = """
=== Module: MonographDCTAP/Monograph_Work_Text.tsv ===
Overridden Conforms: False
Results (4):
Validation Result:
Message: Less than 1 values on Work->bf:language
Validation Result:
Message: Less than 1 values on Work->bf:content
Validation Result:
Message: Less than 1 values on Work->bf:adminMetadata
Validation Result:
Message: Less than 1 values on Title->bf:mainTitle
"""
print("=" * 80)
print("πŸ§ͺ TESTING RAPID FIX LOGIC")
print("=" * 80)
print("\nπŸ“„ INPUT RDF:")
print(SAMPLE_INVALID_RDF)
print("\n❌ VALIDATION ERRORS:")
print(SAMPLE_VALIDATION_ERRORS)
print("\n" + "=" * 80)
print("πŸ”§ RUNNING RAPID FIX WITH DEBUG LOGGING")
print("=" * 80)
# Import the function
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
try:
from app import rapid_fix_missing_properties
steps_log = []
result = rapid_fix_missing_properties(
SAMPLE_INVALID_RDF,
SAMPLE_VALIDATION_ERRORS,
'monograph',
steps_log=steps_log
)
print("\nπŸ“‹ STEP-BY-STEP LOG:")
print("-" * 80)
for step in steps_log:
print(step)
print("\n" + "=" * 80)
if result:
print("βœ… RAPID FIX PRODUCED OUTPUT:")
print("=" * 80)
print(result)
print("\n" + "=" * 80)
print("πŸ” ANALYSIS:")
print("=" * 80)
# Check what was added
if "<bf:language>" in result and "<bf:language>" not in SAMPLE_INVALID_RDF:
print("βœ… Added bf:language")
if "<bf:content>" in result and "<bf:content>" not in SAMPLE_INVALID_RDF:
print("βœ… Added bf:content")
if "<bf:adminMetadata>" in result and "<bf:adminMetadata>" not in SAMPLE_INVALID_RDF:
print("βœ… Added bf:adminMetadata")
# Check if it has assigner
if "<bf:assigner>" in result:
print(" βœ… AdminMetadata includes bf:assigner")
else:
print(" ❌ AdminMetadata MISSING bf:assigner!")
else:
print("❌ RAPID FIX RETURNED None")
print("=" * 80)
except Exception as e:
print(f"\n❌ ERROR: {e}")
import traceback
traceback.print_exc()