Skip to main content

Sanskrit meter identification and analysis library

Project description

Chanda

PyPI version Python 3.8+ License: AGPL v3

Sanskrit Meter Identification and Analysis Library

A comprehensive Python library for identifying and analyzing Sanskrit poetic meters. Supports 200+ meters including Sama-vṛtta, Ardhasama-vṛtta, Viṣama-vṛtta, and Mātrā-vṛtta.


Features

  • 200+ Meter Database: Comprehensive coverage of Sanskrit meters

    • Sama-vṛtta (meters with identical padas)
    • Ardhasama-vṛtta & Viṣama-vṛtta (meters with varying padas)
    • Mātrā-vṛtta (matra-based meters like Āryā, Gīti)
  • Smart Identification:

    • Exact pattern matching
    • Fuzzy matching with syllable-level correction suggestions
    • Verse-level analysis (4-line grouping)
  • Multi-Script Support: 15+ scripts and transliteration schemes

    • Devanagari, IAST, ITRANS, Harvard-Kyoto, SLP1, WX, Velthuis, and more
  • Detailed Analysis:

    • Syllable segmentation
    • Laghu-Guru (light-heavy) marking
    • Gana notation conversion
    • Mātrā (morae) counting
    • Jāti (classification) identification

Installation

From PyPI

pip install chanda

From Source

git clone https://github.com/hrishikeshrt/chanda.git
cd chanda
pip install -e .

Quick Start

Python API

from chanda import analyze_line

# Simple example - Anuṣṭubh (most common meter)
text = "को न्वस्मिन् साम्प्रतं लोके गुणवान् कश्च वीर्यवान्"
result = analyze_line(text)
meters = [name for name, _ in result.chanda]
print(meters)  # Output: ['अनुष्टुभ्']

# Gana-based meter example - shows gana pattern
text = "नमस्ते सदा वत्सले मातृभूमे"
result = analyze_line(text)
meters = [name for name, _ in result.chanda]
print(meters)  # Output: ['भुजङ्गप्रयात']
print(result.gana)            # Output: यययय

Results are objects (ChandaResult / TextAnalysisResult). Use result.to_dict() or result.to_json() for serialization.

Command-Line Interface

# Analyze a single line
chanda "को न्वस्मिन् साम्प्रतं लोके गुणवान् कश्च वीर्यवान्"

# Analyze a file
chanda -f bhagavad_gita.txt --verse --summary

# Interactive mode
chanda -i

# Get help
chanda --help

Detailed Usage

Single Line Analysis

from chanda import analyze_line

text = "रामो राजमणिः सदा विजयते रामं रमेशं भजे"
result = analyze_line(text, fuzzy=True)

if result.found:
    print(f"Meter(s): {[name for name, _ in result.chanda]}")
    print(f"Syllables: {result.syllables}")
    print(f"Pattern (LG): {' '.join(result.lg)}")
    print(f"Gana: {result.gana}")
    print(f"Syllable count: {result.length}")
    print(f"Mātrā count: {result.matra}")
else:
    # Check fuzzy matches
    if result.fuzzy:
        best_match = result.fuzzy[0]
        from chanda import format_chanda_list
        print(f"Closest meter: {format_chanda_list(best_match['chanda'])}")
        print(f"Similarity: {best_match['similarity']:.2%}")

Verse Analysis

from chanda import analyze_text

verse = """को न्वस्मिन् साम्प्रतं लोके गुणवान् कश्च वीर्यवान्।
धर्मज्ञश्च कृतज्ञश्च सत्यवाक्यो दृढव्रतः॥"""

results = analyze_text(verse, verse_mode=True, fuzzy=True)

# Access verse-level results
for verse in results.result.verse:
    if not verse.chanda:
        continue
    best_meters, score = verse.chanda
    print(f"Verse meter: {' / '.join(best_meters)} (score: {score})")

Documentation

Full documentation is available at chanda.readthedocs.io


Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with tests
  4. Run the test suite
  5. Submit a pull request

Citation

If you use Chandojñānam in your research, please cite:

@inproceedings{terdalkar2023chandojnanam,
    title = "Chandojnanam: A {S}anskrit Meter Identification and Utilization System",
    author = "Terdalkar, Hrishikesh  and
      Bhattacharya, Arnab",
    booktitle = "Proceedings of the Computational {S}anskrit {\&} Digital Humanities: Selected papers presented at the 18th World {S}anskrit Conference",
    month = jan,
    year = "2023",
    address = "Canberra, Australia (Online mode)",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2023.wsc-csdh.8",
    pages = "113--127",
}

License

GNU Affero General Public License v3.0 - see LICENSE file for details.


Acknowledgments

  • Based on traditional chandaśāstra texts
  • Meter definitions compiled from various classical sources
  • Built on the excellent sanskrit-text and indic-transliteration libraries

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chanda-1.0.0.tar.gz (71.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chanda-1.0.0-py3-none-any.whl (51.5 kB view details)

Uploaded Python 3

File details

Details for the file chanda-1.0.0.tar.gz.

File metadata

  • Download URL: chanda-1.0.0.tar.gz
  • Upload date:
  • Size: 71.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for chanda-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5ca526192766b7466f86bde37be704bd1ec3c1488e584531c1ee1a674f2cb67c
MD5 7d9e39f1a6a4c5c706937b42a7d298a2
BLAKE2b-256 a767463af652fc16498a998d57776f53c4b150c562df4b35c7764a5b29ca2ca7

See more details on using hashes here.

File details

Details for the file chanda-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: chanda-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 51.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for chanda-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 27acb9a8aea706cfa7d58e9d8f67a65635367da526f17d76c7b259ebbb8320ea
MD5 cd1ade1e3522632055e33c1e937a10e2
BLAKE2b-256 9ff929b2609565e1a4900322c88bfbb5a154d7bf5ed3ec6fd40e79e7e29bd6dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page