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.7

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.7
File Size Uploaded
ganapati-0.0.7.tar.gz 37.6 kB Details

Built distribution (wheel)

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

Total release size: 77.1 kB

Release files / ganapati-0.0.7.tar.gz

Download URL ganapati-0.0.7.tar.gz
Size 37.6 kB
Tags Source
SHA-256 checksum
How to use checksums
70972b3cf652341ba93339e35f4f200965d941f5753316a1f40ed4bc1fbf573b
BLAKE2b-256 checksum
How to use checksums
c808b358580cac33382bc9833c628d64088b30492f2643ea403df533ffceb59d
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.7-py3-none-any.whl

Download URL ganapati-0.0.7-py3-none-any.whl
Size 39.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a2014094b6661c599c18bbdd1a9294402e074bf3ed8c06dc98814a3ebc3caac5
BLAKE2b-256 checksum
How to use checksums
e80cb371c1ed4b438bfb917a563c737a8d26f5db0147f34cac2d33c4117d7cc5
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

0.0.8

2 release files

This release

0.0.7 This release

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