1
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from crawler_platform.app.config.loader import ProjectConfig
|
||||
from crawler_platform.app.api.routes import extraction_log_summary
|
||||
from crawler_platform.app.core.extractor.base import ExtractedClaim, ExtractionBundle, ExtractionPageContext
|
||||
from crawler_platform.app.core.extractor.hybrid import HybridExtractor, mark_bundle, merge_bundles
|
||||
from crawler_platform.app.core.extractor.hybrid import HybridExtractor, fallback_bundle, mark_bundle, merge_bundles
|
||||
from crawler_platform.app.core.extractor.validation import validate_extraction_bundle
|
||||
|
||||
|
||||
@@ -142,3 +143,61 @@ def test_hybrid_smart_routing_skips_llm_for_category_page() -> None:
|
||||
assert bundle.raw_output["llm_skipped"] is True
|
||||
assert bundle.raw_output["effective_extraction_mode"] == "rule_only"
|
||||
assert "CategoryPage" in bundle.raw_output["llm_skip_reason"]
|
||||
|
||||
|
||||
def test_rule_only_mode_records_rule_llm_summary_counts() -> None:
|
||||
rule_bundle = ExtractionBundle(
|
||||
claims=[
|
||||
ExtractedClaim("A", "Thing", "color", object_value="red"),
|
||||
ExtractedClaim("A", "Thing", "size", object_value="large"),
|
||||
]
|
||||
)
|
||||
|
||||
class FixedRuleExtractor:
|
||||
def extract(self, page_text, project_config): # noqa: ANN001
|
||||
return rule_bundle
|
||||
|
||||
def extract_from_context(self, context, project_config): # noqa: ANN001
|
||||
return rule_bundle
|
||||
|
||||
extractor = HybridExtractor("generic", mode="rule_only")
|
||||
extractor.rule_extractor = FixedRuleExtractor()
|
||||
|
||||
bundle = extractor.extract("Alpha color red size large", project_config())
|
||||
|
||||
assert bundle.raw_output["rule_claim_count"] == 2
|
||||
assert bundle.raw_output["llm_claim_count"] == 0
|
||||
assert bundle.raw_output["comparison"]["rule_only"] == 2
|
||||
|
||||
|
||||
def test_fallback_records_rule_counts_and_comparison() -> None:
|
||||
rule_bundle = ExtractionBundle(
|
||||
claims=[
|
||||
ExtractedClaim("A", "Thing", "color", object_value="red"),
|
||||
ExtractedClaim("A", "Thing", "size", object_value="large"),
|
||||
]
|
||||
)
|
||||
mark_bundle(rule_bundle, source="rule", mode="hybrid")
|
||||
|
||||
bundle = fallback_bundle(rule_bundle, HybridExtractor("generic", mode="hybrid"), RuntimeError("boom"))
|
||||
|
||||
assert bundle.raw_output["rule_claim_count"] == 2
|
||||
assert bundle.raw_output["llm_claim_count"] == 0
|
||||
assert bundle.raw_output["comparison"]["rule_only"] == 2
|
||||
|
||||
|
||||
def test_extraction_log_summary_backfills_legacy_rule_only_counts() -> None:
|
||||
summary = extraction_log_summary(
|
||||
{
|
||||
"validation": {"rejected_claim_count": 4},
|
||||
"candidate_claims": [
|
||||
{"metadata": {"agreement": "rule_only", "extraction_source": "rule"}},
|
||||
{"metadata": {"agreement": "rule_only", "extraction_source": "rule"}},
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
assert summary["rule_claim_count"] == 2
|
||||
assert summary["llm_claim_count"] == 0
|
||||
assert summary["comparison"]["rule_only"] == 2
|
||||
assert summary["comparison"]["rejected_by_validation"] == 4
|
||||
|
||||
Reference in New Issue
Block a user