vyasa-patha CLI & API Reference
vyasa-patha is the recitation engine in vyutils for generating Vedic and Classical Sanskrit recitation modes (Prakṛti and Vikṛti pāṭhas). It parses Pada-pāṭha texts, detects Pāṇinian Pragṛhya vowels, formats Parigraha (iti) clauses, applies forward Sandhi, and outputs multi-script recitations.
Installation
Section titled “Installation”Building from Source
Section titled “Building from Source”cargo build --release -p vyasa-pathacargo install --path crates/vyasa-pathaBinary location: ~/.cargo/bin/vyasa-patha
CLI Synopsis
Section titled “CLI Synopsis”vyasa-patha [OPTIONS] [TEXT]cat <pada_file.txt> | vyasa-patha [OPTIONS]If [TEXT] is provided as an argument, it is processed directly. If omitted, vyasa-patha reads Pada-pāṭha from stdin until EOF.
CLI Options & Flags
Section titled “CLI Options & Flags”| Flag | Long Option | Values | Default | Description |
|---|---|---|---|---|
-m |
--mode |
krama | pada | jata | ghana |
krama |
Recitation mode to generate. |
-t |
--to |
<SCRIPT> |
devanagari |
Target script format (e.g. telugu, kannada, grantha, iast, iso15919). |
-s |
--steps |
flag | off | Emit numbered steps line-by-line rather than continuous text. |
-h |
--help |
— | — | Print help information and exit. |
-V |
--version |
— | — | Print version information and exit. |
CLI Examples
Section titled “CLI Examples”1. Generating Continuous Krama-pāṭha
Section titled “1. Generating Continuous Krama-pāṭha”vyasa-patha "अ॒ग्निम् । ई॒ळे॒ । पु॒रो-हि॑तम् । य॒ज्ञस्य॑ । दे॒वम् । ऋ॒त्विज॑म् ।"Output:
अ॒ग्निमी॑ळे । ई॒ळे॒ पु॒रोहि॑तम् । पु॒रो-हि॑तम् । पु॒रोहि॑तमिति॑ पु॒रो-हि॑तम् । पु॒रोहि॑तं य॒ज्ञस्य॑ । य॒ज्ञस्य॑ दे॒वम् । दे॒वमृ॒त्विज॑म् । ऋ॒त्विज॒मित्यृ॒त्विज॑म् ॥2. Stepped Pairwise Output (--steps)
Section titled “2. Stepped Pairwise Output (--steps)”vyasa-patha "अ॒ग्निम् । ई॒ळे॒ । पु॒रो-हि॑तम् ।" --stepsOutput:
1. (1-2) अ॒ग्निमी॑ळे2. (2-3) ई॒ळे॒ पु॒रोहि॑तम्3. (3) पु॒रो-हि॑तम्4. (3-Par) पु॒रोहि॑तमिति॑ पु॒रो-हि॑तम्3. Multi-Script Generation
Section titled “3. Multi-Script Generation”Generate Krama-pāṭha directly in Telugu script:
vyasa-patha "अ॒ग्निम् । ई॒ळे॒ । पु॒रो-हि॑तम् ।" --to telugu --stepsOutput:
1. (1-2) అ॒గ్నిమీ॑ళే2. (2-3) ఈ॒ళే॒ పు॒రోహితమ్3. (3) పు॒రో-హితమ్4. (3-Par) పు॒రోహితమితి॑ పు॒రో-హితమ్Generate in Western Academic Roman (IAST):
vyasa-patha "अ॒ग्निम् । ई॒ळे॒ ।" --to iastOutput:
a̱gnimī̱ḷe̱ | ī̱ḷe̱ ití ī̱ḷe̱ ||Rust Library API
Section titled “Rust Library API”Add vyasa-patha and vyasa-lipi to your Cargo.toml:
[dependencies]vyasa-patha = { version = "0.1.0" }vyasa-lipi = { version = "0.1.0" }1. High-Level Functions
Section titled “1. High-Level Functions”generate_krama(pada_text: &str) -> String
Section titled “generate_krama(pada_text: &str) -> String”Generates continuous Krama-pāṭha text in Devanagari with daṇḍa delimiters.
use vyasa_patha::generate_krama;
let output = generate_krama("अ॒ग्निम् । ई॒ळे॒ । पु॒रो-हि॑तम् ।");generate_krama_in_script(pada_text: &str, script: Script) -> String
Section titled “generate_krama_in_script(pada_text: &str, script: Script) -> String”Generates continuous Krama-pāṭha in any target script supported by vyasa-lipi.
use vyasa_patha::generate_krama_in_script;use vyasa_lipi::Script;
let telugu = generate_krama_in_script("अ॒ग्निम् । ई॒ळे॒ ।", Script::Telugu);generate_jata(pada_text: &str) -> String
Section titled “generate_jata(pada_text: &str) -> String”Generates continuous Jaṭā-pāṭha text ($1\text{-}2, 2\text{-}1, 1\text{-}2$) in Devanagari with forward and reverse Sandhi.
use vyasa_patha::generate_jata;
let jata = generate_jata("अ॒ग्निम् । ई॒ळे॒ । पु॒रो-हि॑तम् ।");generate_jata_in_script(pada_text: &str, script: Script) -> String
Section titled “generate_jata_in_script(pada_text: &str, script: Script) -> String”Generates continuous Jaṭā-pāṭha in any target script supported by vyasa-lipi.
generate_ghana(pada_text: &str) -> String
Section titled “generate_ghana(pada_text: &str) -> String”Generates continuous Ghana-pāṭha text. Each window of three padas is Jaṭā plus triples (1-2, 2-1, 1-2-3, 3-2-1, 1-2-3); the last pair falls back to Jaṭā.
use vyasa_patha::generate_ghana;
let ghana = generate_ghana("अ॒ग्निम् । ई॒ळे॒ । पु॒रो-हि॑तम् ।");generate_ghana_in_script(pada_text: &str, script: Script) -> String
Section titled “generate_ghana_in_script(pada_text: &str, script: Script) -> String”Generates continuous Ghana-pāṭha in any target script supported by vyasa-lipi.
2. Verse-Level & Mid-Level Prakṛti / Vikṛti Functions
Section titled “2. Verse-Level & Mid-Level Prakṛti / Vikṛti Functions”generate_krama_for_verse(pada_verse: &str) -> Vec<KramaStep>
Section titled “generate_krama_for_verse(pada_verse: &str) -> Vec<KramaStep>”Generates complete Krama steps for a multi-hemistich verse. Strictly respects ardharca boundaries (daṇḍa । pauses): hemistichs are never chained across ।, terminal padas before । receive Parigraha, and compounds receive Parigraha.
generate_jata_for_verse(pada_verse: &str) -> Vec<JataStep>
Section titled “generate_jata_for_verse(pada_verse: &str) -> Vec<JataStep>”Generates complete Jaṭā steps for a multi-hemistich verse ($1\text{-}2, 2\text{-}1, 1\text{-}2$), respecting ardharca boundaries and compound Parigrahas.
generate_jata_patha(padas: &[Pada]) -> Vec<JataStep>
Section titled “generate_jata_patha(padas: &[Pada]) -> Vec<JataStep>”Permutes a slice of Pada elements into canonical JataStep tokens with forward and reverse Sandhi.
generate_ghana_for_verse(pada_verse: &str) -> Vec<GhanaStep>
Section titled “generate_ghana_for_verse(pada_verse: &str) -> Vec<GhanaStep>”Generates complete Ghana steps for a multi-hemistich verse, respecting ardharca boundaries. GhanaStep is Jaṭā plus third_index / forward_triple / reverse_triple.
generate_ghana_patha(padas: &[Pada]) -> Vec<GhanaStep>
Section titled “generate_ghana_patha(padas: &[Pada]) -> Vec<GhanaStep>”Permutes a slice of Pada elements into canonical GhanaStep tokens.
parse_verse_hemistichs(input: &str) -> Vec<Vec<Pada>>
Section titled “parse_verse_hemistichs(input: &str) -> Vec<Vec<Pada>>”Splits a Pada-pāṭha verse by hemistich daṇḍas (। or ॥) and parses each hemistich into its own Vec<Pada>.
parse_pada_patha(input: &str) -> Vec<Pada>
Section titled “parse_pada_patha(input: &str) -> Vec<Pada>”Parses a raw Pada-pāṭha string into individual Pada structs, resolving accents and compound hyphenation.
generate_krama_patha(padas: &[Pada]) -> Vec<KramaStep>
Section titled “generate_krama_patha(padas: &[Pada]) -> Vec<KramaStep>”Permutes a slice of Pada elements into canonical KramaStep tokens with compound Parigraha and terminal Parigraha clauses.
format_krama_patha(steps: &[KramaStep]) -> String
Section titled “format_krama_patha(steps: &[KramaStep]) -> String”Formats a slice of KramaStep tokens into continuous recitation text separated by single daṇḍas (।) and terminated by a double daṇḍa (॥).
3. Low-Level Core Engines
Section titled “3. Low-Level Core Engines”detect_pragrhya(pada: &Pada) -> Option<PragrhyaType>
Section titled “detect_pragrhya(pada: &Pada) -> Option<PragrhyaType>”Evaluates whether a word is Pragṛhya according to Pāṇinian sūtras:
DualEnding(Pāṇini 1.1.11)PronounAdas(Pāṇini 1.1.12)ArchaicPronoun(Pāṇini 1.1.13)ParticleU(Pāṇini 1.1.13–14)ParticleO(Pāṇini 1.1.15)
generate_parigraha(pada: &Pada) -> String
Section titled “generate_parigraha(pada: &Pada) -> String”Constructs a canonical Parigraha (iti) clause for a Pada:
- Simple pada:
पदम् + इति॑ + पदम् - Terminal m assimilation:
पदम्→पदमिति॑ पदम् - Compound decomposition:
रत्न॒-धात॑मम्→रत्न॒धात॑ममिति॑ रत्न॒-धात॑मम् - Particle u:
ऊँ॒ इति॑ उ
apply_forward_sandhi(p1: &Pada, p2: &Pada) -> String
Section titled “apply_forward_sandhi(p1: &Pada, p2: &Pada) -> String”Applies authentic Vedic euphonic combination across adjacent padas:
- Pāṇini 8.4.66 (udāttād anudāttasya svaritaḥ): Shifts initial anudātta of
p2to svarita ifp1ends in udātta (अ॒ग्निम्+ई॒ळे॒$\to$अ॒ग्निमी॑ळे). - Pāṇini 8.4.67 Exception: Suppresses the svarita shift if
p2contains a following udātta/svarita (दे॒वम्+ऋ॒त्विज॑म्$\to$दे॒वमृ॒त्विज॑म्). - Pronoun Visarga Dropping: Pronoun
सःdrops visarga before consonants (Pāṇini 6.1.132). - Pragṛhya Immunity: Sandhi blocked if
p1.is_pragrhya(). - Final m Assimilation: Merges into vowels, becomes Anusvāra before consonants.
- Unicode Accent Sequences: Guarantees Anusvāra precedes combining pitch marks (
\u0902\u0951).
Data Models
Section titled “Data Models”pub struct Pada { pub raw: String, pub clean: String, pub compound_parts: Vec<String>, pub pragrhya: Option<PragrhyaType>,}raw: The original pada text preserving all Vedic pitch accents and hyphens.clean: Punctuation- and accent-stripped Devanagari text for dictionary lookup and grammatical classification.compound_parts: Individual members if the pada is an analyzed compound (samāsa).pragrhya:Some(PragrhyaType)if the word has Pragṛhya status.
KramaStep
Section titled “KramaStep”pub struct KramaStep { pub first_index: usize, pub second_index: Option<usize>, pub text: String, pub is_parigraha: bool,}first_index: 1-based index of the first pada.second_index: 1-based index of the second pada (Nonefor Parigraha steps).text: Sandhi-joined recitation text for this step.is_parigraha:trueif this step represents an iti closure clause.
GhanaStep
Section titled “GhanaStep”Jaṭā fields plus optional triples for the third pada:
pub struct GhanaStep { pub first_index: usize, pub second_index: Option<usize>, pub third_index: Option<usize>, pub forward_text: String, pub reverse_text: String, pub forward_triple: String, pub reverse_triple: String, pub text: String, pub is_parigraha: bool,}third_index: 1-based index of the third pada (Nonefor Jaṭā fallback of the last pair, and for Parigraha).forward_triple/reverse_triple: sequential sandhi for1-2-3and3-2-1(empty when there is no third pada).