mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-29 09:46:29 +01:00
Merge pull request #2871 from ruchirguitar/feat/add-gujarati-proof
Proofing: add Gujarati (gu_IN) spelling, suggestion dispatch and grammar checks
This commit is contained in:
11 files changed
+494
-7
No files matched your search
@@ -0,0 +1,118 @@
|
||||
//! Generic repeated-word and spacing checks with Gujarati messages.
|
||||
//! No Gujarati-specific grammar or case rules are inferred.
|
||||
|
||||
use crate::{Issue, IssueKind, ProofLang, words};
|
||||
|
||||
fn issue(start: usize, end: usize, message: String, suggestions: Vec<String>) -> Issue {
|
||||
Issue { start, end, kind: IssueKind::Grammar, message, suggestions, lang: ProofLang::Gu }
|
||||
}
|
||||
|
||||
/// Checks `text` for repeated words and spacing problems, with Gujarati messages.
|
||||
pub fn check(text: &str) -> Vec<Issue> {
|
||||
let mut issues = Vec::new();
|
||||
repeated_words(text, &words(text), &mut issues);
|
||||
spaces(text, &mut issues);
|
||||
issues.sort_by_key(|i| (i.start, i.end));
|
||||
issues
|
||||
}
|
||||
|
||||
/// Words Gujarati repeats on purpose (`હા હા`, `ના ના`, `ધીમે ધીમે`, `સાચે સાચે`).
|
||||
const ALLOWED_REPEATS: &[&str] = &["હા", "ના", "ધીમે", "જલ્દી", "વારંવાર", "સાચે", "રોજે", "ખરેખર", "જરા", "થોડું", "સાથે", "પાસે"];
|
||||
|
||||
fn is_digit(c: char) -> bool {
|
||||
c.is_ascii_digit() || ('\u{0AE6}'..='\u{0AEF}').contains(&c)
|
||||
}
|
||||
|
||||
fn repeated_words(text: &str, ws: &[(usize, usize)], v: &mut Vec<Issue>) {
|
||||
for pair in ws.windows(2) {
|
||||
let [(a0, b0), (a1, b1)] = pair else { continue };
|
||||
let (Some(w0), Some(w1), Some(gap)) = (text.get(*a0..*b0), text.get(*a1..*b1), text.get(*b0..*a1)) else { continue };
|
||||
if !gap.is_empty()
|
||||
&& gap.chars().all(char::is_whitespace)
|
||||
&& w0.chars().all(|c| c.is_alphabetic() || (super::is_gujarati_char(c) && !c.is_numeric()))
|
||||
&& w0 == w1
|
||||
&& !ALLOWED_REPEATS.contains(&w0)
|
||||
{
|
||||
v.push(issue(*a0, *b1, format!("પુનરાવર્તિત શબ્દ: “{w1}”"), vec![w0.to_string()]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn spaces(text: &str, v: &mut Vec<Issue>) {
|
||||
for (i, c) in text.char_indices() {
|
||||
if c != ' ' {
|
||||
continue;
|
||||
}
|
||||
let rest = text.get(i + 1..).unwrap_or("");
|
||||
let mut it = rest.chars();
|
||||
let Some(p) = it.next() else { continue };
|
||||
let after = it.next();
|
||||
// A ratio/score keeps the spaces in digit-space-colon-space-digit (ASCII or Gujarati digits).
|
||||
let ratio = p == ':'
|
||||
&& text.get(..i).and_then(|before| before.chars().next_back()).is_some_and(is_digit)
|
||||
&& after == Some(' ')
|
||||
&& it.next().is_some_and(is_digit);
|
||||
let flag = !ratio
|
||||
&& match p {
|
||||
',' => true,
|
||||
';' => !matches!(after, Some(')' | '(' | '-' | 'P' | 'D')),
|
||||
'.' => !matches!(after, Some('.')) && !after.is_some_and(|a| a.is_ascii_digit()),
|
||||
':' | '!' | '?' => after.is_none_or(|a| a.is_whitespace() || matches!(a, '"' | '”' | '’' | '!' | '?')),
|
||||
_ => false,
|
||||
};
|
||||
if flag {
|
||||
v.push(issue(i, i + 1 + p.len_utf8(), "વિરામચિહ્ન પહેલાં જગ્યા".into(), vec![p.to_string()]));
|
||||
}
|
||||
}
|
||||
for run in crate::space_runs(text) {
|
||||
v.push(issue(run.start, run.end, "બેવડી જગ્યા".into(), vec![" ".into()]));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn intentional_repeats_are_fine() {
|
||||
for text in ["હા હા, હું આવીશ.", "ના ના, આ નથી.", "ધીમે ધીમે ચાલ.", "સાચે સાચે બોલ."]
|
||||
{
|
||||
assert!(check(text).is_empty(), "{text}: {:?}", check(text));
|
||||
}
|
||||
assert_eq!(check("પુસ્તક પુસ્તક છે.").len(), 1);
|
||||
assert!(check("1 1").is_empty());
|
||||
assert!(check("૧ ૧").is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repeated_words_and_spaces_have_gujarati_messages() {
|
||||
let text = "ઘર ઘર , શાળા.";
|
||||
let issues = check(text);
|
||||
assert_eq!(issues.len(), 3, "{issues:?}");
|
||||
assert_eq!(issues[0].message, "પુનરાવર્તિત શબ્દ: “ઘર”");
|
||||
assert_eq!(issues[0].suggestions, ["ઘર"]);
|
||||
assert!(issues.iter().any(|i| i.message == "વિરામચિહ્ન પહેલાં જગ્યા" && &text[i.start..i.end] == " ,"));
|
||||
assert!(issues.iter().any(|i| i.message == "બેવડી જગ્યા"));
|
||||
assert!(issues.iter().all(|i| i.lang == ProofLang::Gu && i.kind == IssueKind::Grammar));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ratios_and_scores_keep_their_spaces() {
|
||||
for text in ["3 : 1", "1 : 2", "સ્કોર 12 : 10.", "૩ : ૧", "૧ : ૨", "સ્કોર ૧૨ : ૧૦."] {
|
||||
assert!(check(text).is_empty(), "{text}: {:?}", check(text));
|
||||
}
|
||||
for text in ["શબ્દ : બીજો", "3 : શબ્દ", "3 :", "૩ : શબ્દ", "૩ :"] {
|
||||
assert!(check(text).iter().any(|i| i.message == "વિરામચિહ્ન પહેલાં જગ્યા"), "{text}");
|
||||
}
|
||||
}
|
||||
|
||||
proptest::proptest! {
|
||||
#[test]
|
||||
fn never_panics_and_ranges_are_valid(s in "\\PC{0,80}") {
|
||||
for issue in check(&s) {
|
||||
proptest::prop_assert!(issue.start <= issue.end && issue.end <= s.len());
|
||||
proptest::prop_assert!(s.is_char_boundary(issue.start) && s.is_char_boundary(issue.end));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
//! Gujarati proofing using the installed Hunspell `gu_IN` dictionary (never bundled).
|
||||
//! Suggestions use its runtime MAP/REP/TRY/KEY tables. Generic grammar checks have Gujarati
|
||||
//! messages; hyphenation keeps the existing fallback.
|
||||
|
||||
pub mod grammar;
|
||||
pub(crate) mod suggest;
|
||||
#[cfg(test)]
|
||||
pub(crate) mod test_dict;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::affix::AffixDict;
|
||||
use crate::slot::DictSlot;
|
||||
|
||||
pub use suggest::suggest;
|
||||
|
||||
/// File names of a Gujarati Hunspell dictionary.
|
||||
const NAMES: &[&str] = &["gu_IN", "gu-IN", "gu"];
|
||||
|
||||
/// The Gujarati dictionary, found on first use (see [`DictSlot`]).
|
||||
pub(crate) static DICT: DictSlot<AffixDict> = DictSlot::new(NAMES, "Gujarati");
|
||||
|
||||
/// The Gujarati dictionary: the installed Hunspell `gu_IN` (read on first use), one given with
|
||||
/// [`install_dictionary`], or an empty one when none is available (Gujarati spelling is off
|
||||
/// then; see [`has_dictionary`]).
|
||||
pub fn dictionary() -> Arc<AffixDict> {
|
||||
DICT.get()
|
||||
}
|
||||
|
||||
/// Use this Gujarati dictionary from now on (Hunspell `.aff` and `.dic` text, decoded to
|
||||
/// UTF-8), for example one the user picked. On error the current dictionary stays.
|
||||
pub fn install_dictionary(aff: &str, dic: &str) -> Result<(), String> {
|
||||
DICT.install(aff, dic)
|
||||
}
|
||||
|
||||
/// Is a Gujarati dictionary available (spelling is checked)?
|
||||
pub fn has_dictionary() -> bool {
|
||||
DICT.has_dictionary()
|
||||
}
|
||||
|
||||
/// Returns `true` when `c` is in the Gujarati Unicode block (U+0A80..=U+0AFF).
|
||||
pub fn is_gujarati_char(c: char) -> bool {
|
||||
('\u{0A80}'..='\u{0AFF}').contains(&c)
|
||||
}
|
||||
|
||||
/// Is `word` spelled correctly in Gujarati? Numbers, single letters, short words with digits and words in other scripts are accepted, and so
|
||||
/// is every word when no Gujarati dictionary is installed.
|
||||
pub fn is_correct(word: &str) -> bool {
|
||||
is_correct_with(&dictionary(), word)
|
||||
}
|
||||
|
||||
/// [`is_correct`] with the File › Options › Proofing choices: with Ignore words that contain numbers off, words with digits are checked.
|
||||
pub fn is_correct_with_options(word: &str, opts: &crate::Options) -> bool {
|
||||
check(&dictionary(), word, opts)
|
||||
}
|
||||
|
||||
/// [`is_correct`] against a given dictionary (an empty one accepts everything).
|
||||
pub fn is_correct_with(d: &AffixDict, word: &str) -> bool {
|
||||
check(d, word, &crate::Options::default())
|
||||
}
|
||||
|
||||
/// [`is_correct_with_options`] against a given dictionary.
|
||||
fn check(d: &AffixDict, word: &str, opts: &crate::Options) -> bool {
|
||||
if d.is_empty() {
|
||||
return true;
|
||||
}
|
||||
let w = word.trim_matches(|c: char| !c.is_alphanumeric() && !is_gujarati_char(c) && !matches!(c, '\'' | '’' | '-'));
|
||||
let w = w.trim_matches(['\'', '’', '-']);
|
||||
let letter_count = w.chars().filter(|&c| (is_gujarati_char(c) && !c.is_numeric()) || c.is_alphabetic()).count();
|
||||
if letter_count <= 1 || (opts.ignore_numbers && w.chars().any(char::is_numeric)) {
|
||||
return true;
|
||||
}
|
||||
// A word in another script (or with no Gujarati characters) is not marked by this dictionary.
|
||||
if !w.chars().any(is_gujarati_char) {
|
||||
return true;
|
||||
}
|
||||
if w.contains('-') {
|
||||
// The whole word first, as Hunspell does: a hyphenated entry or user word.
|
||||
return known(d, w) || w.split('-').all(|p| p.chars().count() <= 1 || !p.chars().any(is_gujarati_char) || known(d, p));
|
||||
}
|
||||
known(d, w)
|
||||
}
|
||||
|
||||
/// Is one word (no hyphens) in the dictionary or the user dictionary?
|
||||
fn known(d: &AffixDict, w: &str) -> bool {
|
||||
d.check(w) || crate::in_user_dictionary(&w.to_lowercase())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn dictionary_lookup_accepts_gujarati_file_names() {
|
||||
let dir = std::env::temp_dir().join(format!("wordcraft-gu-aliases-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
for name in ["gu_IN", "gu-IN", "gu"] {
|
||||
std::fs::write(dir.join(format!("{name}.aff")), test_dict::AFF).unwrap();
|
||||
std::fs::write(dir.join(format!("{name}.dic")), test_dict::DIC).unwrap();
|
||||
let (aff, dic) = crate::hunspell::find_in(&dir, NAMES).unwrap();
|
||||
let d = crate::hunspell::load(&aff, &dic).unwrap();
|
||||
assert!(is_correct_with(&d, "ઘરો"));
|
||||
std::fs::remove_file(aff).unwrap();
|
||||
std::fs::remove_file(dic).unwrap();
|
||||
}
|
||||
std::fs::remove_dir(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gujarati_words_affixes_and_case_markers() {
|
||||
test_dict::install();
|
||||
let d = dictionary();
|
||||
assert!(has_dictionary());
|
||||
assert_eq!(d.len(), 15);
|
||||
for w in [
|
||||
"ઘર",
|
||||
"ઘરો",
|
||||
"ઘરોને",
|
||||
"ઘરોમાં",
|
||||
"પુસ્તક",
|
||||
"પુસ્તકો",
|
||||
"પુસ્તકોમાં",
|
||||
"પાણી",
|
||||
"શાળા",
|
||||
"ભાષા",
|
||||
"પરીક્ષણ",
|
||||
"પ્રેમ",
|
||||
"શહેર",
|
||||
"ગામ",
|
||||
"મિત્ર",
|
||||
"અઘર",
|
||||
"શાળા-શહેર",
|
||||
] {
|
||||
assert!(is_correct(w), "{w}");
|
||||
}
|
||||
for w in ["ઘરર", "પુસ્તકક", "પાણીઈ", "શાળળા", "zqપ્રતિબંધિત"] {
|
||||
assert!(!is_correct(w), "{w}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn forbidden_words_are_rejected() {
|
||||
test_dict::install();
|
||||
assert!(!is_correct("zqપ્રતિબંધિત"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_dictionary_and_ignored_inputs_are_quiet() {
|
||||
let empty = AffixDict::default();
|
||||
assert!(is_correct_with(&empty, "શાળા"));
|
||||
assert!(install_dictionary("FLAG bogus\n", "1\nઘર\n").is_err());
|
||||
let d = AffixDict::from_hunspell(test_dict::AFF, test_dict::DIC, &[]).unwrap();
|
||||
for w in ["", "2026", "૧૨", "૨૦૨૬", "અ", "English", "日本語"] {
|
||||
assert!(is_correct_with(&d, w), "{w}");
|
||||
}
|
||||
let no_ignore = crate::Options { ignore_numbers: false, ..Default::default() };
|
||||
assert!(check(&d, "૧૨", &no_ignore));
|
||||
assert!(check(&d, "2026", &no_ignore));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn user_dictionary_applies() {
|
||||
test_dict::install();
|
||||
assert!(!is_correct("નવોશબ્દગુજરાતી"));
|
||||
crate::add_word("નવોશબ્દગુજરાતી");
|
||||
assert!(is_correct("નવોશબ્દગુજરાતી"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gujarati_dispatch_messages_options_and_mixed_spans() {
|
||||
crate::hold_dictionary_tests();
|
||||
test_dict::install();
|
||||
assert!(crate::has_dictionary(Some("gu-IN")));
|
||||
assert!(crate::is_correct_for("ઘરો", Some("guj")));
|
||||
let text = "ઘર પુસ્તકક";
|
||||
let issues = crate::check_text(text, &[(0..text.len(), crate::ProofLang::Gu)]);
|
||||
assert_eq!(issues.len(), 1, "{issues:?}");
|
||||
assert_eq!(&text[issues[0].start..issues[0].end], "પુસ્તકક");
|
||||
assert_eq!(issues[0].message, "શક્ય જોડણી ભૂલ");
|
||||
assert_eq!(issues[0].lang, crate::ProofLang::Gu);
|
||||
let text = "ઘર this is is wrong";
|
||||
let issues = crate::check_text(text, &[(0..3, crate::ProofLang::Gu), (4..text.len(), crate::ProofLang::En)]);
|
||||
assert!(issues.iter().any(|i| i.lang == crate::ProofLang::En && i.message.starts_with("Repeated word")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
//! Gujarati suggestions: the shared ranking ([`crate::affix_suggest`]) with the installed
|
||||
//! dictionary's own MAP/REP/TRY/KEY tables and nothing Gujarati hard-coded.
|
||||
|
||||
use crate::affix::AffixDict;
|
||||
use crate::affix_suggest::Tuning;
|
||||
|
||||
/// Spelling suggestions for a Gujarati word, best first, at most `max`.
|
||||
pub fn suggest(word: &str, max: usize) -> Vec<String> {
|
||||
suggest_in(&super::dictionary(), word, max)
|
||||
}
|
||||
|
||||
/// [`suggest`] against a given dictionary.
|
||||
pub fn suggest_in(d: &AffixDict, word: &str, max: usize) -> Vec<String> {
|
||||
crate::affix_suggest::suggest_in(d, word, max, &Tuning::DEFAULT)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn suggestion_results_stay_bounded_on_complex_inputs() {
|
||||
crate::gu::test_dict::install();
|
||||
for word in ["zqખૂબલાંબોશબ્દગુજરાતી", "પુસતક", "પરીક્ષણણ"] {
|
||||
let res = suggest(word, 6);
|
||||
assert!(res.len() <= 6, "{word}: got {} suggestions", res.len());
|
||||
assert!(!res.contains(&"zqપ્રતિબંધિત".to_string()));
|
||||
for s in &res {
|
||||
assert!(!s.is_empty());
|
||||
assert!(super::super::is_correct(s), "suggested word {s} should be valid");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A NOSUGGEST stem stays correct spelling, but the Gujarati collector never offers it or any
|
||||
/// prefixed, suffixed, REP-reached or recased form of it; ordinary stems are still offered.
|
||||
#[test]
|
||||
fn nosuggest_stems_and_forms_are_never_offered() {
|
||||
let aff = "SET UTF-8\nNOSUGGEST N\nFORBIDDENWORD F\nTRY abeklmnostxy\nMAP 1\nMAP ae\nKEY ak\nREP 2\nREP xy toka\nREP zz normal\nPFX X Y 1\nPFX X 0 pre .\nSFX A Y 1\nSFX A 0 ble/B .\nSFX B Y 1\nSFX B 0 s .\n";
|
||||
let d = AffixDict::from_hunspell(aff, "4\ntoka/NXA\nnormal/XA\nTkname/N\nbanned/F\n", &[]).unwrap();
|
||||
for word in d.forms("toka").into_iter().chain(["TOKA".into(), "Toka".into(), "Tkname".into(), "TKNAME".into()]) {
|
||||
assert!(d.check(&word), "NOSUGGEST is still correct: {word}");
|
||||
assert!(!d.can_suggest(&word), "NOSUGGEST form: {word}");
|
||||
}
|
||||
for input in ["tokax", "tokablesx", "pretokax", "pretokablesx", "toka", "TOKA", "tkname", "teka", "xy", "normaltoka", "toak", "taak"] {
|
||||
let got = suggest_in(&d, input, 32);
|
||||
assert!(got.iter().all(|w| w.split(' ').all(|part| d.can_suggest(part))), "{input}: {got:?}");
|
||||
assert!(got.iter().all(|w| !w.to_lowercase().contains("toka") && w.to_lowercase() != "tkname"), "{input}: {got:?}");
|
||||
}
|
||||
assert!(suggest_in(&d, "norrmal", 8).contains(&"normal".into()));
|
||||
assert!(suggest_in(&d, "zz", 8).contains(&"normal".into()));
|
||||
// Filtering happens before display casing: an ordinary mixed-case stem keeps its all-caps
|
||||
// suggestion, with and without a NOSUGGEST declaration.
|
||||
for aff in ["", "NOSUGGEST N\n"] {
|
||||
let ordinary = AffixDict::from_hunspell(aff, "2\nmixCase\nhidden/N\n", &[]).unwrap();
|
||||
assert!(suggest_in(&ordinary, "MIXCASX", 8).contains(&"MIXCASE".into()));
|
||||
}
|
||||
|
||||
// The same contract in Gujarati script, with Gujarati affixes and REP pairs.
|
||||
let aff = "SET UTF-8\nNOSUGGEST N\nTRY ગુપ્તસામાન્યઅોં\nREP 2\nREP ગુપત ગુપ્ત\nREP સામાનય સામાન્ય\nPFX X Y 1\nPFX X 0 અ .\nSFX A Y 1\nSFX A 0 ો/B .\nSFX B Y 1\nSFX B 0 માં .\n";
|
||||
let d = AffixDict::from_hunspell(aff, "2\nગુપ્ત/NXA\nસામાન્ય/XA\n", &[]).unwrap();
|
||||
let hidden = d.forms("ગુપ્ત");
|
||||
assert!(hidden.contains(&"અગુપ્તો".into()) && hidden.contains(&"ગુપ્તોમાં".into()), "{hidden:?}");
|
||||
for word in hidden.iter().chain(&["અગુપ્તોમાં".to_string()]) {
|
||||
assert!(d.check(word), "NOSUGGEST is still correct: {word}");
|
||||
assert!(!d.can_suggest(word), "NOSUGGEST form: {word}");
|
||||
}
|
||||
for input in ["ગુપત", "અગુપત", "ગુપતો", "અગુપતોમાં", "ગુપ્તત", "અગુપ્તોમા"]
|
||||
{
|
||||
let got = suggest_in(&d, input, 32);
|
||||
assert!(got.iter().all(|w| w.split(' ').all(|part| d.can_suggest(part))), "{input}: {got:?}");
|
||||
assert!(got.iter().all(|w| !w.contains("ગુપ્ત")), "{input}: {got:?}");
|
||||
}
|
||||
assert!(suggest_in(&d, "સામાનય", 8).contains(&"સામાન્ય".into()));
|
||||
assert!(suggest_in(&d, "અસામાનયો", 8).contains(&"અસામાન્યો".into()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gujarati_suggestions_use_runtime_tables() {
|
||||
crate::gu::test_dict::install();
|
||||
for (word, want) in [("શાલા", "શાળા"), ("પાની", "પાણી"), ("પ્રેમમ", "પ્રેમ"), ("પરીકશણ", "પરીક્ષણ")]
|
||||
{
|
||||
let s = suggest(word, 8);
|
||||
assert!(s.contains(&want.into()), "{word}: {s:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn suggestions_stay_bounded_and_skip_forbidden_words() {
|
||||
crate::gu::test_dict::install();
|
||||
for w in ["", "બે શબ્દો", &"શ".repeat(41)] {
|
||||
assert!(suggest(w, 4).is_empty());
|
||||
}
|
||||
assert!(suggest("ઘર", 0).is_empty());
|
||||
assert!(suggest_in(&AffixDict::default(), "ઘર", 4).is_empty());
|
||||
assert!(suggest("ઘર", 4).len() <= 4);
|
||||
assert!(!suggest("ઘર", 4).contains(&"ઘર".into()));
|
||||
assert!(!suggest("zqપ્રતિબંધિત", 8).contains(&"zqપ્રતિબંધિત".into()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//! Hand-written synthetic Gujarati test data. No words, rules or suggestion tables were copied
|
||||
//! from a system dictionary. This is a small fixture, not a redistributable Gujarati dictionary.
|
||||
|
||||
pub const AFF: &str = "SET UTF-8
|
||||
FLAG UTF-8
|
||||
FORBIDDENWORD F
|
||||
TRY અઆઇઈઉઊઋએઐઓઔકખગઘઙચછજઝઞટઠડઢણતથદધનપફબભમયરલવશષસહળક્ષજ્ઞાિીુૂૃૄેૈોૌ્ંઃઁ
|
||||
KEY ષસ|તર
|
||||
MAP 4
|
||||
MAP ઇઈિી
|
||||
MAP ઉઊુૂ
|
||||
MAP સશષ
|
||||
MAP ણન
|
||||
REP 1
|
||||
REP કશ ક્ષ
|
||||
SFX N Y 4
|
||||
SFX N 0 ો/C .
|
||||
SFX N 0 ો .
|
||||
SFX N 0 ઓ/C .
|
||||
SFX N 0 ઓ .
|
||||
SFX C Y 4
|
||||
SFX C 0 ને .
|
||||
SFX C 0 માં .
|
||||
SFX C 0 થી .
|
||||
SFX C 0 નો .
|
||||
PFX X Y 1
|
||||
PFX X 0 અ .
|
||||
";
|
||||
|
||||
pub const DIC: &str = "15
|
||||
ઘર/NX
|
||||
પુસ્તક/NX
|
||||
પાણી
|
||||
શાળા
|
||||
ભાષા
|
||||
પરીક્ષણ
|
||||
પ્રેમ
|
||||
શહેર
|
||||
ગામ/NX
|
||||
મિત્ર/NX
|
||||
ઝાડ
|
||||
ફળ
|
||||
કમળ
|
||||
સૂર્ય
|
||||
zqપ્રતિબંધિત/F
|
||||
";
|
||||
|
||||
pub fn install() {
|
||||
crate::hold_dictionary_tests();
|
||||
super::install_dictionary(AFF, DIC).unwrap();
|
||||
}
|
||||
@@ -224,9 +224,9 @@ fn composed_chars(core: &[char]) -> (Vec<char>, Vec<Option<usize>>) {
|
||||
(nfc, starts)
|
||||
}
|
||||
|
||||
/// Does a pack's `pats` hyphenate `core` in `lang`? Russian, Bulgarian and Turkish: a word in
|
||||
/// their script (the guard their rules use) whose letters the patterns know, so a word with a
|
||||
/// letter the pack never mentions (`ё`) goes on to the built-in rules. Polish, Portuguese, Italian
|
||||
/// Does a pack's `pats` hyphenate `core` in `lang`? Russian, Bulgarian, Turkish and Gujarati: a
|
||||
/// word in their script (the guard their rules use) whose letters the patterns know, so a word with a
|
||||
/// letter the pack never mentions goes on to the fallback rules. Polish, Portuguese, Italian
|
||||
/// and German: every word, as their embedded patterns do. Any other language: a word whose letters
|
||||
/// the patterns know.
|
||||
fn pack_patterns_fit(lang: ProofLang, pats: &Patterns, core: &[char]) -> bool {
|
||||
@@ -235,6 +235,7 @@ fn pack_patterns_fit(lang: ProofLang, pats: &Patterns, core: &[char]) -> bool {
|
||||
ProofLang::Bg => core.iter().all(|&c| crate::bg::is_letter(c)) && pack_knows(pats, core),
|
||||
ProofLang::Tr => core.iter().all(|&c| crate::tr::hyphen::is_letter(c)) && pack_knows(pats, core),
|
||||
ProofLang::Pl | ProofLang::Pt | ProofLang::It | ProofLang::De => true,
|
||||
ProofLang::Gu => core.iter().all(|&c| crate::gu::is_gujarati_char(c)) && pack_knows(pats, core),
|
||||
_ => pats.values(core).is_some(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,3 +185,12 @@ fn polish_heuristic_for_foreign_letters() {
|
||||
let c: Vec<char> = "szczérze".chars().collect();
|
||||
assert_eq!(heuristic_points_pl(&c), vec![5], "szczé-rze: `rz` stays whole");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gujarati_pack_patterns_fit_checks_script_and_exceptions() {
|
||||
let pats = Patterns::parse("1ક 1ત પુ-સ્ત-ક");
|
||||
let gu_word: Vec<char> = "પુસ્તક".chars().collect();
|
||||
assert!(pack_patterns_fit(ProofLang::Gu, &pats, &gu_word));
|
||||
let en_word: Vec<char> = "hyphenation".chars().collect();
|
||||
assert!(!pack_patterns_fit(ProofLang::Gu, &pats, &en_word));
|
||||
}
|
||||
@@ -70,6 +70,10 @@ pub enum ProofLang {
|
||||
/// dictionary (else the neighbouring Rioplatense `es_AR`, a Latin American or a generic one),
|
||||
/// and the `vos` forms of verbs (`tenés`, `vení`, `decime`) accepted ([`crate::es::voseo`]).
|
||||
EsUy,
|
||||
/// Gujarati (`gu`, `gu-IN`, `guj`): the installed Hunspell dictionary (`gu_IN`, when there is
|
||||
/// one), dictionary-driven suggestions and generic checks with Gujarati messages. Hyphenation
|
||||
/// keeps the fallback patterns.
|
||||
Gu,
|
||||
/// German (`de`, `de-DE`, `de-AT`…; `de-CH` and `de-LI` are [`ProofLang::Pack`] `de-ch`, with
|
||||
/// their own dictionary and these patterns): hyphenation by the German patterns (reformed
|
||||
/// spelling), and spelling when a German Hunspell dictionary or `de` pack is found. No grammar
|
||||
@@ -90,7 +94,7 @@ pub enum ProofLang {
|
||||
|
||||
impl ProofLang {
|
||||
/// Every language with a spelling dictionary, in display order.
|
||||
pub const PROOFED: [ProofLang; 16] = [
|
||||
pub const PROOFED: [ProofLang; 17] = [
|
||||
ProofLang::En,
|
||||
ProofLang::EnGb,
|
||||
ProofLang::EnAu,
|
||||
@@ -107,6 +111,7 @@ impl ProofLang {
|
||||
ProofLang::EsMx,
|
||||
ProofLang::Es419,
|
||||
ProofLang::EsUy,
|
||||
ProofLang::Gu,
|
||||
];
|
||||
|
||||
/// The proofing language of a BCP 47 tag (`pl-PL`, `en_GB`, `PL`…). The primary subtag
|
||||
@@ -142,6 +147,8 @@ impl ProofLang {
|
||||
ProofLang::Cs
|
||||
} else if primary.eq_ignore_ascii_case("id") || primary.eq_ignore_ascii_case("ind") || primary.eq_ignore_ascii_case("in") {
|
||||
ProofLang::Id
|
||||
} else if primary.eq_ignore_ascii_case("gu") || primary.eq_ignore_ascii_case("guj") {
|
||||
ProofLang::Gu
|
||||
} else if primary.eq_ignore_ascii_case("es") || primary.eq_ignore_ascii_case("spa") {
|
||||
ProofLang::spanish(tag)
|
||||
} else if ["de", "deu", "ger"].iter().any(|c| primary.eq_ignore_ascii_case(c)) {
|
||||
@@ -225,6 +232,7 @@ impl ProofLang {
|
||||
ProofLang::Ru => "ru",
|
||||
ProofLang::Cs => "cs",
|
||||
ProofLang::Id => "id",
|
||||
ProofLang::Gu => "gu",
|
||||
ProofLang::Es | ProofLang::EsMx | ProofLang::Es419 | ProofLang::EsUy => "es",
|
||||
ProofLang::De => "de",
|
||||
ProofLang::Other => "",
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
//! The table of languages proofed against Hunspell dictionaries, and the dictionary-folder and load-error API.
|
||||
|
||||
use super::{
|
||||
DICTIONARY_GENERATION, EnglishSource, Issue, Options, Ordering, ProofLang, cs, english, es, hr, hunspell, id, it, pack_lang, pl, pt, ru, slot, tr,
|
||||
DICTIONARY_GENERATION, EnglishSource, Issue, Options, Ordering, ProofLang, cs, english, es, gu, hr, hunspell, id, it, pack_lang, pl, pt, ru,
|
||||
slot, tr,
|
||||
};
|
||||
|
||||
/// A language proofed against an installed Hunspell dictionary: all the functions below need to
|
||||
@@ -20,7 +21,7 @@ pub(super) struct Language {
|
||||
|
||||
/// Every language proofed against a Hunspell dictionary, in the order File › Options › Proofing
|
||||
/// lists them. English has a built-in word list and is handled apart.
|
||||
pub(super) static LANGUAGES: [Language; 12] = [
|
||||
pub(super) static LANGUAGES: [Language; 13] = [
|
||||
Language {
|
||||
lang: ProofLang::Pl,
|
||||
slot: &pl::DICT,
|
||||
@@ -87,6 +88,14 @@ pub(super) static LANGUAGES: [Language; 12] = [
|
||||
suggest: |w, n, _| id::suggest(w, n),
|
||||
grammar: |t, _, _| id::grammar::check(t),
|
||||
},
|
||||
Language {
|
||||
lang: ProofLang::Gu,
|
||||
slot: &gu::DICT,
|
||||
message: "શક્ય જોડણી ભૂલ",
|
||||
is_correct: |w, _, o| gu::is_correct_with_options(w, o),
|
||||
suggest: |w, n, _| gu::suggest(w, n),
|
||||
grammar: |t, _, _| gu::grammar::check(t),
|
||||
},
|
||||
Language {
|
||||
lang: ProofLang::Es,
|
||||
slot: &es::SPAIN_DICT,
|
||||
|
||||
@@ -35,6 +35,9 @@
|
||||
//! - **Indonesian** ([`ProofLang::Id`], module [`id`]): the installed Hunspell `id_ID`
|
||||
//! dictionary (not bundled), dictionary-driven suggestions and generic checks with Indonesian
|
||||
//! messages. Hyphenation uses the existing English fallback.
|
||||
//! - **Gujarati** ([`ProofLang::Gu`], module [`gu`]): the installed Hunspell `gu_IN`
|
||||
//! dictionary (not bundled), dictionary-driven suggestions and generic checks with Gujarati
|
||||
//! messages. Hyphenation uses the existing English fallback.
|
||||
//! - **Spanish** ([`ProofLang::Es`], [`ProofLang::EsMx`], [`ProofLang::Es419`], [`ProofLang::EsUy`],
|
||||
//! module [`es`]): each variety's installed Hunspell dictionary (`es_ES`, `es_MX`, `es_419`,
|
||||
//! `es_UY`, with fallbacks; not bundled), dictionary-driven suggestions, Uruguayan `vos` forms,
|
||||
@@ -79,6 +82,7 @@ mod english;
|
||||
pub mod es;
|
||||
pub mod fr;
|
||||
mod grammar_en;
|
||||
pub mod gu;
|
||||
pub mod hr;
|
||||
pub mod hunspell;
|
||||
pub mod hyphen;
|
||||
|
||||
@@ -539,6 +539,7 @@ fn hyphenation_locales(lang: ProofLang) -> Vec<String> {
|
||||
ProofLang::Ru => &["ru"],
|
||||
ProofLang::Cs => &["cs"],
|
||||
ProofLang::Id => &["id"],
|
||||
ProofLang::Gu => &["gu-in", "gu"],
|
||||
ProofLang::Es => &["es-es", "es"],
|
||||
ProofLang::EsMx => &["es-mx", "es-419", "es"],
|
||||
ProofLang::Es419 => &["es-419", "es"],
|
||||
|
||||
@@ -13,6 +13,7 @@ fn write_test_dictionaries(dir: &std::path::Path) {
|
||||
("ru_RU", ru::test_dict::AFF, ru::test_dict::DIC),
|
||||
("cs_CZ", cs::test_dict::AFF, cs::test_dict::DIC),
|
||||
("id_ID", id::test_dict::AFF, id::test_dict::DIC),
|
||||
("gu_IN", gu::test_dict::AFF, gu::test_dict::DIC),
|
||||
("es_ES", es::test_dict::AFF, es::test_dict::DIC),
|
||||
("es_MX", es::test_dict::AFF, es::test_dict::DIC_AMERICAS),
|
||||
("es_419", es::test_dict::AFF, es::test_dict::DIC_AMERICAS),
|
||||
@@ -628,7 +629,7 @@ fn mixed_language_paragraphs_check_each_run_in_its_language() {
|
||||
proptest::proptest! {
|
||||
#[test]
|
||||
fn mixed_spans_never_panic(s in "\\PC{0,60}", cuts in proptest::collection::vec((0usize..80, 0usize..80, 0u8..15), 0..6)) {
|
||||
let langs = [ProofLang::En, ProofLang::EnGb, ProofLang::EnCa, ProofLang::Pl, ProofLang::Pt, ProofLang::It, ProofLang::Tr, ProofLang::Ru, ProofLang::Cs, ProofLang::Id, ProofLang::Es, ProofLang::EsMx, ProofLang::Es419, ProofLang::EsUy, ProofLang::Other];
|
||||
let langs = [ProofLang::En, ProofLang::EnGb, ProofLang::EnCa, ProofLang::Pl, ProofLang::Pt, ProofLang::It, ProofLang::Tr, ProofLang::Ru, ProofLang::Cs, ProofLang::Id, ProofLang::Gu, ProofLang::Es, ProofLang::EsMx, ProofLang::Es419, ProofLang::EsUy, ProofLang::Other];
|
||||
let spans: Vec<(Range<usize>, ProofLang)> = cuts.iter().map(|&(a, b, l)| (a.min(b)..a.max(b), langs[l as usize % langs.len()])).collect();
|
||||
for i in check_text(&s, &spans) {
|
||||
proptest::prop_assert!(i.start <= i.end && i.end <= s.len());
|
||||
|
||||
Reference in new issue
Block a user