-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[prakriya] Add sutra tests and update examples
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
Showing
48 changed files
with
1,148 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.