Spaces:
Sleeping
Sleeping
File size: 9,819 Bytes
e47681e 788895f e47681e 788895f e47681e 788895f e47681e 788895f e47681e 788895f e47681e 788895f e47681e 788895f e47681e 788895f e47681e 788895f e47681e 788895f e47681e 788895f e47681e 788895f e47681e 788895f | 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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | """
Comprehensive Homeopathic Medicine Database with Common Misspellings
"""
import json
from typing import Dict, List, Tuple
# Main remedy database with common misspellings
REMEDY_DATABASE = {
"Arnica Montana": {
"correct_name": "Arnica Montana",
"common_names": ["Arnica", "Mountain Tobacco", "Leopard's Bane"],
"common_misspellings": ["Arnika", "Arnicha", "Arnoca", "Arnicum"],
"description": "First remedy for trauma, injuries, and shock",
"indications": ["Physical trauma", "Bruising", "Muscle soreness", "Post-surgical", "Shock"],
"potencies": ["6C", "30C", "200C", "1M"],
"dosage": "3-5 pellets every 2-4 hours for acute"
},
"Belladonna": {
"correct_name": "Belladonna",
"common_names": ["Deadly Nightshade"],
"common_misspellings": ["Belladona", "Beladona", "Belladone"],
"description": "Sudden violent onset with intense symptoms",
"indications": ["Sudden fever", "Throbbing headache", "Acute inflammation"],
"potencies": ["30C", "200C", "1M"],
"dosage": "Every 1-2 hours in acute fever"
},
"Argentum Nitricum": {
"correct_name": "Argentum Nitricum",
"common_names": ["Silver Nitrate"],
"common_misspellings": [
"Argentic Nitricum", "Argentum Nitric", "Argent Nitricum",
"Argentum Nitrate", "Argentic Nitrate", "Argent Nitric"
],
"description": "Anxiety, anticipation, digestive issues",
"indications": ["Anxiety", "Stage fright", "Diarrhea from anxiety", "Vertigo"],
"potencies": ["30C", "200C", "1M"],
"dosage": "3 times daily for anxiety"
},
"Nux Vomica": {
"correct_name": "Nux Vomica",
"common_names": ["Poison Nut", "Quaker Buttons"],
"common_misspellings": ["Nuxvomica", "Nux Vomic", "Nuxvomic", "Nux Vom"],
"description": "Irritable, impatient, digestive complaints",
"indications": ["Digestive disorders", "Overindulgence", "Insomnia", "Irritability"],
"potencies": ["6C", "30C", "200C"],
"dosage": "3 times daily for digestive issues"
},
"Pulsatilla": {
"correct_name": "Pulsatilla",
"common_names": ["Wind Flower", "Pasque Flower"],
"common_misspellings": ["Pulsatila", "Pulsitilla", "Pulsitila", "Pulsatella"],
"description": "Mild, yielding, changeable symptoms",
"indications": ["Changeable symptoms", "Digestive issues", "Colds", "Weepy"],
"potencies": ["6C", "30C", "200C"],
"dosage": "Every 4 hours for acute"
},
# Additional 15 common remedies
"Bryonia Alba": {
"correct_name": "Bryonia Alba",
"common_names": ["White Bryony", "Wild Hops"],
"common_misspellings": ["Briyonia", "Bryonia", "Bironia", "Bryonia Alba"],
"description": "Irritable, thirsty, worse from motion",
"indications": ["Dry mucous", "Joint pains", "Constipation", "Pleurisy"],
"potencies": ["6C", "30C", "200C"],
"dosage": "Every 4 hours"
},
"Aconitum Napellus": {
"correct_name": "Aconitum Napellus",
"common_names": ["Monkshood", "Aconite"],
"common_misspellings": ["Aconite", "Aconitum", "Aconite Napellus", "Aconiteum"],
"description": "Sudden onset after fright, intense anxiety",
"indications": ["Sudden fever", "Panic attacks", "Croup", "Exposure"],
"potencies": ["30C", "200C", "1M"],
"dosage": "Every 30 minutes in acute panic"
},
"Chamomilla": {
"correct_name": "Chamomilla",
"common_names": ["German Chamomile"],
"common_misspellings": ["Camomilla", "Chamomile", "Chamomila", "Camomile"],
"description": "Extreme irritability, oversensitivity to pain",
"indications": ["Teething", "Colic", "Irritability", "Childbirth pain"],
"potencies": ["6C", "30C", "200C"],
"dosage": "Every 15-30 minutes for acute pain"
},
"Gelsemium": {
"correct_name": "Gelsemium",
"common_names": ["Yellow Jasmine"],
"common_misspellings": ["Gelsem", "Gelsimium", "Gelseminum", "Gelsemia"],
"description": "Weakness, trembling, anticipatory anxiety",
"indications": ["Flu", "Stage fright", "Headache", "Weakness"],
"potencies": ["30C", "200C", "1M"],
"dosage": "Every 2-4 hours"
},
"Ignatia": {
"correct_name": "Ignatia",
"common_names": ["St. Ignatius Bean"],
"common_misspellings": ["Ignatia Amara", "Ignat", "Ignatia", "Ignatiam"],
"description": "Acute grief, hysteria, contradictory symptoms",
"indications": ["Grief", "Hysteria", "Headache from grief", "Sighing"],
"potencies": ["30C", "200C", "1M"],
"dosage": "As needed for emotional distress"
},
"Phosphorus": {
"correct_name": "Phosphorus",
"common_names": [],
"common_misspellings": ["Phosporus", "Phos", "Phosphorous", "Phosph"],
"description": "Bleeding, fear, thirst for cold drinks",
"indications": ["Bleeding", "Anxiety", "Pneumonia", "Burning pains"],
"potencies": ["30C", "200C", "1M"],
"dosage": "3 times daily"
},
"Sepia": {
"correct_name": "Sepia",
"common_names": ["Cuttlefish Ink"],
"common_misspellings": ["Sep", "Sepiah", "Sapia", "Seppia"],
"description": "Indifference, bearing-down sensation",
"indications": ["Menopausal symptoms", "Indifference", "Prolapse", "Headache"],
"potencies": ["30C", "200C", "1M"],
"dosage": "Once daily or weekly"
},
"Silicea": {
"correct_name": "Silicea",
"common_names": ["Silica", "Flint"],
"common_misspellings": ["Silica", "Silice", "Silicaea", "Sil"],
"description": "Lack of confidence, suppurations, sensitive to cold",
"indications": ["Abscesses", "Lack of confidence", "Sweaty feet", "Headache"],
"potencies": ["30C", "200C", "1M"],
"dosage": "Once weekly"
},
"Sulphur": {
"correct_name": "Sulphur",
"common_names": ["Brimstone"],
"common_misspellings": ["Sulfur", "Sulpur", "Sulfer", "Sulph"],
"description": "Philosophical, untidy, skin complaints",
"indications": ["Skin disorders", "Itching", "Philosophical", "Hungry at 11am"],
"potencies": ["30C", "200C", "1M"],
"dosage": "Once weekly"
},
"Thuja": {
"correct_name": "Thuja",
"common_names": ["Arbor Vitae"],
"common_misspellings": ["Thuga", "Thuja Occidentalis", "Thuje", "Thuya"],
"description": "Fixed ideas, warts, vaccination effects",
"indications": ["Warts", "Vaccination effects", "Fixed ideas", "Skin growths"],
"potencies": ["30C", "200C", "1M"],
"dosage": "Once weekly"
}
}
def search_remedy_by_name(query: str, use_spell_check: bool = True) -> List[Tuple[str, Dict, float]]:
"""
Search for remedies by name with spell correction
Returns: [(remedy_name, remedy_data, confidence_score)]
"""
query = query.strip().lower()
if not query or len(query) < 2:
return []
results = []
for remedy_name, remedy_data in REMEDY_DATABASE.items():
confidence = 0
# 1. Exact match (highest confidence)
if query == remedy_name.lower():
confidence = 100
# 2. Partial match in correct name
elif query in remedy_name.lower():
confidence = 80
# 3. Match in common names
elif any(query in name.lower() for name in remedy_data.get("common_names", [])):
confidence = 70
# 4. Spell correction matching
elif use_spell_check and _spell_correction_match(query, remedy_name, remedy_data):
confidence = _calculate_spell_confidence(query, remedy_name, remedy_data)
if confidence > 0:
results.append((remedy_name, remedy_data, confidence))
# Sort by confidence
results.sort(key=lambda x: x[2], reverse=True)
return results[:10]
def _spell_correction_match(query: str, remedy_name: str, remedy_data: Dict) -> bool:
"""Check if query matches through spell correction"""
# Check common misspellings
if query in [m.lower() for m in remedy_data.get("common_misspellings", [])]:
return True
# Simple Levenshtein-like check for short remedies
if len(query) > 3 and len(remedy_name) > 3:
# Check if query is close to remedy name
if _string_similarity(query, remedy_name.lower()) > 0.7:
return True
return False
def _calculate_spell_confidence(query: str, remedy_name: str, remedy_data: Dict) -> float:
"""Calculate confidence score for spell-corrected matches"""
# Exact misspelling match
if query in [m.lower() for m in remedy_data.get("common_misspellings", [])]:
return 90
# Calculate string similarity
similarity = _string_similarity(query, remedy_name.lower())
if similarity > 0.9:
return 85
elif similarity > 0.8:
return 75
elif similarity > 0.7:
return 65
else:
return 50
def _string_similarity(s1: str, s2: str) -> float:
"""Calculate simple string similarity"""
if not s1 or not s2:
return 0
# Common prefix length
prefix_len = 0
for i in range(min(len(s1), len(s2))):
if s1[i] == s2[i]:
prefix_len += 1
else:
break
return prefix_len / max(len(s1), len(s2))
def get_remedy_details(name: str) -> Dict:
"""Get complete remedy details"""
return REMEDY_DATABASE.get(name)
def get_all_remedies() -> List[str]:
"""Get list of all remedy names"""
return list(REMEDY_DATABASE.keys()) |