Skip to content

Commit

Permalink
chore: Update vlazba version to 0.7.7; fix lujvo decomposition
Browse files Browse the repository at this point in the history
  • Loading branch information
lagleki committed Feb 23, 2025
1 parent 3cd8168 commit cd74a30
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vlazba"
version = "0.7.6"
version = "0.7.7"
edition = "2021"
authors = ["lagleki <[email protected]>"]
description = "Lojban words generator and analyzer"
Expand Down
5 changes: 2 additions & 3 deletions src/gismu_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl GismuGenerator {
.zip(shape.chars().skip(1))
.enumerate()
.filter_map(|(i, (c1, c2))| {
if c1.to_ascii_lowercase() == 'c' && c2.to_ascii_lowercase() == 'c' {
if c1.eq_ignore_ascii_case(&'c') && c2.eq_ignore_ascii_case(&'c') {
let mut p: Vec<Predicate> = vec![Box::new(self.validator_for_cc(i))];
if shape.chars().nth(i + 2) == Some('c') {
p.push(Box::new(self.validator_for_ccc(i)));
Expand Down Expand Up @@ -275,8 +275,7 @@ impl<'a> GismuMatcher<'a> {
fn match_structural_pattern(&self, letter: &str, c: char) -> bool {
SIMILARITIES
.iter()
.find(|&&(key, _)| key == c.to_ascii_lowercase())
.map_or(false, |&(_, pattern)| {
.find(|&&(key, _)| key == c.to_ascii_lowercase()).is_some_and(|&(_, pattern)| {
pattern.contains(letter) || pattern.is_empty()
})
}
Expand Down
29 changes: 29 additions & 0 deletions src/jvozba/jvokaha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,32 @@ fn jvokaha2(lujvo: &str) -> Result<Vec<String>, Box<dyn Error>> {
Ok(res)
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_valid_lujvo_bramlatu() {
assert_eq!(
jvokaha("bramlatu").unwrap(),
vec!["bra", "mlatu"]
);
}

#[test]
fn test_valid_lujvo_toirbroda() {
assert_eq!(
jvokaha("toirbroda").unwrap(),
vec!["toi", "r", "broda"]
);
}

#[test]
fn test_valid_lujvo_ca_irgau() {
assert_eq!(
jvokaha("ca'irgau").unwrap(),
vec!["ca'i", "r", "gau"]
);
}
}

22 changes: 13 additions & 9 deletions src/jvozba/jvozbanarge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn is_forbidden(d: &LujvoAndScore, forbid_la_lai_doi: bool) -> bool {

#[inline]
fn is_cmevla(valsi: &str) -> bool {
valsi.chars().last().map_or(false, |c| !"aeiouy'".contains(c))
valsi.chars().last().is_some_and(|c| !"aeiouy'".contains(c))
}

pub fn normalize(rafsi_list: &[String]) -> Vec<String> {
Expand All @@ -91,18 +91,22 @@ pub fn normalize(rafsi_list: &[String]) -> Vec<String> {
let end = rafsi.chars().last().unwrap();
let init = result[0].chars().next().unwrap();

if is_4letter(rafsi)
|| (is_c(end) && is_c(init) && is_permissible(end, init) == 0)
|| (end == 'n' && ["ts", "tc", "dz", "dj"].iter().any(|&s| result[0].starts_with(s)))
|| (i == rafsi_list.len() - 2 && is_cvv(rafsi) && should_add_hyphen(rafsi_list, &result))
|| (i == rafsi_list.len() - 2 && is_cvc(rafsi) && is_tosmabru(rafsi, &result))
{
if is_4letter(rafsi) {
result.insert(0, "y".to_string());
} else if is_c(end) && is_c(init) && is_permissible(end, init) == 0 {
result.insert(0, "y".to_string());
} else if end == 'n' && ["ts", "tc", "dz", "dj"].iter().any(|&s| result[0].starts_with(s)) {
result.insert(0, "y".to_string());
}

if i == rafsi_list.len() - 2 && is_cvv(rafsi) && should_add_hyphen(rafsi_list, &result) {
// Handle CVV case for first rafsi separately
if i == rafsi_list.len() - 2 && is_cvv(rafsi) {
let hyphen = if result[0].starts_with('r') { "n" } else { "r" };
result.insert(0, hyphen.to_string());
if rafsi_list.len() > 2 || !is_ccv(&result[0]) {
result.insert(0, hyphen.to_string());
}
} else if i == rafsi_list.len() - 2 && is_cvc(rafsi) && is_tosmabru(rafsi, &result) {
result.insert(0, "y".to_string());
}

result.insert(0, rafsi.clone());
Expand Down

0 comments on commit cd74a30

Please sign in to comment.