shevchenko
Version:
JavaScript library for declension of Ukrainian anthroponyms
38 lines (34 loc) • 1.27 kB
JavaScript
/**
* @file JavaScript library for declension of Ukrainian anthroponyms
* @module shevchenko
* @version 3.2.2
* @author Oleksandr Tolochko <shevchenko-js@tooleks.com>
* @license MIT
* @copyright 2017-2026 Oleksandr Tolochko <shevchenko-js@tooleks.com>
* @see {@link git+https://github.com/tooleks/shevchenko-js.git}
*/
;
var alphabet = require('../../language/alphabet.js');
require('../../language/word-class.js');
require('../../language/grammatical-case.js');
require('../../language/grammatical-gender.js');
class WordTransformer {
constructor(vectorSize, unknownCharcode = 0) {
this.vectorSize = vectorSize;
this.unknownCharcode = unknownCharcode;
}
/**
* Vectorizes a given word for ML processing.
*/
encode(word) {
var _a;
const values = new Uint8Array(this.vectorSize);
const letters = word.slice(-this.vectorSize).toLowerCase().padStart(this.vectorSize, '-');
for (let index = 0; index < letters.length; index += 1) {
const letter = letters[index];
values[index] = (_a = alphabet.AlphabetEncoding[letter]) !== null && _a !== void 0 ? _a : this.unknownCharcode;
}
return values;
}
}
exports.WordTransformer = WordTransformer;