[lang][library] Languages: liber-lang (words with UTF-16 offsets, lemmatizer trait with tables and hand-written rules, coverage, warm-up, levels, Ludus concept ids, Gale-Church alignment with anchors); known words, the known band, familiar books and editions as events

This commit is contained in:
2026-11-17 19:33:45 +01:00
parent 4e68eec3c4
commit 7dca9de95c
25 changed files with 2272 additions and 8 deletions
+25
View File
@@ -0,0 +1,25 @@
//! Ludus concept ids for vocabulary: `w-<lang>-<16 base32 chars of sha256(lemma)>` (lowercase ASCII, Ludus rule).
use crate::{Lang, fold};
use sha2::{Digest, Sha256};
const ALPHABET: &[u8; 32] = b"abcdefghijklmnopqrstuvwxyz234567";
/// The concept id of a lemma. The lemma is folded first (lowercase, NFC; Latin `j`/`v` → `i`/`u`), so every form of
/// one lemma shares one concept.
pub fn concept_id(lang: Lang, lemma: &str) -> String {
let digest = Sha256::digest(fold(lemma, lang).as_bytes());
// 16 base32 characters are exactly 80 bits: the first 10 bytes.
let mut bits: u128 = 0;
for &b in &digest[..10] {
bits = (bits << 8) | u128::from(b);
}
let mut out = String::with_capacity(21);
out.push_str("w-");
out.push_str(lang.code());
out.push('-');
for i in (0..16).rev() {
out.push(ALPHABET[((bits >> (i * 5)) & 31) as usize] as char);
}
out
}