124 lines
4.1 KiB
Python
124 lines
4.1 KiB
Python
from src.rag.qa_v1_1_73.claim_context import build_claim_context
|
|
from src.rag.qa_v1_1_73.schemas import EvidenceItem
|
|
|
|
|
|
def evidence(**overrides) -> EvidenceItem:
|
|
values = {
|
|
"evidence_id": "S1",
|
|
"kb": "V16/V15",
|
|
"source": "WRKY",
|
|
"relation": "participates_in",
|
|
"target": "stress response",
|
|
"evidence": "WRKY proteins participate in stress responses.",
|
|
}
|
|
values.update(overrides)
|
|
return EvidenceItem(**values)
|
|
|
|
|
|
def test_explicit_species_in_evidence_is_claim_species():
|
|
item = evidence(
|
|
source="AtRALF1",
|
|
relation="inhibits",
|
|
target="root growth",
|
|
evidence="In Arabidopsis thaliana, AtRALF1 inhibits root growth.",
|
|
species="Arabidopsis thaliana",
|
|
)
|
|
context = build_claim_context(item)
|
|
assert context.claim_species == ["Arabidopsis thaliana"]
|
|
assert context.species_source == "evidence"
|
|
|
|
|
|
def test_title_species_is_paper_context_not_claim_species():
|
|
item = evidence(
|
|
title="WRKY transcription factors in Juglans regia",
|
|
evidence="WRKY proteins participate in stress responses.",
|
|
species="Carya illinoinensis",
|
|
)
|
|
context = build_claim_context(item)
|
|
assert context.claim_species == []
|
|
assert context.paper_species == []
|
|
assert context.species_source == "none"
|
|
|
|
|
|
def test_unvalidated_free_text_species_are_not_promoted():
|
|
item = evidence(
|
|
evidence="RALF genes were examined in Solanum lycopersicum and Oryza sativa."
|
|
)
|
|
context = build_claim_context(item)
|
|
assert context.claim_species == []
|
|
|
|
|
|
def test_context_keeps_srt_components_separate():
|
|
item = evidence(
|
|
source="AtRALF1",
|
|
relation="inhibits",
|
|
target="root growth",
|
|
evidence="In Arabidopsis thaliana, AtRALF1 inhibits root growth.",
|
|
)
|
|
context = build_claim_context(item)
|
|
assert context.subject == "AtRALF1"
|
|
assert context.function_or_process == "root growth"
|
|
assert context.direction == "inhibits"
|
|
|
|
|
|
def test_ordinary_capitalized_english_words_are_not_species():
|
|
context = build_claim_context(
|
|
evidence(evidence="They play multiple roles in plant development.")
|
|
)
|
|
assert context.claim_species == []
|
|
|
|
|
|
def test_genus_only_context_does_not_turn_leading_words_into_species():
|
|
context = build_claim_context(
|
|
evidence(evidence="Their involvement in Arabidopsis has been investigated.")
|
|
)
|
|
assert context.claim_species == []
|
|
|
|
|
|
def test_full_wrky_title_extracts_only_parenthetical_scientific_name():
|
|
context = build_claim_context(
|
|
evidence(
|
|
title=(
|
|
"Genome-Wide Identification and Transcriptional Expression Profiles "
|
|
"of Transcription Factor WRKY in Common Walnut (Juglans regia L.)"
|
|
)
|
|
)
|
|
)
|
|
assert context.paper_species == ["Juglans regia"]
|
|
assert "Identification and" not in context.paper_species
|
|
|
|
|
|
def test_conflicting_raw_species_is_not_promoted_without_evidence_corroboration():
|
|
context = build_claim_context(
|
|
evidence(
|
|
title="WRKY transcription factors in Juglans regia",
|
|
evidence="WRKY proteins participate in stress responses.",
|
|
species="Carya illinoinensis",
|
|
)
|
|
)
|
|
assert context.claim_species == []
|
|
assert context.paper_species == []
|
|
|
|
|
|
def test_structured_species_must_be_a_valid_two_token_scientific_name():
|
|
item = evidence(
|
|
evidence="Plant development was examined during stress.",
|
|
species="Plant development",
|
|
)
|
|
assert build_claim_context(item).claim_species == []
|
|
|
|
|
|
def test_free_text_scientific_shapes_are_not_species_without_validation():
|
|
for text in (
|
|
"The genes act in Plant development.",
|
|
"Expression changes occurred in Tomato fruit.",
|
|
"The family contributes to regulation of Root growth.",
|
|
"The pathway depends on signalling of Plant hormones.",
|
|
"The phenotype involved <i>plant growth</i>.",
|
|
):
|
|
assert build_claim_context(evidence(evidence=text)).claim_species == []
|
|
|
|
|
|
def test_arbitrary_title_pair_is_not_paper_species():
|
|
assert build_claim_context(evidence(title="Transcription factors")).paper_species == []
|