File size: 2,543 Bytes
0e0e2c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from __future__ import annotations

from copy import deepcopy
from typing import Any


_FIELD_VERIFICATION_NOTE = (
    "No disease-specific claim for this field has been verified in the "
    "project source registry. Local agricultural review is required."
)

_EXPERT_REVIEW_NOTE = (
    "Ask a local agricultural expert to verify the image and field conditions "
    "before taking disease-specific action."
)

_SOURCE_BY_LABEL = {
    "Wheat___Brown_Rust": ["SRC-005"],
    "Wheat___Yellow_Rust": ["SRC-005"],
}

_SUPPORTED_LABELS = {
    "Corn___Common_Rust": ("Common rust", "corn"),
    "Corn___Gray_Leaf_Spot": ("Gray leaf spot", "corn"),
    "Rice___Brown_Spot": ("Brown spot", "rice"),
    "Rice___Leaf_Blast": ("Leaf blast", "rice"),
    "Wheat___Brown_Rust": ("Brown rust", "wheat"),
    "Wheat___Yellow_Rust": ("Yellow rust", "wheat"),
}


def _field(items: list[str], source_ids: list[str]) -> dict[str, Any]:
    return {
        "items": list(items),
        "provenance_status": "local_verification_required",
        "sources": list(source_ids),
    }


def _entry(label: str, disease_name: str, crop: str) -> dict[str, Any]:
    source_ids = _SOURCE_BY_LABEL.get(label, [])
    return {
        "label": label,
        "disease_name": disease_name,
        "crop": crop,
        "evidence_status": "local_verification_required",
        "symptoms": _field([_FIELD_VERIFICATION_NOTE], source_ids),
        "possible_lookalikes": _field([_FIELD_VERIFICATION_NOTE], source_ids),
        "favourable_conditions": _field([_FIELD_VERIFICATION_NOTE], source_ids),
        "prevention": _field([_FIELD_VERIFICATION_NOTE], source_ids),
        "immediate_safe_actions": _field([_FIELD_VERIFICATION_NOTE], source_ids),
        "when_to_contact_expert": _field([_EXPERT_REVIEW_NOTE], source_ids),
        "evidence_note": (
            "The source registry currently verifies only institutional "
            "diagnostic/advisory context for these entries, not the "
            "disease-specific claims above."
        ),
    }


_KNOWLEDGE_BASE = {
    label: _entry(label, disease_name, crop)
    for label, (disease_name, crop) in _SUPPORTED_LABELS.items()
}


def get_disease_knowledge(label: Any) -> dict[str, Any] | None:
    """Return a defensive copy of structured evidence-aware disease knowledge."""
    if not isinstance(label, str):
        return None
    entry = _KNOWLEDGE_BASE.get(label)
    return deepcopy(entry) if entry is not None else None