Skip to content

Commit

Permalink
[prakriya] Add sutra tests and update examples
Browse files Browse the repository at this point in the history
Sutra tests:
- Add 1.1.38
- Add 1.4.2
- Add 1.4.12
- Add 1.4.15
- Add 3.2.147
- Add 3.2.148
- Add 3.2.154
- Add 3.2.155
- Add 3.2.156
- Add 3.2.164
- Add 3.2.166
- Add 3.3.106
- Add 3.3.106.v1
- Add 3.3.92
- Add 3.3.96
- Add 3.3.97
- Add 3.3.99
- Add 6.4.13
- Add 6.4.22
- Add 6.4.39
- Add 6.4.74
- Add 8.2.62 (partial)
- Add 8.2.64
- Add 3.3.94 varttikas
- Enable 3.2.146
- Enable 3.2.168
- Enable 3.3.107
- Enable 7.4.40

Examples:
- Add `create_all_krdantas`
- Output sanadi text in `create_all_tinantas`
- Update examples to properly support all vidyut-lipi schemes

API:
- change `upadesha()` to `aupadeshika()`
- Simplify enum iteration with `.copied()`
  • Loading branch information
akprasad committed Dec 12, 2024
1 parent fa37457 commit c7280cb
Show file tree
Hide file tree
Showing 48 changed files with 1,148 additions and 258 deletions.
18 changes: 9 additions & 9 deletions src/bin/create_kosha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn linga_vibhakti_vacana_options() -> Vec<(vp::Linga, vp::Vibhakti, vp::Vacana)>
for linga in vp::Linga::iter() {
for vibhakti in vp::Vibhakti::iter() {
for vacana in vp::Vacana::iter() {
ret.push((*linga, *vibhakti, *vacana))
ret.push((linga, vibhakti, vacana))
}
}
}
Expand Down Expand Up @@ -117,18 +117,18 @@ fn tinanta_options() -> Vec<(
let mut ret = Vec::new();
for prayoga in vp::Prayoga::iter() {
for pada in vp::DhatuPada::iter() {
if *prayoga == vp::Prayoga::Bhave {
if prayoga == vp::Prayoga::Bhave {
// Duplicates karmani -- skip
continue;
}
for lakara in vp::Lakara::iter() {
if *lakara == vp::Lakara::Let {
if lakara == vp::Lakara::Let {
// Experimental -- skip
continue;
}
for purusha in vp::Purusha::iter() {
for vacana in vp::Vacana::iter() {
ret.push((*prayoga, *pada, *lakara, *purusha, *vacana));
ret.push((prayoga, pada, lakara, purusha, vacana));
}
}
}
Expand Down Expand Up @@ -478,18 +478,18 @@ fn create_sarvanamas(padas: &mut PadaVec) {
let prati = vp::Pratipadika::basic(stem);
let lingas = vec![Linga::Pum, Linga::Stri, Linga::Napumsaka];

for (linga, vibhakti, vacana) in &linga_vibhakti_vacana {
let args = vp::Subanta::new(prati.clone(), *linga, *vibhakti, *vacana);
for (linga, vibhakti, vacana) in linga_vibhakti_vacana.iter().copied() {
let args = vp::Subanta::new(prati.clone(), linga, vibhakti, vacana);
let prakriyas = v.derive_subantas(&args);
for p in prakriyas {
let morph = Pada::Subanta(Subanta {
pratipadika: Pratipadika::Basic {
text: stem.to_string(),
lingas: lingas.clone(),
},
linga: Some(Linga::from(*linga)),
vibhakti: Some(Vibhakti::from(*vibhakti)),
vacana: Some(Vacana::from(*vacana)),
linga: Some(Linga::from(linga)),
vibhakti: Some(Vibhakti::from(vibhakti)),
vacana: Some(Vacana::from(vacana)),
is_purvapada: false,
});
let text = p.text();
Expand Down
2 changes: 1 addition & 1 deletion vidyut-kosha/src/morph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ impl From<vp::Dhatu> for Dhatu {
Dhatu {
prefixes: vp.prefixes().to_vec(),
sanadi: vp.sanadi().to_vec(),
text: match vp.upadesha() {
text: match vp.aupadeshika() {
Some(s) => s.to_string(),
None => String::new(),
},
Expand Down
2 changes: 2 additions & 0 deletions vidyut-lipi/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub enum LipiError {
ParseError,
}

impl std::error::Error for LipiError {}

impl fmt::Display for LipiError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use LipiError::*;
Expand Down
8 changes: 4 additions & 4 deletions vidyut-prakriya/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,23 @@ test_krdantas:
../target/release/test_results \
--data-type krdanta \
--test-cases test-files/krdantas-basic.csv \
--hash "2633afc74d312baeaba290c517e2427571bf9a5d2fb6b65b57b97fe3274ed9f0"
--hash "769a763ab754ee5accf0edefa09b38b1084a069c6bf4e183c3f7039c295511fe"
../target/release/test_results \
--data-type krdanta \
--test-cases test-files/krdantas-nic.csv \
--hash "b4ed0d24a5436a3879911ecc1ed420db09128056dea80d298cb12412ff79e04b"
--hash "7be488ee87ad8402487d39cc6e3c0fe8be7a9480e88b02a5eec5e05c4a790d0c"
../target/release/test_results \
--data-type krdanta \
--test-cases test-files/krdantas-san.csv \
--hash "2b1cf48f5b3ad1073c83c9970acf778135bb3375d18b5316a826ece5f2105fca"
--hash "a2de7869bf2c6b534c7075ac37803c232f1c24f6fcc58713d85c4f89bbe79d55"
../target/release/test_results \
--data-type krdanta \
--test-cases test-files/krdantas-yan.csv \
--hash "038ac65be234cfde608106385964b3a67e66fe508d6f91a14b8bff9b6a1c017f"
../target/release/test_results \
--data-type krdanta \
--test-cases test-files/krdantas-yan-luk.csv \
--hash "ed81f38274b4ac93370559b4b7881e80c4403e96770c09fcba0da41f1f39978d"
--hash "6bdaea4c974026fa7bfab4e874b1c3f0368d6a2f35bbf94ad626ab573bf8282d"

test_dhatus:
cargo build --release --bin test_results
Expand Down
36 changes: 18 additions & 18 deletions vidyut-prakriya/data/dhatupatha-ganasutras.tsv
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
01.0933_GawAdayo mitaH
01.0934_janIjFzkanasuraYjo'mantASca
01.0935_jvalahvalahmalanamAmanupasargAdvA
01.0936_glAsnAvanuvamAM ca
01.0937_na kamyamicamAm
01.0938_Samo darSane
01.0939_yamo'parivezaRe
01.0940_sKadiravapariByAM ca
02.0076_carkarItaM ca
04.0162_svAdaya oditaH
10.0493_jYapAdayo mitaH
10.0494_nAnye mito'hetO
10.0495_kusma nAmno vA
10.0496_A kusmAdAtmanepadinaH
10.0497_A garvAdAtmanepadinaH
10.0498_A DfzAdvA
10.0499_A svadaH sakarmakAt
10.0500_hantyarTASca
01.0933 GawAdayo mitaH
01.0934 janIjFzkanasuraYjo'mantASca
01.0935 jvalahvalahmalanamAmanupasargAdvA
01.0936 glAsnAvanuvamAM ca
01.0937 na kamyamicamAm
01.0938 Samo darSane
01.0939 yamo'parivezaRe
01.0940 sKadiravapariByAM ca
02.0076 carkarItaM ca
04.0162 svAdaya oditaH
10.0493 jYapAdayo mitaH
10.0494 nAnye mito'hetO
10.0495 kusma nAmno vA
10.0496 A kusmAdAtmanepadinaH
10.0497 A garvAdAtmanepadinaH
10.0498 A DfzAdvA
10.0499 A svadaH sakarmakAt
10.0500 hantyarTASca
4 changes: 3 additions & 1 deletion vidyut-prakriya/data/varttikas.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
2.1.37.1 BayaBItaBItiBIBiriti vaktavyam
2.4.45.1 iRvadika iti vaktavyam
2.4.54.1 varjane pratizeDo vaktavyaH
2.4.56.2 valAdAvArDaDAtuke vezyate
2.4.56.1 GaYapoH pratizeDe kyapa upasaNKyAnam
2.4.56.2 valAdAvArDaDAtuke vikalpa izyate
3.1.11.1 ojaso'psaraso nityamitarezAM viBAzayA
3.1.14.1 satrakazwakakzakfcCragahaneByaH kaRvacikIrzAyAm iti vaktavyam
3.1.15.2 tapasaH parasmEpadaM ca
Expand All @@ -37,6 +38,7 @@
3.2.60.1 samAnAnyayoSceti vaktavyam
3.2.174.1 krukannapi vaktavyaH
3.2.178.1 kvibvacipracCAyatastukawaprujuSrIRAM dIrGo'saMprasAraRaM ca
3.3.106.1 SradantarorupasargavadvfttiH
3.3.125.1 KanerqaqarekekavakA vAcyAH
4.1.6.1 DAtorugitaH pratizeDaH
4.1.68.1 SvaSurasyokArAkAralopaSca
Expand Down
2 changes: 1 addition & 1 deletion vidyut-prakriya/examples/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn run(dhatupatha: Dhatupatha) -> Result<(), Box<dyn Error>> {
}
}
}
println!("{:?}", dhatu.upadesha());
println!("{:?}", dhatu.aupadeshika());
}

println!("Generated {} forms.", total);
Expand Down
129 changes: 129 additions & 0 deletions vidyut-prakriya/examples/create_all_krdantas.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
//! Creates a very large list of krdantas. This list includes all combinations of:
//!
//! - Around 2000 dhatus from our dhatupatha
//! - 5 sanAdi combinations (none, nic, san, yan, yan-luk)
//! - Around 120 krt-pratyayas from the `Krt` enum, including variants like sya-Satf and sya-SAnac.
//!
//! These combinations produce around 2000 x 5 x 120 = 1.2 million krdantas.
//!
//! Usage:
//!
//! cargo run --release --example create_all_krdantas -- --output-scheme Devanagari
use clap::Parser;
use serde::Serialize;
use std::error::Error;
use std::io;
use vidyut_lipi::{Lipika, Scheme};
use vidyut_prakriya::args::{BaseKrt, Krdanta, Sanadi};
use vidyut_prakriya::{Dhatupatha, Vyakarana};

/// Command line arguments.
#[derive(Parser)]
#[command(author, version, about)]
struct Args {
/// If set, the output scheme to use.
///
/// Any scheme name accepted by `vidyut-prakriya` is valid. Examples: `Devanagari`, `Iso15919`,
/// `Slp1`.
///
/// (Default: `Slp1`)
#[arg(long)]
output_scheme: Option<String>,
}

#[derive(Debug, Serialize)]
struct Row<'a> {
krdantas: String,
dhatu: &'a str,
gana: &'static str,
number: u16,
sanadi: String,
krt: &'static str,
}

fn create_output_string(
lipika: &mut Lipika,
mut items: Vec<String>,
output_scheme: Scheme,
) -> String {
items.sort();
if output_scheme != Scheme::Slp1 {
for s in items.iter_mut() {
*s = lipika.transliterate(&s, Scheme::Slp1, output_scheme);
}
}
items.join("|")
}

fn run(dhatupatha: Dhatupatha, args: Args) -> Result<(), Box<dyn Error>> {
let sanadi_choices = vec![
vec![],
vec![Sanadi::san],
vec![Sanadi::Ric],
vec![Sanadi::yaN],
vec![Sanadi::yaNluk],
];

let v = Vyakarana::builder().log_steps(false).build();
let mut lipika = Lipika::new();
let mut wtr = csv::Writer::from_writer(io::stdout());

let output_scheme: Scheme = match args.output_scheme {
Some(s) => s.parse()?,
None => Scheme::Slp1,
};

for sanadis in &sanadi_choices {
for entry in &dhatupatha {
let dhatu = entry.dhatu().clone().with_sanadi(&sanadis);
for krt in BaseKrt::iter() {
let krdanta = Krdanta::builder().dhatu(dhatu.clone()).krt(krt).build()?;

let prakriyas = v.derive_krdantas(&krdanta);
if prakriyas.is_empty() {
continue;
}

let dhatu_text = &dhatu.aupadeshika().expect("ok");
let krdantas: Vec<_> = prakriyas.iter().map(|p| p.text()).collect();
let krdantas = create_output_string(&mut lipika, krdantas, output_scheme);
let sanadi_text: Vec<_> = sanadis.iter().map(|x| x.as_str()).collect();
let sanadi_text = sanadi_text.join("-");

let row = Row {
krdantas,
dhatu: dhatu_text,
gana: dhatu.gana().expect("ok").as_str(),
number: entry.number(),
sanadi: sanadi_text,
krt: krt.as_str(),
};

wtr.serialize(row)?;
}
}
}

wtr.flush()?;
Ok(())
}

fn main() {
let args = Args::parse();

let dhatus = match Dhatupatha::from_path("data/dhatupatha.tsv") {
Ok(res) => res,
Err(err) => {
println!("{}", err);
std::process::exit(1);
}
};

match run(dhatus, args) {
Ok(()) => (),
Err(err) => {
eprintln!("{}", err);
std::process::exit(1);
}
}
}
Loading

0 comments on commit c7280cb

Please sign in to comment.