63 lines
1.8 KiB
Python
63 lines
1.8 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""Phase 0 extraction test."""
|
||
|
|
|
||
|
|
import sys
|
||
|
|
import time
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
sys.path.insert(0, str(Path(__file__).parent / "ontology_platform"))
|
||
|
|
|
||
|
|
from ont_platform.core.extractors.web_extractor import extract_web_content
|
||
|
|
from ont_platform.core.extraction.lightweight_extractor import LightweightExtractor
|
||
|
|
|
||
|
|
|
||
|
|
def test_extraction(url: str):
|
||
|
|
"""Test Phase 0 extraction."""
|
||
|
|
print(f"\nURL: {url}\n")
|
||
|
|
|
||
|
|
start = time.time()
|
||
|
|
|
||
|
|
try:
|
||
|
|
print("1. Extracting content with Trafilatura...")
|
||
|
|
extracted = extract_web_content(url=url)
|
||
|
|
print(f" Title: {extracted.title}")
|
||
|
|
print(f" Length: {len(extracted.text)} chars")
|
||
|
|
|
||
|
|
print("\n2. Extracting JSON candidates...")
|
||
|
|
extractor = LightweightExtractor(use_llm=False)
|
||
|
|
result = extractor.extract(
|
||
|
|
text=extracted.text,
|
||
|
|
project_id="test",
|
||
|
|
document_id="test",
|
||
|
|
)
|
||
|
|
|
||
|
|
elapsed = time.time() - start
|
||
|
|
|
||
|
|
print(f" Entities: {len(result.entities)}")
|
||
|
|
print(f" Relations: {len(result.relations)}")
|
||
|
|
print(f" Time: {elapsed:.2f}s")
|
||
|
|
|
||
|
|
if result.entities:
|
||
|
|
print(f"\n Top entities:")
|
||
|
|
for e in result.entities[:3]:
|
||
|
|
print(f" - {e['label']} ({e['type']}) [{e['confidence']}]")
|
||
|
|
|
||
|
|
if elapsed <= 30:
|
||
|
|
print(f"\nSUCCESS: {elapsed:.2f}s <= 30s target")
|
||
|
|
return True
|
||
|
|
else:
|
||
|
|
print(f"\nFAIL: {elapsed:.2f}s > 30s target")
|
||
|
|
return False
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
print(f"ERROR: {e}")
|
||
|
|
import traceback
|
||
|
|
traceback.print_exc()
|
||
|
|
return False
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
url = sys.argv[1] if len(sys.argv) > 1 else "https://example.com"
|
||
|
|
success = test_extraction(url)
|
||
|
|
sys.exit(0 if success else 1)
|