Files
PlantAI-rag/tests/test_qa_v1_1_73_natural_constrained_paths.py

59 lines
2.5 KiB
Python

from src.rag.qa_v1_1_73.graph_path_chain import NativeGraphPathRetriever
def test_natural_three_hop_question_compiles_visible_pairs_and_terminal():
question = (
"K. paulula was reared in insectary cages containing pilose beggarticks. "
"What scientific name was used for this host plant?"
)
pairs, terminal = NativeGraphPathRetriever._question_chain_spec(question)
assert pairs == [("k paulula", "insectary cages"), ("insectary cages", "pilose beggarticks")]
assert terminal == ("pilose beggarticks", "__classification__")
def test_generic_four_hop_question_compiles_repeated_visible_entities():
question = (
"GeneA was reported to interact with ProteinB. "
"ProteinB was reported to regulate ProcessC. "
"ProcessC was reported to occur in TissueD. "
"According to the study, what did TissueD contain?"
)
pairs, terminal = NativeGraphPathRetriever._question_chain_spec(question)
assert pairs == [("genea", "proteinb"), ("proteinb", "processc"), ("processc", "tissued")]
assert terminal == ("tissued", "contains")
def test_one_hop_natural_question_compiles_terminal_relation():
pairs, terminal = NativeGraphPathRetriever._question_chain_spec(
"which condition was DREB1A/CBF3 reported to respond to?"
)
assert pairs == []
assert terminal == ("dreb1a cbf3", "responds_to")
def test_explicit_verb_is_preferred_over_broad_condition_type():
_, terminal = NativeGraphPathRetriever._question_chain_spec(
"which stress, treatment, hormone, or pathogen condition was DREB1A/CBF3 reported to respond to?"
)
assert terminal == ("dreb1a cbf3", "responds_to")
def test_floral_outcome_compiles_to_phenotype_terminal():
_, terminal = NativeGraphPathRetriever._question_chain_spec(
"LsWRKY68 is homologous to WRKY33, which operates where antagonistic pathways involving ET intersect. "
"After resolving ET as ethylene, which floral outcome was attributed to this hormone?"
)
assert terminal == ("ethylene", "__phenotype__")
def test_entity_name_variants_include_safe_singular_form():
assert NativeGraphPathRetriever._name_variants(["insectary cages", "SOS2"]) == [
"insectary cages", "insectary cage", "sos2"
]
def test_method_approach_gets_a_conservative_graph_alias():
assert NativeGraphPathRetriever._name_variants(["an Agrobacterium-mediated approach"]) == [
"an agrobacterium mediated approach", "agrobacterium mediated transformation"
]