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

The three 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, the reader profiles

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

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.3
File Size Uploaded
ganapati-0.0.3.tar.gz 31.4 kB Details

Built distribution (wheel)

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

Total release size: 64.4 kB

Release files / ganapati-0.0.3.tar.gz

Download URL ganapati-0.0.3.tar.gz
Size 31.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d5e1a397f43b7d07c8160f35126950d77a27597ddf03ae1e5939966969f65532
BLAKE2b-256 checksum
How to use checksums
bb289d78447552c06b616aebce4086c08ab9317b70c70cbde8d02d6ad9454ace
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.3-py3-none-any.whl

Download URL ganapati-0.0.3-py3-none-any.whl
Size 33.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4c88e5f0717ab401119a7ca3557f17f01e53c23226e50115f7292c245c16b1d4
BLAKE2b-256 checksum
How to use checksums
a88c3e36d68a66d7057c38147e77db7072f855d4d2875c3edf6093849dae01f8
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

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

This release

0.0.3 This release

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