File size: 2,841 Bytes
a40763c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
#!/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()
|