Skip to content

Commit

Permalink
Move normalizeRadicalCharacters to CJK-util
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuuuube committed Nov 3, 2024
1 parent 1a234b1 commit b1b97ba
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
10 changes: 10 additions & 0 deletions ext/js/language/CJK-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import {basicTextProcessorOptions} from './text-processors.js';

/** @type {import('CJK-util').CodepointRange} */
const CJK_UNIFIED_IDEOGRAPHS_RANGE = [0x4e00, 0x9fff];
/** @type {import('CJK-util').CodepointRange} */
Expand Down Expand Up @@ -123,3 +125,11 @@ export function normalizeRadicals(text) {
}
return result;
}

/** @type {import('language').TextProcessor<boolean>} */
export const normalizeRadicalCharacters = {
name: 'Normalize radical characters',
description: '⼀ → 一 (U+2F00 → U+4E00)',
options: basicTextProcessorOptions,
process: (str, setting) => (setting ? normalizeRadicals(str) : str),
};
9 changes: 0 additions & 9 deletions ext/js/language/ja/japanese-text-preprocessors.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import {normalizeRadicals} from '../CJK-util.js';
import {basicTextProcessorOptions} from '../text-processors.js';
import {convertAlphabeticToKana} from './japanese-wanakana.js';
import {
Expand Down Expand Up @@ -100,11 +99,3 @@ export const normalizeCombiningCharacters = {
options: basicTextProcessorOptions,
process: (str, setting) => (setting ? normalizeCombiningCharactersFunction(str) : str),
};

/** @type {import('language').TextProcessor<boolean>} */
export const normalizeRadicalCharacters = {
name: 'Normalize radical characters',
description: '⼀ → 一 (U+2F00 → U+4E00)',
options: basicTextProcessorOptions,
process: (str, setting) => (setting ? normalizeRadicals(str) : str),
};
2 changes: 1 addition & 1 deletion ext/js/language/language-descriptors.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

import {removeArabicScriptDiacritics} from './ar/arabic-text-preprocessors.js';
import {normalizeRadicalCharacters} from './CJK-util.js';
import {eszettPreprocessor} from './de/german-text-preprocessors.js';
import {germanTransforms} from './de/german-transforms.js';
import {englishTransforms} from './en/english-transforms.js';
Expand All @@ -27,7 +28,6 @@ import {
convertHalfWidthCharacters,
convertHiraganaToKatakana,
normalizeCombiningCharacters,
normalizeRadicalCharacters,
} from './ja/japanese-text-preprocessors.js';
import {japaneseTransforms} from './ja/japanese-transforms.js';
import {isStringPartiallyJapanese} from './ja/japanese.js';
Expand Down
11 changes: 1 addition & 10 deletions ext/js/language/zh/chinese.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import {CJK_IDEOGRAPH_RANGES, CJK_PUNCTUATION_RANGE, FULLWIDTH_CHARACTER_RANGES, isCodePointInRanges, normalizeRadicals} from '../CJK-util.js';
import {basicTextProcessorOptions} from '../text-processors.js';
import {CJK_IDEOGRAPH_RANGES, CJK_PUNCTUATION_RANGE, FULLWIDTH_CHARACTER_RANGES, isCodePointInRanges} from '../CJK-util.js';

/** @type {import('CJK-util').CodepointRange} */
const BOPOMOFO_RANGE = [0x3100, 0x312f];
Expand Down Expand Up @@ -74,11 +73,3 @@ export function isCodePointChinese(codePoint) {
export function normalizePinyin(str) {
return str.normalize('NFC').toLowerCase().replace(/[\s・:'’-]|\/\//g, '');
}

/** @type {import('language').TextProcessor<boolean>} */
export const normalizeRadicalCharacters = {
name: 'Normalize radical characters',
description: '⼀ → 一 (U+2F00 → U+4E00)',
options: basicTextProcessorOptions,
process: (str, setting) => (setting ? normalizeRadicals(str) : str),
};

0 comments on commit b1b97ba

Please sign in to comment.