QModel / app /synonyms.py
aelgendy's picture
Sync codebase with local main (config, README, docker, gitignore updates)
15f1210 verified
Raw
History Blame Contribute Delete
3 kB
"""Islamic synonym mapping for query expansion."""
from typing import Dict, List
# Mapping from common terms to their English and Arabic synonyms
ISLAMIC_THESAURUS: Dict[str, List[str]] = {
# Thematic terms
"patience": ["sabr", "صبر", "ثبات", "تصبر"],
"sabr": ["patience", "صبر", "endurance"],
"mercy": ["rahmah", "رحمة", "رأفة", "مغفرة"],
"rahmah": ["mercy", "رحمة", "compassion"],
"prayer": ["salah", "صلوات", "صلاة", "قيام"],
"salah": ["prayer", "صلاة", "namaz"],
"charity": ["zakat", "صدقة", "إنفاق", "زكاة"],
"zakat": ["charity", "alms", "زكاة"],
"fasting": ["sawm", "siyam", "صيام", "صوم"],
"sawm": ["fasting", "صوم", "siyam"],
"pilgrimage": ["hajj", "umrah", "حج", "عمرة"],
"hajj": ["pilgrimage", "حج"],
"faith": ["iman", "إيمان", "عقيدة"],
"iman": ["faith", "إيمان", "belief"],
"heaven": ["jannah", "جنة", "فردوس"],
"jannah": ["heaven", "paradise", "جنة"],
"hell": ["jahannam", "nar", "جهنم", "نار"],
"jahannam": ["hell", "fire", "جهنم"],
# Legal & Scholarly terms
"inheritance": ["mirath", "fara'id", "ميراث", "مواريث", "فرائض", "ورثة", "تريكة"],
"mirath": ["inheritance", "ميراث", "فرائض"],
"fara'id": ["inheritance", "فرائض", "laws of inheritance"],
"will": ["وصية", "wasiyyah"],
"wasiyyah": ["will", "وصية", "testament"],
# Technical terms
"authentic": ["sahih", "صحيح", "موثوق"],
"sahih": ["authentic", "صحيح", "rigorous"],
"weak": ["da'if", "ضعيف", "واهي"],
"da'if": ["weak", "ضعيف"],
"narrator": ["rawi", "راوي", "سند", "إسناد"],
"isnad": ["narrators", "chain", "إسناد", "سند"],
# Core Spiritual & Belief terms
"tawhid": ["monotheism", "توحيد", "إخلاص"],
"piety": ["taqwa", "تقوى", "خشية"],
"taqwa": ["piety", "تقوى", "god-consciousness"],
"repentance": ["tawbah", "توبة", "استغفار", "انابة"],
"tawbah": ["repentance", "توبة"],
"forgiveness": ["maghfirah", "عفو", "مغفرة", "غفران"],
"supplication":["dua", "دعاء", "ابتهال"],
"dua": ["supplication", "دعاء", "prayer"],
"striving": ["jihad", "جهاد", "مجاهدة"],
"jihad": ["striving", "جهاد", "struggle"],
"intercession":["shafa'ah", "شفاعة"],
"shafa'ah": ["intercession", "شفاعة"],
}
def expand_synonyms(keywords: List[str]) -> List[str]:
"""Expand a list of keywords with synonyms from the thesaurus."""
expanded = set(keywords)
for kw in keywords:
kw_lower = kw.lower()
if kw_lower in ISLAMIC_THESAURUS:
expanded.update(ISLAMIC_THESAURUS[kw_lower])
return list(expanded)