Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify diacratic removal; modify Latin & Greek preprocessors #724

Merged
merged 13 commits into from
Apr 8, 2024
56 changes: 0 additions & 56 deletions ext/js/language/la/latin-text-preprocessors.js

This file was deleted.

11 changes: 7 additions & 4 deletions ext/js/language/language-descriptors.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import {removeArabicScriptDiacritics} from './ar/arabic-text-preprocessors.js';
import {eszettPreprocessor} from './de/german-text-preprocessors.js';
import {collapseEmphaticSequences, convertAlphabeticCharacters, convertHalfWidthCharacters, convertHiraganaToKatakana, convertNumericCharacters} from './ja/japanese-text-preprocessors.js';
import {isStringPartiallyJapanese} from './ja/japanese.js';
import {removeLatinDiacritics} from './la/latin-text-preprocessors.js';
import {removeRussianDiacritics, yoToE} from './ru/russian-text-preprocessors.js';
import {capitalizeFirstLetter, decapitalize} from './text-preprocessors.js';
import {capitalizeFirstLetter, decapitalize, removeAlphabeticDiacritics} from './text-preprocessors.js';

const capitalizationPreprocessors = {
decapitalize,
Expand Down Expand Up @@ -84,7 +83,10 @@ const languageDescriptors = [
iso: 'grc',
name: 'Ancient Greek',
exampleText: 'γράφω',
textPreprocessors: capitalizationPreprocessors
textPreprocessors: {
...capitalizationPreprocessors,
removeAlphabeticDiacritics
}
},
{
iso: 'hu',
Expand All @@ -109,7 +111,8 @@ const languageDescriptors = [
name: 'Latin',
exampleText: 'legere',
textPreprocessors: {
removeLatinDiacritics
...capitalizationPreprocessors,
removeAlphabeticDiacritics
}
},
{
Expand Down
14 changes: 14 additions & 0 deletions ext/js/language/text-preprocessors.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,17 @@
options: basicTextPreprocessorOptions,
process: (str, setting) => (setting ? str.charAt(0).toUpperCase() + str.slice(1) : str)
};

/**
* WARNING: This should NOT be used with languages that use Han characters,
* as it can result in undesirable normalization:

Check failure on line 39 in ext/js/language/text-preprocessors.js

View workflow job for this annotation

GitHub Actions / Static Analysis

Trailing spaces not allowed
* - '\u9038'.normalize('NFD') => '\u9038' (逸)

Check failure on line 40 in ext/js/language/text-preprocessors.js

View workflow job for this annotation

GitHub Actions / Static Analysis

Trailing spaces not allowed
* - '\ufa67'.normalize('NFD') => '\u9038' (逸 => 逸)

Check failure on line 41 in ext/js/language/text-preprocessors.js

View workflow job for this annotation

GitHub Actions / Static Analysis

Trailing spaces not allowed
* @type {import('language').TextPreprocessor<boolean>}
*/
export const removeAlphabeticDiacritics = {
name: 'Remove Alphabetic Diacritics',
description: 'ἄήé -> αηe',
options: basicTextPreprocessorOptions,
process: (str, setting) => (setting ? str.normalize('NFD').replace(/[\u0300-\u036f]/g, '') : str)
};
Loading