""" 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())