import polars as pl OM_FREQ = 432.0 class VedicLanguageEngine: def __init__(self, df_vowels, df_consonants, df_barakhadi, df_marathi): self.df_vowels = df_vowels self.df_consonants = df_consonants self.df_barakhadi = df_barakhadi self.df_marathi = df_marathi def get_char_features(self, char): v_match = self.df_vowels.filter(pl.col("char") == char) if not v_match.is_empty(): row = v_match.row(0, named=True) return {"type": "vowel", "f1": row.get("f1_hz") or 0.0, "f2": row.get("f2_hz") or 0.0, "f3": row.get("f3_hz") or 0.0, "duration": row.get("duration_ms") or 0.0} c_match = self.df_consonants.filter(pl.col("char") == char) if not c_match.is_empty(): row = c_match.row(0, named=True) return {"type": "consonant", "f1": 0.0, "f2": 0.0, "f3": 0.0, "duration": row.get("duration_ms") or 0.0} return None def shabda_prakar_olakha(self, word): m_match = self.df_marathi.filter(pl.col("char") == word) if not m_match.is_empty(): return m_match.row(0, named=True).get("शब्द प्रकार") or "अज्ञात" verb_suffixes = ["ला", "ली", "ले", "तो", "ते", "तात", "णे"] for suffix in verb_suffixes: if word.endswith(suffix): return "क्रियापद" return "इतर" def analyze_word(self, word): total_self_net, total_cosmic_net, total_micro = 0.0, 0.0, 0.0 prakar = self.shabda_prakar_olakha(word) for p in word: features = self.get_char_features(p) if features: if features["type"] == "vowel": total_self_net += (features["duration"] / 10.0) else: total_cosmic_net += (features["duration"] / 10.0) if features["f1"] > 0: avg_freq = (features["f1"] + features["f2"] + features["f3"]) / 3 total_micro += abs(OM_FREQ - avg_freq) return {"word": word, "prakar": prakar, "self_net": round(total_self_net, 2), "cosmic_net": round(total_cosmic_net, 2), "micro_energy": round(total_micro, 2)} def vakya_vishleshan(self, sentence): words = sentence.split() total_self, total_cosmic, total_micro = 0.0, 0.0, 0.0 for word in words: res = self.analyze_word(word) total_self += res["self_net"] total_cosmic += res["cosmic_net"] total_micro += res["micro_energy"] dvaita = abs(total_self - total_cosmic) return { "वाक्य": sentence, "एकूण_मन_ऊर्जा": round(total_self, 2), "एकूण_शरीर_ऊर्जा": round(total_cosmic, 2), "द्वैत_उत्तर": round(dvaita, 2) }