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

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.1.0
File Size Uploaded
ganapati-0.1.0.tar.gz 40.5 kB Details

Built distribution (wheel)

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

Total release size: 83.6 kB

Release files / ganapati-0.1.0.tar.gz

Download URL ganapati-0.1.0.tar.gz
Size 40.5 kB
Tags Source
SHA-256 checksum
How to use checksums
dcbc52316ba93231ccaf372b5b34e6eb98ad2560df196f978ffd5b0f379f80c0
BLAKE2b-256 checksum
How to use checksums
b4ab950d21ba1a002b94b6edd4a3db6fcf72a135ddd56ecdf01daafa9669d3d9
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.1.0-py3-none-any.whl

Download URL ganapati-0.1.0-py3-none-any.whl
Size 43.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1062366e33261627ad4b26358bd06e43129b5d13cfb6471ec731315725118ff8
BLAKE2b-256 checksum
How to use checksums
1c728d370fd5053236152514f8ad538f23d8386c25989a7b8c93c55d9fd88549
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

This release

0.1.0 This release

2 release files

0.0.9

2 release files

0.0.8

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