Skip to content

Commit

Permalink
[prakriya] Refactor dhatu logic
Browse files Browse the repository at this point in the history
Our previous rule ordering made certain derivations impossible. This
commit standardizes our rule order as follows:

1. We create a complete sanadi dhatu before adding any other pratyayas.
2. Generally, we apply guna before applying dvitva.

Along the way, we found and corrected a variety of small errors and
substantially increased our rule coverage and unit test coverage:

Rules:      ~1094 --> ~1196
Unit tests:   755 -->   973
  • Loading branch information
akprasad committed Sep 17, 2023
1 parent 90b8758 commit 6ebc5bf
Show file tree
Hide file tree
Showing 83 changed files with 6,754 additions and 1,749 deletions.
1 change: 1 addition & 0 deletions vidyut-prakriya/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
www/static/*
16 changes: 8 additions & 8 deletions vidyut-prakriya/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,28 @@ test_tinantas:
cargo build --release
../target/release/test_tinantas \
--test-cases test-files/tinantas-basic-kartari.csv \
--hash "72f94a7fa706cb5b2c96b0f74baa17f1a0c263d96cb92edc669f244dfabafcb2"
--hash "ab8ff253c90d44461bd71c9681d748141d77685758282ea04484966fb1014bfa"
../target/release/test_tinantas \
--test-cases test-files/tinantas-nic-kartari.csv \
--hash "c16ff79b6041e25a3297a614611515537020712341febb340e30ace459a8104b"
--test-cases test-files/tinantas-nic-kartari.csv \
--hash "f8a3b4c50eb88eda52db0a6936ff694168d1a80408a015d71561ab88b0e43269"
../target/release/test_tinantas \
--test-cases test-files/tinantas-san-kartari.csv \
--hash "ba174c9268b8be00262dd1f856161b2cb505b515c4e232feb70cb711eb6ce652"
--hash "04bfbbd22493ae53c7d15c753131242d3923c4d4d5e1aee847665cb87bb2d9f1"
../target/release/test_tinantas \
--test-cases test-files/tinantas-yan-kartari.csv \
--hash "1645ee474a8e370b6cd1a5d487092f2cc84864afd706e2a1ddabea6a8e4c49e3"
--hash "2679e81f6a1e3a2957df5a4fdd6b8bd9666d42d1fb79ab5122ad02bd3e8dd7f2"
../target/release/test_tinantas \
--test-cases test-files/tinantas-basic-karmani.csv \
--hash "a2bbcd572c04973eee057d58a0caf93ea84fb8eb18845633ce4ef271a0abdffd"
--hash "cfb9bf65e38289abc3119f839e41615ecd2bb7f548a8ef78a45cd3d24c183d59"

test_krdantas:
cargo build --release
../target/release/test_krdantas \
--test-cases test-files/krdantas-ktvA.csv \
--hash "8b7e855313d13de73b34c55e1c41daad262575365d2a5748c2469de09a3df15a"
--hash "e8be9f718fa56dd602be71166d1bcfd24da054e77dd2cd628dedda1b004bc4f8"
../target/release/test_krdantas \
--test-cases test-files/krdantas-kta.csv \
--hash "b13cefedbb913354a12b47ff6ae4187c335e2ebe73066b601ac7eeb32c10ea2a"
--hash "223db03e3c5bd4492919cf8fd27d09fd23c0660449df6596bcf6c6dbe9c45caa"

test_subantas:
cargo run --bin test_subantas -- \
Expand Down
2 changes: 1 addition & 1 deletion vidyut-prakriya/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ can take in the comments on the `Rule` type. We suggest using `ashtadhyayi.com`
to learn more about these rules.

The right column shows the in-progress prakriya. We use an output convention
that is common on other Ashtadhyayi websites. The encoding foromat for this
that is common on other Ashtadhyayi websites. The encoding format for this
text is SLP1, which is the encoding format we use throughout the crate.

[sv]: https://github.com/drdhaval2785/SanskritVerb
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 @@ -1636,7 +1636,7 @@ code dhatu artha
06.0165 mila~^ saNgame
06.0166 mu\cx~^ mokzaRe
06.0167 lu\px~^ Cedane
06.0168 vidx~^ lABe
06.0168 vi\dx~^ lABe
06.0169 li\pa~^ upadehe
06.0170 zi\ca~^ kzaraRe
06.0171 kftI~ Cedane
Expand Down
52 changes: 48 additions & 4 deletions vidyut-prakriya/src/ac_sandhi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ lazy_static! {
static ref EC: Set = s("ec");
static ref VAL: Set = s("val");
static ref HAL: Set = s("hal");
static ref YAN: Set = s("yaR");
}

pub fn try_lopo_vyor_vali(p: &mut Prakriya) {
Expand All @@ -37,9 +38,11 @@ pub fn try_lopo_vyor_vali(p: &mut Prakriya) {
let t = get_at(p, i).expect("should be present");
// Ignore if it starts an upadesha, otherwise roots like "vraj" would by vyartha.
// Likewise for roots ending with 'v'.
// Likewise for pratipadikas.
//
// For now, just check if the term is a dhatu.
let is_upadesha_adi = t.is_dhatu() && (t.has_adi('v') || t.has_adi('y'));
vyor_vali && !is_upadesha_adi
vyor_vali && !is_upadesha_adi && !t.is_pratipadika()
},
|p, _, i| {
set_at(p, i, "");
Expand Down Expand Up @@ -92,10 +95,21 @@ pub fn apply_general_ac_sandhi(p: &mut Prakriya) {
},
);

// HACK: ignore sandhi between upasarga and dhatu so that we can correctly derive prARinat,
// etc.
fn is_upasarga_sanadi_dhatu(p: &Prakriya, i: usize) -> bool {
get_at(p, i).expect("present").is_upasarga()
&& p.terms().last().expect("present").is_dhatu()
}

char_rule(
p,
xy(|x, y| AK.contains(x) && AK.contains(y) && al::savarna(x).contains(y)),
|p, text, i| {
if is_upasarga_sanadi_dhatu(p, i) {
return false;
}

let x = text.as_bytes()[i] as char;
set_at(p, i, &al::to_dirgha(x).expect("should be ac").to_string());
set_at(p, i + 1, "");
Expand Down Expand Up @@ -165,14 +179,19 @@ pub fn apply_general_ac_sandhi(p: &mut Prakriya) {
p,
xy(|x, y| A.contains(x) && AC.contains(y)),
|p, text, i| {
if is_upasarga_sanadi_dhatu(p, i) {
return false;
}

let j = i + 1;
let y = text.as_bytes()[i + 1] as char;

if EC.contains(y) {
set_at(p, j, al::to_vrddhi(y).expect("should be set"));
set_at(p, j, al::to_vrddhi(y).expect("should have vrddhi"));
set_at(p, i, "");
p.step("6.1.88");
} else {
set_at(p, j, al::to_guna(y).expect("should be set"));
set_at(p, j, al::to_guna(y).expect("should have guna"));
set_at(p, i, "");
p.step("6.1.87");
}
Expand Down Expand Up @@ -361,7 +380,30 @@ fn hacky_apply_ni_asiddhavat_rules(p: &mut Prakriya) -> Option<()> {
Some(())
}

pub fn run_common(p: &mut Prakriya) {
/// Runs antaranga ac-sandhi rules.
///
/// (Example: div -> dyU + sa -> dudyUzati)
pub fn run_antaranga(p: &mut Prakriya) -> Option<()> {
for i in 0..p.terms().len() {
let cur = p.get(i)?;
if cur.has_upadha(&*IK) && cur.has_antya(&*AC) {
let x = cur.upadha()?;
let res = match x {
'i' | 'I' => "y",
'u' | 'U' => "v",
'f' | 'F' => "r",
'x' | 'X' => "l",
_ => panic!("Unexpected res"),
};
p.op_term("6.1.77", i, |t| t.set_upadha(res));
}
}

p.maybe_save_sthanivat();
Some(())
}

pub fn run_common(p: &mut Prakriya) -> Option<()> {
try_ver_aprktasya(p);

for i in 0..p.terms().len() {
Expand All @@ -372,4 +414,6 @@ pub fn run_common(p: &mut Prakriya) {
hacky_apply_ni_asiddhavat_rules(p);

try_sut_kat_purva(p);

Some(())
}
Loading

0 comments on commit 6ebc5bf

Please sign in to comment.