# JAIM — Vrikshayurveda Rules Update # Grounded in actual Surapala text (all 9 disorder entries) > **How to use this file:** > This file REPLACES the previous hardcoded rule base with rules derived > directly from the Vrikshayurveda disorder table (Surapala, translated by > Sadhale 1996, as cited in the IEEE paper in the project database). > Follow each phase in order. Do not skip phases. > The YAML and JS must stay in sync — the YAML is always the source of truth. --- ## What changed and why The previous 20 rules were illustrative seed rules. This update replaces them with rules extracted directly from the 9 Vrikshayurveda disorder entries: 1. Internal Vata disorder 2. Internal Kapha disorder 3. Internal Pitta disorder 4. External — Scorching heat / Frost (insect-root damage) 5. External — Excessive stormy winds 6. External — Fire / Lightning / Soil aridity / Water stress 7. External — Struck by axe or mechanical wound 8. Faulty seed disorder 9. Ants / insects infestation 10. Excessive watering disorder The symptom keywords, fact vocabulary, rule conditions, conclusions, and treatment recommendations are all derived from the actual text — not invented. --- ## Phase 1 — Replace vrikshayurveda_rules.yaml **File:** `vrikshayurveda_rules.yaml` **Action:** Delete the entire file and replace with the content below. ```yaml rules: # ── INTERNAL VATA DISORDER ────────────────────────────────────────────── - id: R001 name: "Trunk bent + knots → internal Vata disorder" source: vrikshayurveda priority: 10 conditions: [trunk_bent, knots_on_trunk] conclusions: [internal_vata_disorder] dosha: vata explanation: > Bent trunk with knots are primary Vata symptoms — disturbed Vata governs movement and structural integrity in Vrikshayurveda. - id: R002 name: "Yellowing + fruit loss → internal Vata disorder" source: vrikshayurveda priority: 10 conditions: [general_yellowing, flower_fruit_loss] conclusions: [internal_vata_disorder] dosha: vata explanation: > General yellowing of leaves and fruits combined with flower and fruit loss indicates internal Vata imbalance from arid soil conditions. - id: R003 name: "Hard fruits + slow defoliation → internal Vata disorder" source: vrikshayurveda priority: 9 conditions: [hard_fruits, slow_defoliation] conclusions: [internal_vata_disorder] dosha: vata explanation: > Hard less-juicy fruits and slow defoliation are Vata symptoms caused by root-infecting fungi, nematodes, or saline soils. - id: R004 name: "Internal Vata → arid soil cause" source: vrikshayurveda priority: 8 conditions: [internal_vata_disorder] conclusions: [arid_soil_cause] dosha: vata explanation: > Vrikshayurveda identifies arid land as the primary cause of internal Vata — roots stressed by dry or saline soil. - id: R005 name: "Internal Vata → recommend panchmula decoction" source: vrikshayurveda priority: 7 conditions: [internal_vata_disorder] conclusions: [recommend_panchmula_decoction] dosha: none explanation: > Panchmula (five-root preparation) decoction is the classical Vrikshayurveda treatment for internal Vata disorder. - id: R006 name: "Internal Vata → recommend fermented fat decoction" source: vrikshayurveda priority: 7 conditions: [internal_vata_disorder] conclusions: [recommend_fermented_fat_decoction] dosha: none explanation: > Fermented mixture of hog fat, porpoise oil, ghee, hemp, horsehair, and cow horn boiled to decoction is the primary Vata treatment. # ── INTERNAL KAPHA DISORDER ───────────────────────────────────────────── - id: R007 name: "Delayed fruiting + bland overripe fruits → internal Kapha disorder" source: vrikshayurveda priority: 10 conditions: [delayed_fruiting, bland_overripe_fruits] conclusions: [internal_kapha_disorder] dosha: kapha explanation: > Delayed bearing with bland overripe fruits signals Kapha excess — associated with fungal gummosis, rot, or excessive watering. - id: R008 name: "Oozing without injury → internal Kapha disorder" source: vrikshayurveda priority: 9 conditions: [oozing_without_injury] conclusions: [internal_kapha_disorder] dosha: kapha explanation: > Spontaneous oozing from bark without physical damage is a hallmark Kapha symptom indicating gummosis or internal rot. - id: R009 name: "Internal Kapha + winter/spring → fungal root rot cause" source: vrikshayurveda priority: 10 conditions: [internal_kapha_disorder, winter_spring_season] conclusions: [fungal_rot_cause, excessive_moisture_cause] dosha: kapha explanation: > Kapha disorders appearing in winter and spring are caused by fungal gummosis, nutrient deficiency, or excessive watering. - id: R010 name: "Internal Kapha → recommend white mustard paste" source: vrikshayurveda priority: 7 conditions: [internal_kapha_disorder] conclusions: [recommend_white_mustard_paste_roots] dosha: none explanation: > White mustard paste applied at the roots is the primary Vrikshayurveda treatment for Kapha disorder. - id: R011 name: "Internal Kapha → recommend sesame ash water + soil replacement" source: vrikshayurveda priority: 7 conditions: [internal_kapha_disorder] conclusions: [recommend_sesame_ash_water, recommend_fresh_dry_soil] dosha: none explanation: > Watering with sesame-and-ash mixture followed by replacing root soil with fresh dry earth removes Kapha excess and excess moisture. # ── INTERNAL PITTA DISORDER ───────────────────────────────────────────── - id: R012 name: "Early leaf withering → internal Pitta disorder" source: vrikshayurveda priority: 10 conditions: [early_leaf_withering] conclusions: [internal_pitta_disorder] dosha: pitta explanation: > Early withering of leaves before season indicates excess Pitta heat — caused by viral disease, salinity in irrigation water, or blight. - id: R013 name: "Early fruit/flower decay → internal Pitta disorder" source: vrikshayurveda priority: 10 conditions: [early_fruit_flower_decay] conclusions: [internal_pitta_disorder] dosha: pitta explanation: > Premature decay of fruits or flowers is a Pitta symptom occurring at end of summer, linked to blossom blight and fungal infection. - id: R014 name: "Internal Pitta + end of summer → heat-fungal cause" source: vrikshayurveda priority: 10 conditions: [internal_pitta_disorder, end_of_summer] conclusions: [heat_fungal_cause, salinity_cause] dosha: pitta explanation: > Pitta disorders at end of summer are caused by viral disease, salinity in irrigation water, and susceptibility to fungal blight. - id: R015 name: "Internal Pitta → recommend triphala ghee honey decoction" source: vrikshayurveda priority: 7 conditions: [internal_pitta_disorder] conclusions: [recommend_triphala_ghee_honey] dosha: none explanation: > Watering with triphala, ghee, and honey decoction is the primary Vrikshayurveda treatment for Pitta disorder. - id: R016 name: "Internal Pitta → recommend milk honey yastamdhu madhuka" source: vrikshayurveda priority: 7 conditions: [internal_pitta_disorder] conclusions: [recommend_milk_honey_yastamdhu_madhuka] dosha: none explanation: > Watering with decoction of milk, honey, yastamdhu, and madhuka is the secondary Vrikshayurveda cooling treatment for Pitta. # ── EXTERNAL: SCORCHING HEAT / FROST / INSECT ROOT DAMAGE ─────────────── - id: R017 name: "Yellowing + Vata-like symptoms → heat or frost external cause" source: vrikshayurveda priority: 9 conditions: [general_yellowing, vata_like_symptoms] conclusions: [external_heat_frost_disorder] dosha: none explanation: > Leaf yellowing with Vata-like symptoms but no internal Vata cause indicates external scorching heat, frost, or insect root damage. - id: R018 name: "External heat/frost → roots eaten by insects cause" source: vrikshayurveda priority: 8 conditions: [external_heat_frost_disorder] conclusions: [insect_root_damage_cause, water_stress_cause] dosha: none explanation: > External heat or frost disorders are caused by water stress predisposing trees to attack by pathogens and root-eating insects. - id: R019 name: "External heat/frost → recommend cold water treatment 7 days" source: vrikshayurveda priority: 7 conditions: [external_heat_frost_disorder] conclusions: [recommend_cold_water_7days] dosha: none explanation: > Insects can be removed by cold water treatment for seven days — the primary Vrikshayurveda remedy for external heat/frost disorder. - id: R020 name: "External heat/frost → recommend white mustard vasa kusta paste" source: vrikshayurveda priority: 7 conditions: [external_heat_frost_disorder] conclusions: [recommend_white_mustard_vasa_kusta_paste] dosha: none explanation: > Rubbing roots with white mustard, vasa, kusta, and ativisa paste is the second treatment for insect-induced root damage. - id: R021 name: "Insect root damage → recommend milk kunapa cow dung paste" source: vrikshayurveda priority: 6 conditions: [insect_root_damage_cause] conclusions: [recommend_milk_kunapa_cowdung_paste] dosha: none explanation: > Paste of milk, kunapa water, and cow dung with water applied to wounds heals insect-damaged root tissue. # ── EXTERNAL: EXCESSIVE STORMY WINDS ──────────────────────────────────── - id: R022 name: "Uprooting + branch breaking → stormy wind disorder" source: vrikshayurveda priority: 10 conditions: [tree_uprooting, branch_breaking] conclusions: [stormy_wind_disorder] dosha: none explanation: > Uprooting and branch breaking are the defining symptoms of excessive stormy wind — mechanical damage, not biological. - id: R023 name: "Tree twisting → stormy wind disorder" source: vrikshayurveda priority: 9 conditions: [tree_twisting] conclusions: [stormy_wind_disorder] dosha: none explanation: > Tree twisting is a stormy wind symptom indicating mechanical structural damage to the trunk. - id: R024 name: "Stormy wind disorder → recommend Plaksa Udumbara ghee paste" source: vrikshayurveda priority: 7 conditions: [stormy_wind_disorder] conclusions: [recommend_plaksa_udumbara_ghee_paste] dosha: none explanation: > Mixture of Plaksa bark, Udumbara, ghee, honey, wine, and milk applied to damaged areas is the Vrikshayurveda wind-damage remedy. # ── EXTERNAL: FIRE / LIGHTNING / WATER STRESS ─────────────────────────── - id: R025 name: "Drying of tree + Vata-like symptoms → fire/lightning/drought" source: vrikshayurveda priority: 9 conditions: [tree_drying, vata_like_symptoms] conclusions: [fire_lightning_drought_disorder] dosha: none explanation: > Drying with Vata-like symptoms indicates fire, lightning strike, soil aridity, or severe water stress as external cause. - id: R026 name: "Fire/lightning → recommend remove burned branches + milk water" source: vrikshayurveda priority: 7 conditions: [fire_lightning_drought_disorder] conclusions: [recommend_remove_burned_branches, recommend_milk_water_moisten] dosha: none explanation: > Burned branches must be removed and cuts moistened with milk and water before smoking with crab shells. - id: R027 name: "Fire/lightning → recommend lotus mud + kunapa water" source: vrikshayurveda priority: 7 conditions: [fire_lightning_drought_disorder] conclusions: [recommend_lotus_mud_kunapa] dosha: none explanation: > Entire tree covered in lotus mud then watered with kunapa mixture is the Vrikshayurveda treatment for severely burned trees. - id: R028 name: "Lightning strike specifically → recommend vidari arsenic sesame" source: vrikshayurveda priority: 8 conditions: [fire_lightning_drought_disorder, lightning_strike] conclusions: [recommend_vidari_arsenic_sesame_milk] dosha: none explanation: > Trees struck by lightning need anointing with vidari, sugar, red arsenic, and sesame then sprinkled with milk and water. # ── EXTERNAL: MECHANICAL WOUND (AXE ETC.) ─────────────────────────────── - id: R029 name: "Tree wounds + drying up → mechanical wound disorder" source: vrikshayurveda priority: 9 conditions: [tree_wounds, tree_drying] conclusions: [mechanical_wound_disorder] dosha: none explanation: > Wounds from axe or other implements causing drying are classified as mechanical wound disorder in Vrikshayurveda. - id: R030 name: "Mechanical wound → recommend Nyagrodha Udumbara cow dung paste" source: vrikshayurveda priority: 7 conditions: [mechanical_wound_disorder] conclusions: [recommend_nyagrodha_udumbara_cowdung_paste] dosha: none explanation: > Paste of Nyagrodha bark, Udumbara, cow dung, honey, and ghee applied to wounds is the Vrikshayurveda mechanical wound remedy. # ── FAULTY SEED DISORDER ───────────────────────────────────────────────── - id: R031 name: "Unproductive tree → faulty seed disorder" source: vrikshayurveda priority: 9 conditions: [tree_unproductive] conclusions: [faulty_seed_disorder] dosha: none explanation: > Trees that fail to bear fruit or produce are classified as faulty seed disorder — caused by untreated or pathogen-infected seeds. - id: R032 name: "Faulty seed → seed pathogen or insect cause" source: vrikshayurveda priority: 8 conditions: [faulty_seed_disorder] conclusions: [seed_pathogen_cause] dosha: none explanation: > Unproductive trees trace back to seeds infected with pathogens or damaged by insects at the seed stage. - id: R033 name: "Faulty seed → recommend milk mustard ash seed treatment" source: vrikshayurveda priority: 7 conditions: [faulty_seed_disorder] conclusions: [recommend_milk_mustard_ash_seed_treatment] dosha: none explanation: > Seeds should be treated with milk, mustard, ash of sesame and brhati, rubbed with cow dung, honey, and vidanga. # ── ANTS / INSECT INFESTATION ──────────────────────────────────────────── - id: R034 name: "Foul smell + fragrance loss → insect infestation" source: vrikshayurveda priority: 10 conditions: [foul_smell, fragrance_loss] conclusions: [insect_infestation_disorder] dosha: none explanation: > Foul smell replacing original fragrance is the primary indicator of ant or insect infestation in Vrikshayurveda. - id: R035 name: "Reduced leaf size + stunted seedlings → insect infestation" source: vrikshayurveda priority: 9 conditions: [reduced_leaf_size, stunted_seedlings] conclusions: [insect_infestation_disorder] dosha: none explanation: > Reduction in leaf size and stunted seedling growth indicates insect (ant/caterpillar) activity damaging the root system. - id: R036 name: "Insect infestation → recommend vidanga smoke fumigation" source: vrikshayurveda priority: 7 conditions: [insect_infestation_disorder] conclusions: [recommend_vidanga_smoke_fumigation] dosha: none explanation: > Smoking with white mustard, ramatha, vidanga, vaca, usana mixed with beef and pigeon flesh removes caterpillars and insects. - id: R037 name: "Insect infestation → recommend vidanga ghee ointment + soft water" source: vrikshayurveda priority: 7 conditions: [insect_infestation_disorder] conclusions: [recommend_vidanga_ghee_ointment, recommend_soft_water_7days] dosha: none explanation: > Anointing with vidanga mixed with ghee and watering for seven days with soft water is the second insect treatment. # ── EXCESSIVE WATERING DISORDER ───────────────────────────────────────── - id: R038 name: "Tree indigestion + destruction → excessive watering disorder" source: vrikshayurveda priority: 9 conditions: [tree_indigestion, tree_destruction] conclusions: [excessive_watering_disorder] dosha: kapha explanation: > Trees suffering indigestion and destruction from water excess are classified as excessive watering disorder — a Kapha-adjacent cause. - id: R039 name: "Excessive watering → recommend honey vidanga root application" source: vrikshayurveda priority: 7 conditions: [excessive_watering_disorder] conclusions: [recommend_honey_vidanga_roots] dosha: none explanation: > Honey and vidanga applied to every root of tender plants after uprooting and scratching with nails is the watering excess remedy. # ── CROSS-DISORDER CHAINS ──────────────────────────────────────────────── - id: R040 name: "Excessive moisture + Kapha → excessive watering overlap" source: derived priority: 8 conditions: [excessive_moisture_cause, internal_kapha_disorder] conclusions: [excessive_watering_disorder] dosha: kapha explanation: > When Kapha disorder is accompanied by excessive moisture cause, the tree is likely suffering from both Kapha imbalance and overwatering simultaneously. - id: R041 name: "Arid soil + water stress → fire/drought overlap" source: derived priority: 7 conditions: [arid_soil_cause, water_stress_cause] conclusions: [fire_lightning_drought_disorder] dosha: none explanation: > Arid soil cause combined with water stress can produce symptoms indistinguishable from fire or drought damage. - id: R042 name: "Vata-like symptoms + insect root damage → external heat/frost" source: derived priority: 8 conditions: [vata_like_symptoms, insect_root_damage_cause] conclusions: [external_heat_frost_disorder] dosha: none explanation: > Vata-like symptoms caused by insect root damage confirm external heat or frost as the predisposing condition. ``` --- ## Phase 2 — Replace inference/symptom_extractor.py **File:** `inference/symptom_extractor.py` **Action:** Replace the entire file with the content below. All keyword lists are derived directly from the Vrikshayurveda disorder table — every symptom term maps to the exact fact strings used in the YAML. ```python from __future__ import annotations SYMPTOM_KEYWORDS: dict[str, list[str]] = { # ── VATA SYMPTOMS ─────────────────────────────────────────────────── "trunk_bent": [ "trunk bent", "bent trunk", "curved trunk", "twisted stem", "crooked trunk", "leaning trunk", ], "knots_on_trunk": [ "knots", "knotted", "knots on trunk", "knots on leaves", "nodules", "galls", "swellings on bark", ], "hard_fruits": [ "hard fruit", "hard fruits", "less juicy", "dry fruit", "no juice", "tasteless fruit", "woody fruit", ], "slow_defoliation": [ "slow defoliation", "leaves not falling", "leaves clinging", "slow leaf drop", "delayed leaf shed", ], "flower_fruit_loss": [ "loss of flowers", "fruit drop", "flower drop", "dropping fruit", "flowers falling", "fruits falling", "premature fruit drop", ], "general_yellowing": [ "yellowing", "yellow leaves", "yellowing of leaves", "yellowing of fruits", "pale leaves", "chlorosis", "leaves turning yellow", "yellow fruit", ], # ── KAPHA SYMPTOMS ────────────────────────────────────────────────── "delayed_fruiting": [ "delayed fruiting", "fruit bearing delayed", "no fruit", "not fruiting", "late fruiting", "delayed bearing", "tree not producing", ], "bland_overripe_fruits": [ "bland fruit", "bland and overripe", "overripe", "tasteless", "flat taste", "no flavour", "watery fruit", ], "oozing_without_injury": [ "oozing", "oozing without injury", "seeping", "gummosis", "sap oozing", "resin oozing", "spontaneous discharge", "leaking sap", ], # ── PITTA SYMPTOMS ────────────────────────────────────────────────── "early_leaf_withering": [ "early withering", "leaf withering", "premature withering", "wilting", "early wilting", "leaves dying early", "withered leaves", ], "early_fruit_flower_decay": [ "early decay", "fruit decay", "flower decay", "blossom blight", "rotting flowers", "rotting fruits", "premature decay", "fruit rot", "flower rot", ], # ── EXTERNAL HEAT / FROST SYMPTOMS ────────────────────────────────── "vata_like_symptoms": [ "vata-like", "vata like symptoms", "vata symptoms", "yellowing and drying", "general decline", "drying and yellowing", ], # ── WIND DAMAGE SYMPTOMS ───────────────────────────────────────────── "tree_uprooting": [ "uprooted", "tree uprooting", "fell", "fallen tree", "roots exposed", "tree fell over", "uprooted tree", ], "branch_breaking": [ "branch breaking", "broken branch", "branches broken", "limbs broken", "snapped branch", "broken limb", ], "tree_twisting": [ "tree twisting", "twisted tree", "twisted trunk", "trunk twisted", "torqued", ], # ── FIRE / DROUGHT / LIGHTNING SYMPTOMS ────────────────────────────── "tree_drying": [ "drying", "tree drying", "drying up", "dried out", "desiccation", "tree dried", "branches drying", "completely dry", ], "lightning_strike": [ "lightning", "struck by lightning", "lightning strike", "thunder damage", "lightning damage", ], # ── MECHANICAL WOUND SYMPTOMS ───────────────────────────────────────── "tree_wounds": [ "wound", "wounded", "axe wound", "cut", "gash", "mechanical damage", "tool damage", "injured bark", "cut with axe", "bark cut", ], # ── FAULTY SEED SYMPTOMS ────────────────────────────────────────────── "tree_unproductive": [ "unproductive", "not bearing", "no yield", "barren tree", "tree not growing", "no produce", "stunted from seed", "failed to grow", ], # ── INSECT / ANT INFESTATION SYMPTOMS ───────────────────────────────── "foul_smell": [ "foul smell", "bad smell", "smell", "odour", "unpleasant odour", "rotten smell", ], "fragrance_loss": [ "fragrance missing", "fragrance lost", "no fragrance", "original fragrance missing", "lost scent", ], "reduced_leaf_size": [ "reduced leaf size", "smaller leaves", "small leaves", "leaf size reduction", "tiny leaves", ], "stunted_seedlings": [ "stunted seedlings", "seedling stunted", "seedling not growing", "slow seedling", "weak seedling", ], # ── EXCESSIVE WATERING SYMPTOMS ─────────────────────────────────────── "tree_indigestion": [ "indigestion", "tree indigestion", "waterlogged", "soggy roots", "root suffocation", "over watered", "overwatered", "root rot from water", ], "tree_destruction": [ "destruction", "tree destruction", "deteriorating", "collapsing", "decaying rapidly", "dying from water", ], # ── SEASONAL CONTEXT ────────────────────────────────────────────────── "winter_spring_season": [ "winter", "spring", "cold season", "cool season", "winter season", "spring season", ], "end_of_summer": [ "end of summer", "late summer", "summer end", "post summer", "end of hot season", ], } def extract_facts( user_query: str, expanded_queries: list[str], retrieved_chunks: list[str], ) -> set[str]: """ Extract atomic Vrikshayurveda facts from all text sources. Steps: 1. Combine user_query + expanded_queries + retrieved_chunks into a single lowercase string. 2. For each (fact, keywords) entry in SYMPTOM_KEYWORDS, check if ANY keyword appears in the combined text. 3. Return the set of matched fact strings. """ combined = " ".join( [user_query] + expanded_queries + retrieved_chunks ).lower() facts: set[str] = set() for fact, keywords in SYMPTOM_KEYWORDS.items(): if any(kw in combined for kw in keywords): facts.add(fact) return facts ``` --- ## Phase 3 — Update JS RULES array in VISUALIZER_HTML **File:** `app.py` **Action:** Find the `RULES=[...]` array inside the `VISUALIZER_HTML` string constant. Replace it entirely with the array below. Every id, condition, and conclusion string must be character-for-character identical to the YAML above. ```javascript const RULES=[ {id:"R001",conditions:["trunk_bent","knots_on_trunk"],conclusions:["internal_vata_disorder"],priority:10}, {id:"R002",conditions:["general_yellowing","flower_fruit_loss"],conclusions:["internal_vata_disorder"],priority:10}, {id:"R003",conditions:["hard_fruits","slow_defoliation"],conclusions:["internal_vata_disorder"],priority:9}, {id:"R004",conditions:["internal_vata_disorder"],conclusions:["arid_soil_cause"],priority:8}, {id:"R005",conditions:["internal_vata_disorder"],conclusions:["recommend_panchmula_decoction"],priority:7}, {id:"R006",conditions:["internal_vata_disorder"],conclusions:["recommend_fermented_fat_decoction"],priority:7}, {id:"R007",conditions:["delayed_fruiting","bland_overripe_fruits"],conclusions:["internal_kapha_disorder"],priority:10}, {id:"R008",conditions:["oozing_without_injury"],conclusions:["internal_kapha_disorder"],priority:9}, {id:"R009",conditions:["internal_kapha_disorder","winter_spring_season"],conclusions:["fungal_rot_cause","excessive_moisture_cause"],priority:10}, {id:"R010",conditions:["internal_kapha_disorder"],conclusions:["recommend_white_mustard_paste_roots"],priority:7}, {id:"R011",conditions:["internal_kapha_disorder"],conclusions:["recommend_sesame_ash_water","recommend_fresh_dry_soil"],priority:7}, {id:"R012",conditions:["early_leaf_withering"],conclusions:["internal_pitta_disorder"],priority:10}, {id:"R013",conditions:["early_fruit_flower_decay"],conclusions:["internal_pitta_disorder"],priority:10}, {id:"R014",conditions:["internal_pitta_disorder","end_of_summer"],conclusions:["heat_fungal_cause","salinity_cause"],priority:10}, {id:"R015",conditions:["internal_pitta_disorder"],conclusions:["recommend_triphala_ghee_honey"],priority:7}, {id:"R016",conditions:["internal_pitta_disorder"],conclusions:["recommend_milk_honey_yastamdhu_madhuka"],priority:7}, {id:"R017",conditions:["general_yellowing","vata_like_symptoms"],conclusions:["external_heat_frost_disorder"],priority:9}, {id:"R018",conditions:["external_heat_frost_disorder"],conclusions:["insect_root_damage_cause","water_stress_cause"],priority:8}, {id:"R019",conditions:["external_heat_frost_disorder"],conclusions:["recommend_cold_water_7days"],priority:7}, {id:"R020",conditions:["external_heat_frost_disorder"],conclusions:["recommend_white_mustard_vasa_kusta_paste"],priority:7}, {id:"R021",conditions:["insect_root_damage_cause"],conclusions:["recommend_milk_kunapa_cowdung_paste"],priority:6}, {id:"R022",conditions:["tree_uprooting","branch_breaking"],conclusions:["stormy_wind_disorder"],priority:10}, {id:"R023",conditions:["tree_twisting"],conclusions:["stormy_wind_disorder"],priority:9}, {id:"R024",conditions:["stormy_wind_disorder"],conclusions:["recommend_plaksa_udumbara_ghee_paste"],priority:7}, {id:"R025",conditions:["tree_drying","vata_like_symptoms"],conclusions:["fire_lightning_drought_disorder"],priority:9}, {id:"R026",conditions:["fire_lightning_drought_disorder"],conclusions:["recommend_remove_burned_branches","recommend_milk_water_moisten"],priority:7}, {id:"R027",conditions:["fire_lightning_drought_disorder"],conclusions:["recommend_lotus_mud_kunapa"],priority:7}, {id:"R028",conditions:["fire_lightning_drought_disorder","lightning_strike"],conclusions:["recommend_vidari_arsenic_sesame_milk"],priority:8}, {id:"R029",conditions:["tree_wounds","tree_drying"],conclusions:["mechanical_wound_disorder"],priority:9}, {id:"R030",conditions:["mechanical_wound_disorder"],conclusions:["recommend_nyagrodha_udumbara_cowdung_paste"],priority:7}, {id:"R031",conditions:["tree_unproductive"],conclusions:["faulty_seed_disorder"],priority:9}, {id:"R032",conditions:["faulty_seed_disorder"],conclusions:["seed_pathogen_cause"],priority:8}, {id:"R033",conditions:["faulty_seed_disorder"],conclusions:["recommend_milk_mustard_ash_seed_treatment"],priority:7}, {id:"R034",conditions:["foul_smell","fragrance_loss"],conclusions:["insect_infestation_disorder"],priority:10}, {id:"R035",conditions:["reduced_leaf_size","stunted_seedlings"],conclusions:["insect_infestation_disorder"],priority:9}, {id:"R036",conditions:["insect_infestation_disorder"],conclusions:["recommend_vidanga_smoke_fumigation"],priority:7}, {id:"R037",conditions:["insect_infestation_disorder"],conclusions:["recommend_vidanga_ghee_ointment","recommend_soft_water_7days"],priority:7}, {id:"R038",conditions:["tree_indigestion","tree_destruction"],conclusions:["excessive_watering_disorder"],priority:9}, {id:"R039",conditions:["excessive_watering_disorder"],conclusions:["recommend_honey_vidanga_roots"],priority:7}, {id:"R040",conditions:["excessive_moisture_cause","internal_kapha_disorder"],conclusions:["excessive_watering_disorder"],priority:8}, {id:"R041",conditions:["arid_soil_cause","water_stress_cause"],conclusions:["fire_lightning_drought_disorder"],priority:7}, {id:"R042",conditions:["vata_like_symptoms","insect_root_damage_cause"],conclusions:["external_heat_frost_disorder"],priority:8}, ]; ``` --- ## Phase 4 — Update FACT_TYPE classifier in VISUALIZER_HTML **File:** `app.py` **Action:** Find the `FACT_TYPE` function inside `VISUALIZER_HTML` and replace it with this version that covers all new fact strings: ```javascript const FACT_TYPE = f => { const symptoms = [ "trunk_bent","knots_on_trunk","hard_fruits","slow_defoliation", "flower_fruit_loss","general_yellowing","delayed_fruiting", "bland_overripe_fruits","oozing_without_injury","early_leaf_withering", "early_fruit_flower_decay","vata_like_symptoms","tree_uprooting", "branch_breaking","tree_twisting","tree_drying","lightning_strike", "tree_wounds","tree_unproductive","foul_smell","fragrance_loss", "reduced_leaf_size","stunted_seedlings","tree_indigestion", "tree_destruction","winter_spring_season","end_of_summer", ]; const doshas = [ "internal_vata_disorder","internal_kapha_disorder", "internal_pitta_disorder","external_heat_frost_disorder", "stormy_wind_disorder","fire_lightning_drought_disorder", "mechanical_wound_disorder","faulty_seed_disorder", "insect_infestation_disorder","excessive_watering_disorder", ]; const causes = [ "arid_soil_cause","fungal_rot_cause","excessive_moisture_cause", "heat_fungal_cause","salinity_cause","insect_root_damage_cause", "water_stress_cause","seed_pathogen_cause", ]; if (symptoms.includes(f)) return "symptom"; if (f.startsWith("recommend_")) return "remedy"; if (doshas.includes(f)) return "dosha"; if (causes.includes(f)) return "derived"; return "derived"; }; ``` --- ## Phase 5 — Update Gradio symptom selector **File:** `app.py` **Action:** Find the `gr.CheckboxGroup` in the Symptom Chain Explorer tab. Replace it with this expanded selector covering all 9 disorders: ```python symptom_selector = gr.CheckboxGroup( choices=[ # Vata symptoms ("Trunk bent / crooked", "trunk_bent"), ("Knots on trunk or leaves", "knots_on_trunk"), ("Hard / dry fruits", "hard_fruits"), ("Slow defoliation", "slow_defoliation"), ("Flower / fruit loss", "flower_fruit_loss"), ("General yellowing", "general_yellowing"), # Kapha symptoms ("Delayed fruiting", "delayed_fruiting"), ("Bland overripe fruits", "bland_overripe_fruits"), ("Oozing without injury", "oozing_without_injury"), # Pitta symptoms ("Early leaf withering", "early_leaf_withering"), ("Early fruit / flower decay", "early_fruit_flower_decay"), # External / shared symptoms ("Vata-like symptoms (external)", "vata_like_symptoms"), ("Tree drying up", "tree_drying"), ("Lightning strike", "lightning_strike"), ("Tree uprooting", "tree_uprooting"), ("Branch breaking", "branch_breaking"), ("Tree twisting", "tree_twisting"), ("Mechanical wounds (axe etc.)", "tree_wounds"), ("Tree unproductive", "tree_unproductive"), ("Foul smell", "foul_smell"), ("Fragrance loss", "fragrance_loss"), ("Reduced leaf size", "reduced_leaf_size"), ("Stunted seedlings", "stunted_seedlings"), ("Tree indigestion / waterlogged","tree_indigestion"), ("Tree destruction from water", "tree_destruction"), # Seasonal context ("Winter / spring season", "winter_spring_season"), ("End of summer season", "end_of_summer"), ], label="Observed symptoms", ) ``` --- ## Phase 6 — Update smoke test **File:** `inference/smoke_test.py` **Action:** Replace the entire file with the content below. ```python """ Run with: python -m inference.smoke_test All 4 scenarios must pass before using the app. """ from inference.engine import VrikshayurvedaInferenceEngine engine = VrikshayurvedaInferenceEngine() def run_scenario(name: str, query: str, expected_facts: list[str]) -> None: print(f"\n{'='*60}") print(f"SCENARIO: {name}") print('='*60) result = engine.diagnose( user_query=query, expanded_queries=[], retrieved_chunks=[], ) print(f"Primary diagnosis : {result.primary_diagnosis}") print(f"Dosha : {result.dosha}") print(f"Confidence : {round(result.confidence * 100)}%") print(f"\nForward trace:") for line in result.forward_trace: print(f" {line}") print(f"\nAll facts in working memory:") for f in sorted(result.all_facts): print(f" - {f}") missing = [f for f in expected_facts if f not in result.all_facts] if missing: print(f"\n FAIL — missing expected facts: {missing}") else: print(f"\n PASS — all expected facts present") print(f"\nLLM context:") print(f" {result.llm_context}") run_scenario( name="Internal Vata — arid yellowing", query="The tree has general yellowing of leaves and fruits with loss of flowers and fruits.", expected_facts=[ "general_yellowing", "flower_fruit_loss", "internal_vata_disorder", "arid_soil_cause", "recommend_panchmula_decoction", "recommend_fermented_fat_decoction", ], ) run_scenario( name="Internal Kapha — winter oozing", query="The tree is showing delayed fruiting with bland overripe fruits and oozing sap without any injury, it is winter season.", expected_facts=[ "delayed_fruiting", "bland_overripe_fruits", "oozing_without_injury", "winter_spring_season", "internal_kapha_disorder", "fungal_rot_cause", "excessive_moisture_cause", "recommend_white_mustard_paste_roots", "recommend_sesame_ash_water", "recommend_fresh_dry_soil", ], ) run_scenario( name="Internal Pitta — end of summer decay", query="Leaves are withering early and fruits are decaying prematurely at the end of summer.", expected_facts=[ "early_leaf_withering", "early_fruit_flower_decay", "end_of_summer", "internal_pitta_disorder", "heat_fungal_cause", "salinity_cause", "recommend_triphala_ghee_honey", "recommend_milk_honey_yastamdhu_madhuka", ], ) run_scenario( name="Insect infestation", query="The tree has a foul smell, original fragrance is missing, and leaves are reduced in size with stunted seedlings.", expected_facts=[ "foul_smell", "fragrance_loss", "reduced_leaf_size", "stunted_seedlings", "insect_infestation_disorder", "recommend_vidanga_smoke_fumigation", "recommend_vidanga_ghee_ointment", "recommend_soft_water_7days", ], ) ``` --- ## Phase 7 — Verification checklist Run in order before declaring done: ```bash python -m inference.smoke_test ``` All 4 scenarios must show `PASS`. Then verify in the UI: - [ ] Symptom selector shows all 27 symptom options - [ ] Selecting "General yellowing + Flower/fruit loss" fires R002 → R004 → R005 → R006 - [ ] Selecting "Delayed fruiting + Bland overripe fruits + Winter/spring" fires R007 → R009 → R010 → R011 - [ ] Selecting "Early leaf withering + End of summer" fires R012 → R014 → R015 → R016 - [ ] Selecting "Foul smell + Fragrance loss" fires R034 → R036 → R037 - [ ] Selecting "Tree uprooting + Branch breaking" fires R022 → R024 - [ ] Working memory shows correct fact pills after each run - [ ] Proof trace shows all fired rules with no blank entries --- ## Constraints - Only touch: `vrikshayurveda_rules.yaml`, `inference/symptom_extractor.py`, and `app.py` (RULES array, FACT_TYPE function, and CheckboxGroup only) - Do not touch: `inference/forward_chain.py`, `inference/backward_chain.py`, `inference/engine.py` - Do not change rule id numbering — R001 through R042 in order - YAML is the source of truth — if JS and YAML conflict, fix the JS - Smoke test must pass before launching the app