Skip to content

Commit

Permalink
[prakriya] Add better support for kvasu~
Browse files Browse the repository at this point in the history
In addition:
- Simplify binaries that create and test snapshots.
- Rename `upadesha` to `aupadeshika` in various functions.
  • Loading branch information
akprasad committed Dec 24, 2024
1 parent ff2dd76 commit 5d6cd17
Show file tree
Hide file tree
Showing 21 changed files with 621 additions and 679 deletions.
98 changes: 24 additions & 74 deletions vidyut-prakriya/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,10 @@ coverage:
# Integration tests
# ~~~~~~~~~~~~~~~~~

# Generates all tinantas supported by the program and writes them to disk.
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
../target/release/create_tinantas --prayoga kartari --sanadi yaN > test-files/tinantas-yan-kartari.csv
../target/release/create_tinantas --prayoga kartari --sanadi yaNluk > test-files/tinantas-yan-luk-kartari.csv
../target/release/create_tinantas --prayoga kartari --sanadi san,Ric > test-files/tinantas-san-nic-kartari.csv
../target/release/create_tinantas --prayoga kartari --sanadi Ric,san > test-files/tinantas-nic-san-kartari.csv
../target/release/create_tinantas --prayoga karmani > test-files/tinantas-basic-karmani.csv
../target/release/create_tinantas --prayoga karmani --sanadi Ric > test-files/tinantas-nic-karmani.csv
../target/release/create_tinantas --prayoga karmani --sanadi san > test-files/tinantas-san-karmani.csv
../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
# Generates all tinantas, krdantas, and dhatus supported by the program and writes them to disk.
create_test_files:
cargo build --release --bin create_test_files
../target/release/create_test_files --output-dir test-files

# Runs a full evaluation over all forms generated by vidyut-prakriya. `hash` is
# the SHA-256 hash of the test file. We use `hash` to verify test file
Expand All @@ -56,86 +30,62 @@ test_tinantas:
cargo build --release --bin test_results
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-basic-kartari.csv \
--hash "abe62f683a0c3e8cec8f3536e7ea0234ea8af68d6cf7b49e209597eb8f855476"
--test-cases test-files/tinantas-basic.csv \
--hash "b5af09ca0580ca14484f75618e7515b29c16054111092b5cc550accb244e1e28"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-nic-kartari.csv \
--hash "9bfa0fd1eb7d49b4cdf15d50d5c1dbc053dfafbe1a4da673ec41a66fdfa2fc9a"
--test-cases test-files/tinantas-nic.csv \
--hash "d8cf36e3354075b014761ecb39180655f50498c032fd262e0f9f3d7e0558ab95"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-san-kartari.csv \
--hash "d3cf5ec44079bceb409696598b68bf3f57b604d48e018a3360dcb00ff5c04fb8"
--test-cases test-files/tinantas-san.csv \
--hash "bb44e1642942c47e8d4fe09cefdab4f005c0b2653e4dc72f847b9cbf33ac9694"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-yan-kartari.csv \
--hash "1b7d63e8da81ae220a9787b77588d021daeca9696fd58e6ed463bc3e8ac1e8e4"
--test-cases test-files/tinantas-yan.csv \
--hash "06b136ed48064c00eed2e6320ebdc8b086a0e93bd3dedbb375a3d680f23a14a0"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-yan-luk-kartari.csv \
--hash "3256297c907d762d0809d38168172fa151e168187542031b09ef7bf460bc4c28"
--test-cases test-files/tinantas-yan-luk.csv \
--hash "7cd36afdcd38beef9bd66db40e41a080e2db2aea794f6daa06e926096ae48104"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-san-nic-kartari.csv \
--hash "18d96165568b2fcf470c15aace41454010f548ec4559cdac24b1f1fd209af340"
--test-cases test-files/tinantas-san-nic.csv \
--hash "c1f561806c1639926621dcabf69a31285b99f00c80e5fa57e3a4a4afa9310499"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-nic-san-kartari.csv \
--hash "e396839ebf339561d0dcaf87b695d1675ac113629d0a0becbe695a1ac77926a5"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-basic-karmani.csv \
--hash "b8540f8aca8eb202fb1cb949ebff90332df7658a2bf94f12542b59196ed80cc8"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-nic-karmani.csv \
--hash "afb4807a99475dd7480c41f0a4baf59d8bdce1c65a8e5340fcaaf189f190b110"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-san-karmani.csv \
--hash "9d40a83d67a79556a8c2491430ab5f5884b8a1a89ed64786a45a987637cd7c3f"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-yan-karmani.csv \
--hash "9311a5467efadbf224b4f9dc6b981eb3845118cc187adeecc957b41c1f3acd78"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-san-nic-karmani.csv \
--hash "ea21729c7a4ceb7fcc2c66af097a0f053daf06b0e36c9324b8cbd34d82f9fbe7"
../target/release/test_results \
--data-type tinanta \
--test-cases test-files/tinantas-nic-san-karmani.csv \
--hash "4845c125a3acab60fe9189960ace4402cd244db527bd16f7238930a39c547ba8"
--test-cases test-files/tinantas-nic-san.csv \
--hash "8e102d104eea6483e82ad2be8a8005716586ce4b0d2aa447fc20ada0f2882158"

test_krdantas:
cargo build --release --bin test_results
../target/release/test_results \
--data-type krdanta \
--test-cases test-files/krdantas-basic.csv \
--hash "540f1595ec0ac3957cc00dd236dd6af67307b26cc45312b13e2a164ddfaeb89d"
--hash "4ff8687f9a2c36eddd58a23637983ec87319ed5c4616aabe686d0e2b91a558b2"
../target/release/test_results \
--data-type krdanta \
--test-cases test-files/krdantas-nic.csv \
--hash "2d912641df671b2f76920efc0ed31d25d8d13a4dffb74afa471351df6ae0bc31"
--hash "2acacdc4000bd02a58905ef431a65d9d3666296ef9ed9ab0571935f7586e12b9"
../target/release/test_results \
--data-type krdanta \
--test-cases test-files/krdantas-san.csv \
--hash "4870af19eb0e42847f8f1d532e66d71312a702454aee1e47275a953cd56fe8e6"
--hash "294ecfdf8ad81c0164c466b423a3f088f01c7de7894d5efb5fadb74294bf05ff"
../target/release/test_results \
--data-type krdanta \
--test-cases test-files/krdantas-yan.csv \
--hash "2af8e18fcfd0952679fa69b5011c3b40cdca83b6a899b453d62c6d7a9ebc54a5"
--hash "51d9faea44e8295a8e942a0bab8d8f66d4412ff9767c70d24be4408648b7781f"
../target/release/test_results \
--data-type krdanta \
--test-cases test-files/krdantas-yan-luk.csv \
--hash "5399c6a8f2d13ba00b0249ee9b9359ef4c6f4f075e6ab459c97b591cecc71545"
--hash "7e28699c1de0739c567b6007cad110487f59a8bbb3ecad31cc51b990840b6a08"

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


test_subantas:
Expand Down
8 changes: 4 additions & 4 deletions vidyut-prakriya/examples/create_tinantas_babylon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ fn create_entry(
let tinanta = Tinanta::builder()
.dhatu(dhatu)
.prayoga(prayoga)
.purusha(*purusha)
.vacana(*vacana)
.purusha(purusha)
.vacana(vacana)
.pada(pada)
.lakara(lakara)
.build()
Expand Down Expand Up @@ -184,7 +184,7 @@ fn create_entry(
}

// Don't print for last purusha.
if *purusha != Purusha::Uttama {
if purusha != Purusha::Uttama {
html_row += "<br>---"
}
}
Expand Down Expand Up @@ -227,7 +227,7 @@ fn run(dp: Dhatupatha, args: Args) {
for dhatu_entry in dp {
for lakara in Lakara::iter() {
for pada in &[DhatuPada::Parasmai, DhatuPada::Atmane] {
let entry = create_entry(&v, &dhatu_entry, args.sanadi, prayoga, *pada, *lakara);
let entry = create_entry(&v, &dhatu_entry, args.sanadi, prayoga, *pada, lakara);
if let Some(e) = entry {
print!("{}\n{}\n\n", e.search_row, e.html_row);
}
Expand Down
5 changes: 3 additions & 2 deletions vidyut-prakriya/examples/print_prakriyas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn main() {
// Create a basic dhatu with `Dhatu::mula`
//
// For supported dhatus, see `dhatupatha.tsv`.
let bhu = Dhatu::mula("BU", Gana::Bhvadi);
let bhu = Dhatu::mula(Slp1String::from("BU").expect("ok"), Gana::Bhvadi);

let args = Tinanta::builder()
.dhatu(bhu)
Expand All @@ -58,7 +58,8 @@ fn main() {
print_prakriyas(&prakriyas);

// Create a sannanta dhatu with `with_sanadi`.
let jijnasa = Dhatu::mula("jYA\\", Gana::Kryadi).with_sanadi(&[Sanadi::san]);
let jijnasa = Dhatu::mula(Slp1String::from("jYA\\").expect("ok"), Gana::Kryadi)
.with_sanadi(&[Sanadi::san]);

let args = Tinanta::builder()
.dhatu(jijnasa)
Expand Down
57 changes: 50 additions & 7 deletions vidyut-prakriya/src/angasya.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use crate::core::char_view::IndexPrakriya;
use crate::core::operators as op;
use crate::core::{Morph, Prakriya, PrakriyaTag as PT, Rule, Rule::Varttika, Tag as T, Term};
use crate::dhatu_gana as gana;
use crate::it_agama;
use crate::it_samjna;
use crate::sounds as al;
use crate::sounds::{s, Set};
Expand Down Expand Up @@ -408,6 +409,7 @@ fn try_change_cu_to_ku(p: &mut Prakriya, i: usize) -> Option<()> {
if anga.is_abhyasta() {
p.run_at("7.3.55", i, op::adi("G"));
} else if n.last().has_tag_in(&[T::Yit, T::Rit]) || anga.has_text("hn") {
// GAtaka, Gnanti, ...
p.run_at("7.3.54", i, op::adi("G"));
}
} else if anga.is_u(Au::hi) && anga.is_abhyasta() && !n.last().is(V::caN) {
Expand Down Expand Up @@ -1393,7 +1395,12 @@ pub fn run_before_dvitva(p: &mut Prakriya, is_lun: bool, skip_at_agama: bool) ->
for i in 0..p.len() {
// Must run before asiddhavat for sTA + kta -> sTita
try_anga_changes_before_t(p, i);
asiddhavat::run_after_guna(p, i);
}

if !p.terms().iter().any(|t| t.has_u("kvasu~")) {
for i in 0..p.len() {
run_after_it_agama_karya(p, i);
}
}

// Tries adding tuk-Agama for krt-pratyayas that are pit.
Expand Down Expand Up @@ -1492,31 +1499,67 @@ pub fn run_before_dvitva(p: &mut Prakriya, is_lun: bool, skip_at_agama: bool) ->
Some(())
}

/// Runs rules that should apply only after we have resolved it-Agama.
///
/// Examples:
/// - Rules that condition on the first sound of a pratyaya.
/// - Rules that condition specifically on iw-Agama.
pub fn run_after_it_agama_karya(p: &mut Prakriya, i: usize) -> Option<()> {
asiddhavat::run_after_guna(p, i);

Some(())
}

/// Runs rules that should apply only after we have resolved both iw-Agama and dvitva.
///
/// Examples:
/// - Rules that delete 'A' of dhatu if iw-Agama follows. (Should be done after dvitva.)
pub fn run_after_it_agama_karya_and_dvitva_karya(p: &mut Prakriya, i: usize) -> Option<()> {
asiddhavat::run_after_it_agama_karya_and_dvitva_karya(p, i);
try_change_cu_to_ku(p, i);
asiddhavat::run_for_kniti_ardhadhatuke_after_dvitva(p, i);
Some(())
}

pub fn run_after_dvitva(p: &mut Prakriya) -> Option<()> {
subanta::run(p);
if !p.terms().iter().any(|t| t.has_u("kvasu~")) {
for i in 0..p.len() {
run_after_it_agama_karya_and_dvitva_karya(p, i);
}
}

for i in 0..p.len() {
asiddhavat::run_after_dvitva(p, i);
asiddhavat::run_for_kniti_ardhadhatuke_after_dvitva(p, i);
asiddhavat::try_run_kniti_for_dhatu(p, i);
}

// Must come before asiddhavat rule 6.4.78 (e.g. "iyarti", ekahalmadhya)
abhyasasya::run(p);

for i in 0..p.len() {
asiddhavat::try_et_adesha_and_abhyasa_lopa_for_lit(p, i);
}

// ADDED for ciccheda, etc.
try_add_tuk_agama(p);

for i in 0..p.len() {
unknown(p, i);
try_tas_asti_lopa(p, i);

try_didhi_vevi_lopa(p, i);
}

for i in 0..p.terms().len() {
try_change_cu_to_ku(p, i);
abhyasasya::run_for_sani_or_cani(p);

for i in 0..p.len() {
let finished = it_agama::run_for_kvasu_pratyaya(p, i);
if finished.unwrap_or(false) {
run_after_it_agama_karya(p, i);
run_after_it_agama_karya_and_dvitva_karya(p, i);
}
}

abhyasasya::run_for_sani_or_cani(p);
subanta::run(p);

for index in 0..p.len() {
try_ato_dirgha(p, index);
Expand Down
5 changes: 3 additions & 2 deletions vidyut-prakriya/src/angasya/abhyasasya.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,14 @@ fn try_rules_for_lit(p: &mut Prakriya, i: usize) -> Option<()> {

let abhyasa = p.get(i)?;
let dhatu = p.get(i_dhatu)?;
let last = p.terms().last()?;
let i_n = p.find_next_where(i_dhatu, |t| t.is_pratyaya())?;
let next = p.get(i_n)?;

fn add_nut_agama(rule: impl Into<Rule>, p: &mut Prakriya, i: usize) {
op::insert_before(rule.into(), p, i, A::nuw);
}

if !last.has_lakara(Lit) {
if !next.has_lakara(Lit) {
return None;
}

Expand Down
Loading

0 comments on commit 5d6cd17

Please sign in to comment.