Skip to content

Commit

Permalink
[prakriya] Fix various bugs and add more tests
Browse files Browse the repository at this point in the history
Bugs:
- Fix Github issue #121 (aDyApipat)
- Fix Github issue #131 (apIpyat)
- Fix Github issue #132 (ajUhavat)
- Fix Github issue #133 (df should be seT)

Tests:
- Added 6 tests and re-enabled 3 tests

Code:
- Add two leT rules (with no tests)
- Flattened tin-siddhi code for readability. We should probably continue
  this pattern elsewhere. [1]

[1]: http://number-none.com/blow/blog/programming/2014/09/26/carmack-on-inlined-code.html
  • Loading branch information
akprasad committed Oct 29, 2024
1 parent 69d2b55 commit ea4112a
Show file tree
Hide file tree
Showing 15 changed files with 374 additions and 238 deletions.
22 changes: 11 additions & 11 deletions vidyut-prakriya/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,40 +53,40 @@ test_tinantas:
cargo build --release
../target/release/test_tinantas \
--test-cases test-files/tinantas-basic-kartari.csv \
--hash "28293a6aa746f04dff1a5c3b822396c236df269460d691bd137ba01a2c80557f"
--hash "6964b61ad01cfe81b9b8c58cee957cb10db4462cecfded394ebb4631011c742a"
../target/release/test_tinantas \
--test-cases test-files/tinantas-nic-kartari.csv \
--hash "e4ab38f9c71d040bf8cbf7dbc6bb1951749b831240f9248288389a68b24ef413"
--hash "b95f59ca9b070c2eb09edefbea198ef6d4089f28fb494f06993a7a64864fec61"
../target/release/test_tinantas \
--test-cases test-files/tinantas-san-kartari.csv \
--hash "ef278531cd45ba1df9af60e5b4b8ef582fdbe7a7eb31478fe35b9600c42380fc"
--hash "f6d9f65013aa7b420ce57e138872a1acf72285ccfa860a0b2bcf3789e9867a79"
../target/release/test_tinantas \
--test-cases test-files/tinantas-yan-kartari.csv \
--hash "be90fccc6f3907862cf820969094fd958b44b58a447a7a6369edbecde75d8cd4"
--hash "3badfc693401fb722c640875e06fb3169bd8e04176503c6501a1cd2f24fcec37"
../target/release/test_tinantas \
--test-cases test-files/tinantas-yan-luk-kartari.csv \
--hash "aec7b4524b159e195e38ce4b0e5e1335940b60cb41606ba31d1b9fbd010f7d11"
--hash "8e55532333708504593040b4b1025a8568f6d23a07cedd3a8f31e155ae0cc2fb"
../target/release/test_tinantas \
--test-cases test-files/tinantas-basic-karmani.csv \
--hash "b3621fe5bf2295f2f1d15270aa26b9fc973450126cd4a551e53f91571e4d531c"
--hash "4878aa3ec45bef354f7bface2d877ca5cc0fa23ab45b5f52507c4ef3c0a1fc06"
../target/release/test_tinantas \
--test-cases test-files/tinantas-nic-karmani.csv \
--hash "f4760cd6da0496f6db82f1812ba168a18e8cde4e5dffafee815e1e88d19abb36"
--hash "d4c46f2533a47085ac2eb1dcc96d81de25e8fb578b94ccd4c86c4536008bab0b"
../target/release/test_tinantas \
--test-cases test-files/tinantas-san-karmani.csv \
--hash "089160604d7a5a40f8f71e1234cccc3667135b3e2654c4ac346677727e5aae80"
--hash "6ae940a39fcda8d8a24b9e5b905f02a4db9c22cb3bc54f9a996c82b24fbb2120"
../target/release/test_tinantas \
--test-cases test-files/tinantas-yan-karmani.csv \
--hash "260a684b78e4e66a68f89366c07850d1680a72424e2934392678359289a1916b"
--hash "4e7399574447252f72eb2d36cd85eba8f5f20bd9d38aac8802825ec8aa3fb2dd"

test_krdantas:
cargo build --release
../target/release/test_krdantas \
--test-cases test-files/krdantas-ktvA.csv \
--hash "59470473bec6cb2d2254217d604a2302c6ee8926571441b3281004a30abc81ce"
--hash "1f41354393e7490afe73a2cb7f873bc75c6495a6188f739f5ecac08a2ee725a4"
../target/release/test_krdantas \
--test-cases test-files/krdantas-kta.csv \
--hash "2ce641122f4c6ac243acb348d376f35586c5f960ea338b9b1f7b79f0f72e3c12"
--hash "aa72a9d4cec0f82248de228108ab881789962c12fe0094134657a55340822247"

test_subantas:
cargo run --bin test_subantas -- \
Expand Down
8 changes: 6 additions & 2 deletions vidyut-prakriya/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<p><i>A Paninian word generator</i></p>
</div>

(Published as [A fast prakriyā generator][paper] at ISCLS 2024.)
[paper]: https://iscls.github.io/assets/files/proceedings/2024.iscls.7.pdf

`vidyut-prakriya` generates Sanskrit words with their prakriyās (derivations)
according to the rules of Paninian grammar and currently implements around
2,000 rules. Our long-term goal is to provide a complete implementation of the
Expand Down Expand Up @@ -47,8 +50,9 @@ Overview
crate can be compiled to WebAssembly, which means that it can run in a
modern web browser.

`vidyut-prakriya` currently has strong support for basic verbs. For future plans,
see our [roadmap](#roadmap).
`vidyut-prakriya` has excellent support for Sanskrit's basic word types,
including *subanta*s, *tiṅanta*s, *kṛdanta*s, and *taddhitānta*s. It has
moderate support for *samāsa*s and weak support for accent rules.


Usage
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 @@ -1467,7 +1467,7 @@ code dhatu artha
05.0034 ciri hiMsAyAm
05.0035 jiri hiMsAyAm
05.0036 dASa~ hiMsAyAm
05.0037 df hiMsAyAm
05.0037 df\ hiMsAyAm
05.0038 f\kzi hiMsAyAm
06.0001 tu\da~^ vyaTane
06.0002 Ru\da~^ preraRe
Expand Down
5 changes: 4 additions & 1 deletion vidyut-prakriya/src/angasya.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,8 +1137,11 @@ fn try_cani_after_guna(p: &mut Prakriya) -> Option<()> {
if i > 0 && dhatu.has_u("pA\\") && dhatu.has_gana(Bhvadi) {
// apIpyat
p.run("7.4.4", |p| {
p.set(i - 1, |t| {
t.set_antya("I");
t.add_tag(T::FlagNoHrasva);
});
p.set(i, |t| t.set_antya(""));
p.set(i - 1, |t| t.set_antya("I"));
});
return None;
} else if i > 0 && dhatu.has_u("zWA\\") {
Expand Down
3 changes: 2 additions & 1 deletion vidyut-prakriya/src/angasya/abhyasasya.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,9 @@ fn try_general_rules(p: &mut Prakriya, i: usize) -> Option<()> {
}
}

// no-hrasva is for pA --> apIpyat.
let abhyasa = p.get(i)?;
if al::is_dirgha(abhyasa.antya()?) {
if al::is_dirgha(abhyasa.antya()?) && !abhyasa.has_tag(T::FlagNoHrasva) {
let val = al::to_hrasva(abhyasa.antya()?)?;
p.run_at("7.4.59", i, op::antya(&val.to_string()));
}
Expand Down
28 changes: 23 additions & 5 deletions vidyut-prakriya/src/ardhadhatuka.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! ardhadhatuka
use crate::args::{Gana, Lakara, Unadi};
use crate::args::{Dhatu, Gana, Lakara, Sanadi, Unadi};
use crate::core::operators as op;
use crate::core::Rule::Varttika;
use crate::core::Tag as T;
Expand Down Expand Up @@ -114,7 +114,11 @@ pub fn dhatu_adesha_before_pada(p: &mut Prakriya, la: Lakara) {
///
/// These rules must run before we choose the vikarana because the results here affect which
/// vikarana we add.
fn try_dhatu_adesha_before_vikarana(p: &mut Prakriya, la: Option<Lakara>) -> Option<()> {
fn try_dhatu_adesha_before_vikarana(
p: &mut Prakriya,
is_sani_or_cani: bool,
la: Option<Lakara>,
) -> Option<()> {
let i = p.find_first(T::Dhatu)?;
let j = p.find_next_where(i, |t| !t.is_empty())?;
let dhatu = p.get(i)?;
Expand Down Expand Up @@ -186,7 +190,10 @@ fn try_dhatu_adesha_before_vikarana(p: &mut Prakriya, la: Option<Lakara>) -> Opt
let to_gaa = |p: &mut Prakriya| op::upadesha_no_it(p, i, "gAN");
let mut run_it = false;

if p.has(i + 1, |t| t.has_u("Ric")) && p.has(i + 2, |t| t.has_u_in(&["san", "caN"])) {
if p.has(i + 1, |t| t.has_u("Ric")) && !p.has(i + 2, |_| true) && is_sani_or_cani {
// aDijigApayizati, aDyApipayizati; aDyajIgapat, aDyApipat
// Run in anticipation of san and caN, e.g.:
// https://www.sanskritam.world/vyakaranam/sutraani/2/4/51
run_it = p.optional_run("2.4.51", to_gaa);
} else if n.has_u("san") {
// aDijigAMsate
Expand Down Expand Up @@ -384,6 +391,7 @@ pub fn try_add_am_agama(p: &mut Prakriya) -> Option<()> {

pub fn run_before_vikarana(
p: &mut Prakriya,
dhatu: Option<&Dhatu>,
la: Option<Lakara>,
la_is_ardhadhatuka: bool,
) -> Option<()> {
Expand All @@ -399,10 +407,20 @@ pub fn run_before_vikarana(

let i = p.find_first(T::Dhatu)?;

// Check the following term in case we have `san`, etc.
// Check if the following pratyaya will be san or can, for 2.4.51 (णौ च सँश्चङोः)
let is_sani = match dhatu {
Some(Dhatu::Mula(d)) => d.sanadi().iter().any(|s| *s == Sanadi::san),
Some(Dhatu::Nama(d)) => d.other_sanadi().iter().any(|s| *s == Sanadi::san),
None => false,
};
let is_cani = la == Some(Lakara::Lun) && p.terms().last().map_or(false, |t| t.is_ni_pratyaya());
let is_sani_or_cani = is_sani || is_cani;

// These rules run both if the following prakriya is ArdhadhAtuka and if we must anticipate
// ArdhadhAtuka (e.g. from lakAra).
if p.has(i + 1, |t| t.is_ardhadhatuka()) || la_is_ardhadhatuka {
// Rules are under 2.4.35 "ArdhadhAtuke".
try_dhatu_adesha_before_vikarana(p, la);
try_dhatu_adesha_before_vikarana(p, is_sani_or_cani, la);
}

Some(())
Expand Down
16 changes: 8 additions & 8 deletions vidyut-prakriya/src/args/tin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::core::Tag;
use crate::enum_boilerplate;
use wasm_bindgen::prelude::wasm_bindgen;

/// The prayoga of some tinanta.
/// The prayoga of some tiṅanta.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[wasm_bindgen]
pub enum Prayoga {
Expand Down Expand Up @@ -33,7 +33,7 @@ impl Prayoga {
}
}

/// The person of some tinanta.
/// The person of some tiṅanta.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[wasm_bindgen]
pub enum Purusha {
Expand Down Expand Up @@ -61,7 +61,7 @@ impl Purusha {
}
}

/// The number of some tinanta or subanta.
/// The number of some tiṅanta or subanta.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[wasm_bindgen]
pub enum Vacana {
Expand Down Expand Up @@ -89,7 +89,7 @@ impl Vacana {
}
}

/// The tense/mood of some tinanta.
/// The tense/mood of some tiṅanta.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[wasm_bindgen]
pub enum Lakara {
Expand Down Expand Up @@ -154,7 +154,7 @@ impl Lakara {
}
}

/// The pada of some tinanta or krdanta.
/// The pada of some tiṅanta or kṛdanta.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[wasm_bindgen]
pub enum DhatuPada {
Expand All @@ -178,10 +178,10 @@ impl DhatuPada {
}
}

/// The information required to derive a tinanta in the grammar.
/// The information required to derive a tiṅanta in the grammar.
///
/// If a tinanta were just a matter of prayoga/purusha/lakara/vacana, a struct like this would not
/// be necessary. However, a tinanta's derivation can have many other constraints, including:
/// If a tiṅanta were just a matter of prayoga/purusha/lakara/vacana, a struct like this would not
/// be necessary. However, a tiṅanta's derivation can have many other constraints, including:
///
/// - specific upasargas or other prefixes
/// - specific sanAdi pratyayas
Expand Down
Loading

0 comments on commit ea4112a

Please sign in to comment.