Skip to content

Commit

Permalink
[prakriya] Fix several krdanta overgeneration bugs
Browse files Browse the repository at this point in the history
Main fixes:

- Fix an overgeneration bug related to creating the `icCA` nipata.
  Without this fix, we generate the form `icCA` for all krt-pratyayas
  not supported by `izu~`.

- Fix an overgeneration bug caused by matching against the start of the
  dhatu instead of the end of it. This causes us to create forms with
  various sanAdi dhatus that are not allowed.

- Fix an output bug related to the dhatus `ay` and `av` in connection
  with `kvip` and `vic`.

Other fixes:

- Fix the dhatu `smf` so that it is marked as anit.

- Fix `bench.rs` compile errors
  • Loading branch information
akprasad committed Dec 14, 2024
1 parent 560f82b commit ff2dd76
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 102 deletions.
63 changes: 29 additions & 34 deletions vidyut-prakriya/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
# Main commands
# ~~~~~~~~~~~~~

# Generates all tinantas supported by the program and writes them to stdout.
create_tinantas:
cargo run --release --bin create_tinantas


# Generates all krdantas-prAtipadikas supported by the program and writes them to stdout.
create_krdantas:
cargo run --release --bin create_krdantas


# Unit tests
# ~~~~~~~~~~

Expand All @@ -27,8 +14,10 @@ coverage:
# ~~~~~~~~~~~~~~~~~

# Generates all tinantas supported by the program and writes them to disk.
create_test_files:
cargo build --release
create_test_files: create_tinantas create_krdantas create_dhatus

create_tinantas:
cargo build --release --bin create_tinantas
../target/release/create_tinantas --prayoga kartari > test-files/tinantas-basic-kartari.csv
../target/release/create_tinantas --prayoga kartari --sanadi Ric > test-files/tinantas-nic-kartari.csv
../target/release/create_tinantas --prayoga kartari --sanadi san > test-files/tinantas-san-kartari.csv
Expand All @@ -42,11 +31,17 @@ create_test_files:
../target/release/create_tinantas --prayoga karmani --sanadi yaN > test-files/tinantas-yan-karmani.csv
../target/release/create_tinantas --prayoga karmani --sanadi san,Ric > test-files/tinantas-san-nic-karmani.csv
../target/release/create_tinantas --prayoga karmani --sanadi Ric,san > test-files/tinantas-nic-san-karmani.csv

create_krdantas:
cargo build --release --bin create_krdantas
../target/release/create_krdantas > test-files/krdantas-basic.csv
../target/release/create_krdantas --sanadi Ric > test-files/krdantas-nic.csv
../target/release/create_krdantas --sanadi san > test-files/krdantas-san.csv
../target/release/create_krdantas --sanadi yaN > test-files/krdantas-yan.csv
../target/release/create_krdantas --sanadi yaNluk > test-files/krdantas-yan-luk.csv

create_dhatus:
cargo build --release --bin create_dhatus
../target/release/create_dhatus > test-files/dhatus.csv

# Runs a full evaluation over all forms generated by vidyut-prakriya. `hash` is
Expand All @@ -62,85 +57,85 @@ test_tinantas:
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-basic-kartari.csv \
--hash "2dfbc74c55529c9b2ce8dc3202b7c7dca844a4c8f207c2d729ce1fed921fe1b2"
--hash "abe62f683a0c3e8cec8f3536e7ea0234ea8af68d6cf7b49e209597eb8f855476"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-nic-kartari.csv \
--hash "2901d9a7323bd662909ff4ad75d4e8237dca576a92dae36d3059431584c77f9c"
--hash "9bfa0fd1eb7d49b4cdf15d50d5c1dbc053dfafbe1a4da673ec41a66fdfa2fc9a"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-san-kartari.csv \
--hash "f54f89f6652176d48781baab2ea006f4ffc3dc637da1b7fa32b53c0bd7775ff2"
--hash "d3cf5ec44079bceb409696598b68bf3f57b604d48e018a3360dcb00ff5c04fb8"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-yan-kartari.csv \
--hash "69fa8583b872d0c8f21f42815515a7457050a583fad99c062831d817a6094db4"
--hash "1b7d63e8da81ae220a9787b77588d021daeca9696fd58e6ed463bc3e8ac1e8e4"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-yan-luk-kartari.csv \
--hash "0c4776f55b80bdb4e69e137c258d7365efa1f4e6f1e8c58753846646041428ec"
--hash "3256297c907d762d0809d38168172fa151e168187542031b09ef7bf460bc4c28"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-san-nic-kartari.csv \
--hash "58ccd63ddcb785e84253990bb379aad51d93e68b421adf2e0be9c70edf454bd3"
--hash "18d96165568b2fcf470c15aace41454010f548ec4559cdac24b1f1fd209af340"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-nic-san-kartari.csv \
--hash "6618699600fdd272c6cfbe1ffad7567f9bdd8950dfabeb859e6cfffed83836f1"
--hash "e396839ebf339561d0dcaf87b695d1675ac113629d0a0becbe695a1ac77926a5"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-basic-karmani.csv \
--hash "66fa96d66a1fb52d639cc6516c89c54883d71cad2e3558c9984cfdc2d75a6b5e"
--hash "b8540f8aca8eb202fb1cb949ebff90332df7658a2bf94f12542b59196ed80cc8"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-nic-karmani.csv \
--hash "218964795f2d8dba96cefa0f49578f0c636575325bd23412bc10d80fbbb1545a"
--hash "afb4807a99475dd7480c41f0a4baf59d8bdce1c65a8e5340fcaaf189f190b110"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-san-karmani.csv \
--hash "a682c39d420379ebc77598154a4804d94f6c35632877f5cc508b46ddbd548ba9"
--hash "9d40a83d67a79556a8c2491430ab5f5884b8a1a89ed64786a45a987637cd7c3f"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-yan-karmani.csv \
--hash "f4c2dedc816bec356e97c46831ce35c2272ffeb2d5bb29bfa332cff393e67c9f"
--hash "9311a5467efadbf224b4f9dc6b981eb3845118cc187adeecc957b41c1f3acd78"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-san-nic-karmani.csv \
--hash "ef958478945d449bbd093b02a7f4b84f14939c365c67cec65481b168c2ffdc97"
--hash "ea21729c7a4ceb7fcc2c66af097a0f053daf06b0e36c9324b8cbd34d82f9fbe7"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-nic-san-karmani.csv \
--hash "e6ce97fcae9a5855dad2486737e8e28f4a7581190d7b10f9e9592603374504c8"
--hash "4845c125a3acab60fe9189960ace4402cd244db527bd16f7238930a39c547ba8"

test_krdantas:
cargo build --release --bin test_results
../target/release/test_results \
--data-type krdanta \
--test-cases test-files/krdantas-basic.csv \
--hash "90bf0b99a2b641c74a77bbfc1864d904a5ce05ba5aa011f69ea0b12b6e2693e4"
--hash "540f1595ec0ac3957cc00dd236dd6af67307b26cc45312b13e2a164ddfaeb89d"
../target/release/test_results \
--data-type krdanta \
--test-cases test-files/krdantas-nic.csv \
--hash "58fb5d4eef55f5b0d8475e87665cba0038d6daf882399c60a03972e5abc7ed28"
--hash "2d912641df671b2f76920efc0ed31d25d8d13a4dffb74afa471351df6ae0bc31"
../target/release/test_results \
--data-type krdanta \
--test-cases test-files/krdantas-san.csv \
--hash "a689755607b5b634f36ffdb9f01aba212df68eab3d1ddf5cf1cbd8b25ffafaa3"
--hash "4870af19eb0e42847f8f1d532e66d71312a702454aee1e47275a953cd56fe8e6"
../target/release/test_results \
--data-type krdanta \
--test-cases test-files/krdantas-yan.csv \
--hash "7d14c2e8d6f83eff87b6cbdcfb3fedf66bde3e880a555a836b0feaaecee3bc41"
--hash "2af8e18fcfd0952679fa69b5011c3b40cdca83b6a899b453d62c6d7a9ebc54a5"
../target/release/test_results \
--data-type krdanta \
--test-cases test-files/krdantas-yan-luk.csv \
--hash "49cfda9501ba6076e7285a131d9efb1f2d0964fabb71b2e176d94a151e6695c9"
--hash "5399c6a8f2d13ba00b0249ee9b9359ef4c6f4f075e6ab459c97b591cecc71545"

test_dhatus:
cargo build --release --bin test_results
../target/release/test_results \
--data-type dhatu \
--test-cases test-files/dhatus.csv \
--hash "bc7d210cc44e1231e0f89d3f6e39de4288b0c75fa108a1168003fc7c33a16965"
--hash "793e576b1b24e4982a8f51e4789927786eb17eabbeb0fd5c29dc77d89a8eb4b2"


test_subantas:
Expand Down
2 changes: 1 addition & 1 deletion vidyut-prakriya/data/dhatupatha.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ code dhatu artha
01.0916 jvala~ dIptO
01.0917 hvala~ calane
01.0918 hmala~ calane
01.0919 smf ADyAne
01.0919 smf\ ADyAne
01.0920 dF Baye
01.0921 nF naye
01.0922 SrA pAke
Expand Down
12 changes: 6 additions & 6 deletions vidyut-prakriya/examples/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn linga_vibhakti_vacana_options() -> Vec<(Linga, Vibhakti, Vacana)> {
for linga in Linga::iter() {
for vibhakti in Vibhakti::iter() {
for vacana in Vacana::iter() {
ret.push((*linga, *vibhakti, *vacana))
ret.push((linga, vibhakti, vacana))
}
}
}
Expand Down Expand Up @@ -41,16 +41,16 @@ fn run(dhatupatha: Dhatupatha) -> Result<(), Box<dyn Error>> {
for sanadis in &sanadi_choices {
let full_dhatu = dhatu.clone().with_sanadi(&sanadis);

for prayoga in &[Prayoga::Kartari, Prayoga::Karmani] {
for prayoga in [Prayoga::Kartari, Prayoga::Karmani] {
for lakara in Lakara::iter() {
for purusha in Purusha::iter() {
for vacana in Vacana::iter() {
let tinanta = Tinanta::builder()
.dhatu(full_dhatu.clone())
.prayoga(*prayoga)
.purusha(*purusha)
.vacana(*vacana)
.lakara(*lakara)
.prayoga(prayoga)
.purusha(purusha)
.vacana(vacana)
.lakara(lakara)
.build()?;

let prakriyas = v.derive_tinantas(&tinanta);
Expand Down
3 changes: 3 additions & 0 deletions vidyut-prakriya/src/args/taddhita.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ pub enum Taddhita {
/// -la
lac,
/// -vat
vati,
/// -vat
vatup,
/// -vaya
vaya,
Expand Down Expand Up @@ -512,6 +514,7 @@ enum_boilerplate!(Taddhita, {
rUpya => "rUpya",
lac => "lac",
rUpap => "rUpap",
vati => "vati~",
vatup => "vatu~p",
vaya => "vaya",
valac => "valac",
Expand Down
12 changes: 1 addition & 11 deletions vidyut-prakriya/src/bin/create_krdantas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ struct Row<'a> {
vacana: Vacana,
}

const KRDANTAS: &[BaseKrt] = &[
BaseKrt::kta,
BaseKrt::ktavatu,
BaseKrt::Satf,
BaseKrt::SAnac,
BaseKrt::tavya,
BaseKrt::anIyar,
BaseKrt::yat,
];

/// Creates a collection of (linga, vibhakti, vacana) combinations.
fn linga_vibhakti_vacana_options() -> Vec<(Linga, Vibhakti, Vacana)> {
let mut ret = Vec::new();
Expand Down Expand Up @@ -67,7 +57,7 @@ fn run(dhatupatha: Dhatupatha, args: Args) -> Result<(), Box<dyn Error>> {
.fold(String::new(), |b, x| b + x + "+");
let sanadi_str = sanadi_str.trim_end_matches('+');

for krt in KRDANTAS.iter().copied() {
for krt in BaseKrt::iter() {
let krdanta = Krdanta::builder().dhatu(dhatu.clone()).krt(krt).build()?;

for (linga, vibhakti, vacana) in lvv.iter().copied() {
Expand Down
6 changes: 3 additions & 3 deletions vidyut-prakriya/src/bin/test_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,16 @@ fn test_dhatu(line: &str) -> Result<(), Box<dyn Error>> {
fn run(args: Args) -> Result<(), Box<dyn Error>> {
check_file_hash(&args.test_cases, &args.hash);

let file = std::fs::read_to_string(&args.test_cases)?;

if args.data_type == "krdanta" {
let mut r = csv::Reader::from_reader(file.as_bytes());
let mut r = csv::Reader::from_path(&args.test_cases)?;
r.deserialize().par_bridge().for_each(|row| {
match test_krdanta(row) {
Ok(()) => (),
Err(e) => println!("ERROR: Row is malformed: {e}"),
};
});
} else if args.data_type == "tinanta" {
let file = std::fs::read_to_string(&args.test_cases)?;
file.lines()
.skip(1)
.par_bridge()
Expand All @@ -204,6 +203,7 @@ fn run(args: Args) -> Result<(), Box<dyn Error>> {
Err(_) => println!("ERROR: Row is malformed: {line}"),
});
} else if args.data_type == "dhatu" {
let file = std::fs::read_to_string(&args.test_cases)?;
file.lines()
.skip(1)
.par_bridge()
Expand Down
Loading

0 comments on commit ff2dd76

Please sign in to comment.