Skip to main content

ganapati

Metre, verse boundaries, citations, and lemmas. import ganapati registers the Sanskrit reader profiles, so a GRETIL or TEI source is chunked by verse and its tree is built from the citations.

from litesearch import Index
from ganapati import Meter

ix = Index('vault.db')
ix.add('mahabharata.htm')
ix.search('dharma')[:3]
ix.db.by_meter(meter=Meter.ANUSTUBH)[:3]
/Users/71293/code/personal/orgs/ganapati/.venv/lib/python3.13/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
  from .autonotebook import tqdm as notebook_tqdm

[{'content': 'nārāyaṇaṃ namaskṛtya naraṃ caiva narottamam\ndevīṃ sarasvatīṃ caiva tato jayam udīrayet',
  'metadata': '{"meter": "anuṣṭubh", "variant": "pathyā", "gana": "ta_ra_ga_ga", "pada": "8"}',
  'node_id': '73a63025c7fc3d14#0',
  'doc_id': '73a63025c7fc3d14',
  'page': 0},
 {'content': 'samāsīnān abhyagacchad brahmarṣīn saṃśitavratān\nvinayāvanato bhūtvā kadā cit sūtanandanaḥ',
  'metadata': '{"meter": "anuṣṭubh", "variant": "pathyā ra-vipulā", "gana": "ya_ta_ga_ga", "pada": "8"}',
  'node_id': '73a63025c7fc3d14#0',
  'doc_id': '73a63025c7fc3d14',
  'page': 2},
 {'content': 'tam āśramam anuprāptaṃ naimiṣāraṇyavāsinaḥ\ncitrāḥ śrotuṃ kathās tatra parivavrus tapasvinaḥ',
  'metadata': '{"meter": "anuṣṭubh", "variant": "pathyā", "gana": "ja_sa_ga_ga", "pada": "8"}',
  'node_id': '73a63025c7fc3d14#0',
  'doc_id': '73a63025c7fc3d14',
  'page': 3}]

Every chunk carries its metre as searchable metadata.

verse_meta('dharmakṣetre kurukṣetre samavetā yuyutsavaḥ '
           'māmakāḥ pāṇḍavāścaiva kimakurvata sañjaya')
{'meter': 'anuṣṭubh', 'variant': 'pathyā', 'gana': 'ma_ra_ga_ga', 'pada': '8'}

The scan behind it, and the metre that pattern names:

scan('dharmakṣetre kurukṣetre')     # g for heavy, l for light
'gggglggg'
detect_meter('kaścit kāntāvirahaguruṇā svādhikārātpramattaḥ '
             'śāpenāstaṃgamitamahimā varṣabhogyeṇa bhartuḥ '
             'yakṣaścakre janakatanayāsnānapuṇyodakeṣu '
             'snigdhacchāyātaruṣu vasatiṃ rāmagiryāśrameṣu')['name']
<Meter.MANDAKRANTA: 'mandākrāntā'>

A line at a time

Forced alignment and ASR hand you lines, not verses. match_pada names a metre from one pāda and group_verses finds how many lines make a verse.

padas = ['kaścit kāntāvirahaguruṇā svādhikārātpramattaḥ',
         'śāpenāstaṃgamitamahimā varṣabhogyeṇa bhartuḥ',
         'yakṣaścakre janakatanayāsnānapuṇyodakeṣu',
         'snigdhacchāyātaruṣu vasatiṃ rāmagiryāśrameṣu']
match_pada(padas[0]), group_verses(padas).size

Names and terms

A reader asks about Sri Ranganatha where the translation writes Viṣṇu, or about anumana where it says inference.

canonical('Sri Ranganatha'), canonical('Partha'), term_gloss('anumana')
(('viṣṇu', 'nārāyaṇa', 'hari'), ('arjuna',), ('inference',))

The four modules

module what is in it
ganapati.text verse boundaries, pādas and verse numbers, the two chunkers, readers for GRETIL, TEI, VR XML and DCS
ganapati.metre IAST transliteration, syllable weights, the gaṇas, 80 metres, mātrā metres, a metre by name
ganapati.lemma vidyut lemmas, Monier-Williams glosses, the source’s own etymology entries and their repair, the reader profiles
ganapati.names one key per romanised name, deity and figure epithets, English for śāstra and jyotiṣa terms

Install

pip install ganapati

Lemmas and glosses need vidyut and an 81 MB data download, both reached on first use. Without them a store still gets metre, audio timings, and whatever analysis the source itself carries.

Metadata

Release files for ganapati 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ganapati 0.0.8
File Size Uploaded
ganapati-0.0.8.tar.gz 37.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ganapati 0.0.8
File Interpreter ABI Platform
ganapati-0.0.8-py3-none-any.whl Python 3 none any Details

Total release size: 77.3 kB

Release files / ganapati-0.0.8.tar.gz

Download URL ganapati-0.0.8.tar.gz
Size 37.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a3010be754b434bd9a749ec1f2788f38adc3f41d4afc5ea6fa49eab6fb0e1ba3
BLAKE2b-256 checksum
How to use checksums
d7e4654054edbfa046c27a9eda17f9f03dba259c1e30510e53cb792f6de47623
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / ganapati-0.0.8-py3-none-any.whl

Download URL ganapati-0.0.8-py3-none-any.whl
Size 39.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6d44689a53d4040cd137db2dcda2bb1fda5e2d7ff52ca685161bcfa9ea6a186
BLAKE2b-256 checksum
How to use checksums
47e8cf3382d9f276f3367072a3e544d1d519fb25dfebde4423c8a1547b976101
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release history Release notifications | RSS feed

0.1.0

2 release files

0.0.9

2 release files

This release

0.0.8 This release

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page