Files
PlantAI-rag/tests/test_qa_v1_1_73_natural_question_compiler.py

86 lines
3.5 KiB
Python

import inspect
from src.rag.qa_v1_1_73.natural_question_compiler import NaturalQuestionCompiler
def test_compiles_one_hop_question_from_text_only():
plan = NaturalQuestionCompiler().compile(
"which stress, treatment, hormone, or pathogen condition was DREB1A/CBF3 reported to respond to?"
)
assert plan.start_mentions == ["DREB1A/CBF3"]
assert plan.estimated_hops == 1
assert plan.answer_type == "condition"
assert "responds_to" in plan.relation_intents
def test_compiles_two_hop_for_question():
plan = NaturalQuestionCompiler().compile(
"For PCRK1, which gene or protein is linked to the gene or protein that PCRK1 was reported to interact with?"
)
assert plan.start_mentions == ["PCRK1"]
assert plan.estimated_hops == 2
assert plan.answer_type == "gene_or_protein"
assert "interacts_with" in plan.relation_intents
def test_compiles_compressed_three_hop_visible_bridges():
plan = NaturalQuestionCompiler().compile(
"K. paulula was reared in insectary cages containing pilose beggarticks. "
"What scientific name was used for this host plant?"
)
assert plan.start_mentions == ["K. paulula"]
assert plan.estimated_hops == 3
assert "insectary cages" in plan.visible_entities
assert "pilose beggarticks" in plan.visible_entities
assert plan.answer_type == "classification"
def test_compiles_four_hop_paraphrase():
plan = NaturalQuestionCompiler().compile(
"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 plan.start_mentions == ["LsWRKY68"]
assert plan.estimated_hops == 4
assert {"WRKY33", "ET", "ethylene"}.issubset(set(plan.visible_entities))
assert "homology" in plan.relation_intents
assert plan.answer_type == "phenotype"
def test_four_hop_method_question_resolves_developmental_anaphora():
question = (
"PavARF10 showed larger expression differences during flower development. "
"This developmental program was examined in grapevine cultivars transformed through an "
"Agrobacterium-mediated approach. What was this approach used to introduce?"
)
plan = NaturalQuestionCompiler().compile(question)
assert plan.visible_entities == [
"PavARF10", "flower development", "grapevine cultivars", "an Agrobacterium-mediated approach"
]
assert plan.estimated_hops == 4
def test_compiler_api_cannot_receive_benchmark_metadata():
parameters = inspect.signature(NaturalQuestionCompiler.compile).parameters
assert list(parameters) == ["self", "question"]
def test_hop_estimation_ignores_scientific_name_abbreviation_periods():
compiler = NaturalQuestionCompiler()
assert compiler.compile("which classification group was QUA2 assigned to?").estimated_hops == 1
question = (
"L. canum was reported to provide exudates from GT. "
"GT was reported to be collected by wiping leaves with acetone. "
"According to the study, what was acetone used to wash?"
)
assert compiler.compile(question).estimated_hops == 3
def test_compiles_chinese_open_ended_function_question_as_one_hop_summary():
plan = NaturalQuestionCompiler().compile("WRKY基因家族的功能有哪些")
assert plan.answer_mode == "open_ended_summary"
assert plan.answer_type == "biological_process"
assert plan.estimated_hops == 1
assert "function" in plan.relation_intents