shevchenko 2.0.6 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/cjs/shevchenko.js +32 -33
- package/dist/cjs/shevchenko.js.map +1 -1
- package/dist/es/shevchenko.js +27 -27
- package/dist/es/shevchenko.js.map +1 -1
- package/dist/types/anthroponym-inflection/anthroponym-inflector.d.ts +1 -1
- package/dist/types/anthroponym-inflection/append-command-runner.d.ts +1 -1
- package/dist/types/anthroponym-inflection/command-runner-factory.d.ts +1 -1
- package/dist/types/anthroponym-inflection/name-inflector.d.ts +2 -2
- package/dist/types/anthroponym-inflection/replace-command-runner.d.ts +1 -1
- package/dist/types/anthroponym-inflection/rule-inflector.d.ts +1 -1
- package/dist/types/part-of-speech-recognition/neural-network.d.ts +3 -3
- package/dist/types/part-of-speech-recognition/part-of-speech-recognition-rule.d.ts +2 -2
- package/dist/types/part-of-speech-recognition/part-of-speech-recognizer.d.ts +2 -2
- package/dist/types/part-of-speech-recognition/word-transformer.d.ts +1 -1
- package/dist/types/shevchenko.d.ts +9 -8
- package/dist/types/shevchenko.d.ts.map +1 -1
- package/dist/types/utils/lang.utils.d.ts +1 -1
- package/dist/types/utils/regexp.utils.d.ts +1 -1
- package/dist/umd/shevchenko.min.js +5 -5
- package/dist/umd/shevchenko.min.js.map +1 -1
- package/package.json +16 -12
- package/src/anthroponym-inflection/anthroponym-inflector.ts +38 -0
- package/src/anthroponym-inflection/append-command-runner.ts +18 -0
- package/src/anthroponym-inflection/command-runner-factory.ts +23 -0
- package/src/anthroponym-inflection/first-name-inflector.ts +41 -0
- package/src/anthroponym-inflection/index.ts +5 -0
- package/src/anthroponym-inflection/inflector-command-runner.ts +3 -0
- package/src/anthroponym-inflection/inflector.types.ts +42 -0
- package/src/anthroponym-inflection/last-name-inflector.ts +54 -0
- package/src/anthroponym-inflection/middle-name-inflector.ts +29 -0
- package/src/anthroponym-inflection/name-inflector.ts +19 -0
- package/src/anthroponym-inflection/replace-command-runner.ts +18 -0
- package/src/anthroponym-inflection/rule-inflector.ts +40 -0
- package/src/bootstrap.ts +53 -0
- package/src/core/anthroponym.interface.ts +8 -0
- package/src/core/gender.enum.ts +4 -0
- package/src/core/grammatical-case.enum.ts +9 -0
- package/src/core/index.ts +4 -0
- package/src/core/validator.ts +39 -0
- package/src/internal.ts +1 -0
- package/src/part-of-speech-recognition/index.ts +5 -0
- package/src/part-of-speech-recognition/neural-network-config.ts +5 -0
- package/src/part-of-speech-recognition/neural-network-training-data.ts +5 -0
- package/src/part-of-speech-recognition/neural-network.ts +66 -0
- package/src/part-of-speech-recognition/part-of-speech-decoder.ts +26 -0
- package/src/part-of-speech-recognition/part-of-speech-encoder.ts +20 -0
- package/src/part-of-speech-recognition/part-of-speech-recognition-rule.ts +33 -0
- package/src/part-of-speech-recognition/part-of-speech-recognizer.ts +26 -0
- package/src/part-of-speech-recognition/part-of-speech.enum.ts +4 -0
- package/src/part-of-speech-recognition/word-encoder.ts +23 -0
- package/src/part-of-speech-recognition/word-transformer.ts +8 -0
- package/src/resources/inflector/rules.json +7114 -0
- package/src/resources/neural-networks/kosmii/README.md +5 -0
- package/src/resources/neural-networks/kosmii/cache.json +8 -0
- package/src/resources/neural-networks/kosmii/samples.json +9435 -0
- package/src/resources/neural-networks/kosmii/structure.json +47898 -0
- package/src/resources/neural-networks/pelykh/README.md +5 -0
- package/src/resources/neural-networks/pelykh/cache.json +1 -0
- package/src/resources/neural-networks/pelykh/samples.json +221 -0
- package/src/resources/neural-networks/pelykh/structure.json +47898 -0
- package/src/resources/neural-networks/pohorielova/README.md +5 -0
- package/src/resources/neural-networks/pohorielova/cache.json +542 -0
- package/src/resources/neural-networks/pohorielova/samples.json +32147 -0
- package/src/resources/neural-networks/pohorielova/structure.json +47898 -0
- package/src/shevchenko.ts +63 -0
- package/src/utils/lang.utils.ts +13 -0
- package/src/utils/regexp.utils.ts +11 -0
- package/src/utils/string.utils.ts +49 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
## shevchenko
|
|
2
2
|
|
|
3
|
-
JavaScript бібліотека для відмінювання українських
|
|
3
|
+
JavaScript бібліотека для відмінювання українських антропонімів / JavaScript library for declension of Ukrainian anthroponyms
|
|
4
4
|
|
|
5
5
|
### Документація / Documentation
|
|
6
6
|
|
|
@@ -16,13 +16,13 @@ npm install --save shevchenko
|
|
|
16
16
|
|
|
17
17
|
```JavaScript
|
|
18
18
|
const anthroponym = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
gender: 'male', // or 'female'
|
|
20
|
+
firstName: 'Тарас',
|
|
21
|
+
middleName: 'Григорович',
|
|
22
|
+
lastName: 'Шевченко'
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
const result = shevchenko.inVocative(anthroponym);
|
|
26
26
|
|
|
27
|
-
console.log(result); // { gender:
|
|
27
|
+
console.log(result); // { gender: "male", firstName: "Тарасе", middleName: "Григоровичу", lastName: "Шевченку" }
|
|
28
28
|
```
|
package/dist/cjs/shevchenko.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file JavaScript library
|
|
2
|
+
* @file JavaScript library for declension of Ukrainian anthroponyms
|
|
3
3
|
* @module shevchenko
|
|
4
|
-
* @version 2.
|
|
4
|
+
* @version 2.1.1
|
|
5
5
|
* @author Oleksandr Tolochko <tooleks@gmail.com>
|
|
6
6
|
* @license MIT
|
|
7
|
-
* @copyright
|
|
7
|
+
* @copyright 2022 Oleksandr Tolochko <tooleks@gmail.com>
|
|
8
8
|
* @see {@link git+https://github.com/tooleks/shevchenko-js.git}
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
@@ -17,11 +17,10 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
17
17
|
|
|
18
18
|
var synaptic__default = /*#__PURE__*/_interopDefaultLegacy(synaptic);
|
|
19
19
|
|
|
20
|
-
var Gender;
|
|
21
20
|
(function (Gender) {
|
|
22
21
|
Gender["Male"] = "male";
|
|
23
22
|
Gender["Female"] = "female";
|
|
24
|
-
})(Gender || (Gender = {}));
|
|
23
|
+
})(exports.Gender || (exports.Gender = {}));
|
|
25
24
|
|
|
26
25
|
var GrammaticalCase;
|
|
27
26
|
(function (GrammaticalCase) {
|
|
@@ -47,8 +46,8 @@ function validateAnthroponym(anthroponym) {
|
|
|
47
46
|
if (typeof anthroponym !== 'object') {
|
|
48
47
|
throw new TypeError('"anthroponym" must be an object.');
|
|
49
48
|
}
|
|
50
|
-
if (![Gender.Male, Gender.Female].includes(anthroponym.gender)) {
|
|
51
|
-
throw new TypeError("\"anthroponym.gender\" must be one of the following: \"" + Gender.Male + "\", \"" + Gender.Female + "\".");
|
|
49
|
+
if (![exports.Gender.Male, exports.Gender.Female].includes(anthroponym.gender)) {
|
|
50
|
+
throw new TypeError("\"anthroponym.gender\" must be one of the following: \"" + exports.Gender.Male + "\", \"" + exports.Gender.Female + "\".");
|
|
52
51
|
}
|
|
53
52
|
// tslint:disable-next-line max-line-length
|
|
54
53
|
if (typeof anthroponym.firstName === 'undefined' && typeof anthroponym.middleName === 'undefined' && typeof anthroponym.lastName === 'undefined') {
|
|
@@ -74,7 +73,7 @@ var AnthroponymInflector = /** @class */ (function () {
|
|
|
74
73
|
this.lastNameInflector = lastNameInflector;
|
|
75
74
|
}
|
|
76
75
|
/**
|
|
77
|
-
* Inflects
|
|
76
|
+
* Inflects the anthroponym in the given grammatical case.
|
|
78
77
|
*/
|
|
79
78
|
AnthroponymInflector.prototype.inflect = function (anthroponym, grammaticalCase) {
|
|
80
79
|
var result = { gender: anthroponym.gender };
|
|
@@ -122,7 +121,7 @@ function __extends(d, b) {
|
|
|
122
121
|
}
|
|
123
122
|
|
|
124
123
|
/**
|
|
125
|
-
* Counts a number of groups in
|
|
124
|
+
* Counts a number of groups in the given regular expression.
|
|
126
125
|
*/
|
|
127
126
|
function countGroups(src) {
|
|
128
127
|
var pattern = new RegExp(src.toString() + "|");
|
|
@@ -195,7 +194,7 @@ var AppendCommandRunner = /** @class */ (function () {
|
|
|
195
194
|
this.command = command;
|
|
196
195
|
}
|
|
197
196
|
/**
|
|
198
|
-
* Appends the command value to
|
|
197
|
+
* Appends the command value to the given value.
|
|
199
198
|
* Returns a new value.
|
|
200
199
|
*/
|
|
201
200
|
AppendCommandRunner.prototype.exec = function (value) {
|
|
@@ -209,7 +208,7 @@ var ReplaceCommandRunner = /** @class */ (function () {
|
|
|
209
208
|
this.command = command;
|
|
210
209
|
}
|
|
211
210
|
/**
|
|
212
|
-
* Replaces
|
|
211
|
+
* Replaces the given value with the command value.
|
|
213
212
|
* Returns a new value.
|
|
214
213
|
*/
|
|
215
214
|
ReplaceCommandRunner.prototype.exec = function (value) {
|
|
@@ -222,7 +221,7 @@ var CommandRunnerFactory = /** @class */ (function () {
|
|
|
222
221
|
function CommandRunnerFactory() {
|
|
223
222
|
}
|
|
224
223
|
/**
|
|
225
|
-
* Creates a new command runner for
|
|
224
|
+
* Creates a new command runner for the given command.
|
|
226
225
|
*/
|
|
227
226
|
CommandRunnerFactory.prototype.make = function (command) {
|
|
228
227
|
switch (command.type) {
|
|
@@ -246,7 +245,7 @@ var RuleInflector = /** @class */ (function () {
|
|
|
246
245
|
this.commandRunnerFactory = new CommandRunnerFactory();
|
|
247
246
|
}
|
|
248
247
|
/**
|
|
249
|
-
* Inflects
|
|
248
|
+
* Inflects the given word in the given grammatical case using the rule.
|
|
250
249
|
*/
|
|
251
250
|
RuleInflector.prototype.inflect = function (word, grammaticalCase) {
|
|
252
251
|
var _this = this;
|
|
@@ -281,7 +280,7 @@ var NameInflector = /** @class */ (function () {
|
|
|
281
280
|
function NameInflector() {
|
|
282
281
|
}
|
|
283
282
|
/**
|
|
284
|
-
* Inflects
|
|
283
|
+
* Inflects the name in the given grammatical case.
|
|
285
284
|
*/
|
|
286
285
|
NameInflector.prototype.inflect = function (name, gender, grammaticalCase) {
|
|
287
286
|
var _this = this;
|
|
@@ -353,7 +352,7 @@ var MiddleNameInflector = /** @class */ (function (_super) {
|
|
|
353
352
|
|
|
354
353
|
var PATTERN_VOWELS = /[аоуеиіяюєї]/gi;
|
|
355
354
|
/**
|
|
356
|
-
* Counts vowel sounds in
|
|
355
|
+
* Counts vowel sounds in the given word.
|
|
357
356
|
* Returns a number of vowels.
|
|
358
357
|
*/
|
|
359
358
|
function countVowels(word) {
|
|
@@ -511,7 +510,7 @@ var NeuralNetwork = /** @class */ (function () {
|
|
|
511
510
|
return JSON.stringify(this.toJSON(), null, 2);
|
|
512
511
|
};
|
|
513
512
|
/**
|
|
514
|
-
* Trains the neural network using
|
|
513
|
+
* Trains the neural network using the given training data.
|
|
515
514
|
*/
|
|
516
515
|
NeuralNetwork.prototype.train = function (trainingData, trainingOptions) {
|
|
517
516
|
var trainingSet = Object.entries(trainingData).map(function (_a) {
|
|
@@ -525,8 +524,8 @@ var NeuralNetwork = /** @class */ (function () {
|
|
|
525
524
|
return this;
|
|
526
525
|
};
|
|
527
526
|
/**
|
|
528
|
-
* Activates the neural network for
|
|
529
|
-
* Returns a part of speech of
|
|
527
|
+
* Activates the neural network for the given word.
|
|
528
|
+
* Returns a part of speech of the given word.
|
|
530
529
|
*/
|
|
531
530
|
NeuralNetwork.prototype.activate = function (word) {
|
|
532
531
|
var input = new WordEncoder().encode(word);
|
|
@@ -540,7 +539,7 @@ var WordTransformer = /** @class */ (function () {
|
|
|
540
539
|
function WordTransformer() {
|
|
541
540
|
}
|
|
542
541
|
/**
|
|
543
|
-
* Transform
|
|
542
|
+
* Transform the given word for use in part of speech recognition process.
|
|
544
543
|
*/
|
|
545
544
|
WordTransformer.prototype.transform = function (word) {
|
|
546
545
|
return word.toLowerCase();
|
|
@@ -553,8 +552,8 @@ var PartOfSpeechRecognizer = /** @class */ (function () {
|
|
|
553
552
|
this.rules = rules;
|
|
554
553
|
}
|
|
555
554
|
/**
|
|
556
|
-
* Recognizes the part of speech of
|
|
557
|
-
* Returns part of speech of
|
|
555
|
+
* Recognizes the part of speech of the given word.
|
|
556
|
+
* Returns part of speech of the given word.
|
|
558
557
|
* Returns null if part of speech was not recognized.
|
|
559
558
|
*/
|
|
560
559
|
PartOfSpeechRecognizer.prototype.recognize = function (word, gender) {
|
|
@@ -575,8 +574,8 @@ var PartOfSpeechRecognitionRule = /** @class */ (function () {
|
|
|
575
574
|
this.cache = cache;
|
|
576
575
|
}
|
|
577
576
|
/**
|
|
578
|
-
* Applies the part of speech recognizer rule to
|
|
579
|
-
* Returns a part of speech of
|
|
577
|
+
* Applies the part of speech recognizer rule to the given word.
|
|
578
|
+
* Returns a part of speech of the given word.
|
|
580
579
|
*/
|
|
581
580
|
PartOfSpeechRecognitionRule.prototype.apply = function (word) {
|
|
582
581
|
var transformedWord = new WordTransformer().transform(word);
|
|
@@ -154436,9 +154435,9 @@ var pohorielovaStructure = {
|
|
|
154436
154435
|
};
|
|
154437
154436
|
|
|
154438
154437
|
var partOfSpeechRecognizer = new PartOfSpeechRecognizer([
|
|
154439
|
-
new PartOfSpeechRecognitionRule(function (word, gender) { return gender === Gender.Female && /[ая]$/i.test(word); }, NeuralNetwork.fromJSON(pohorielovaStructure), pohorielovaCache),
|
|
154440
|
-
new PartOfSpeechRecognitionRule(function (word, gender) { return gender === Gender.Male && /(ой|ий|ій)$/i.test(word); }, NeuralNetwork.fromJSON(kosmiiStructure), kosmiiCache),
|
|
154441
|
-
new PartOfSpeechRecognitionRule(function (word, gender) { return gender === Gender.Male && /(их)$/i.test(word); }, NeuralNetwork.fromJSON(pelykhStructure), pelykhCache),
|
|
154438
|
+
new PartOfSpeechRecognitionRule(function (word, gender) { return gender === exports.Gender.Female && /[ая]$/i.test(word); }, NeuralNetwork.fromJSON(pohorielovaStructure), pohorielovaCache),
|
|
154439
|
+
new PartOfSpeechRecognitionRule(function (word, gender) { return gender === exports.Gender.Male && /(ой|ий|ій)$/i.test(word); }, NeuralNetwork.fromJSON(kosmiiStructure), kosmiiCache),
|
|
154440
|
+
new PartOfSpeechRecognitionRule(function (word, gender) { return gender === exports.Gender.Male && /(их)$/i.test(word); }, NeuralNetwork.fromJSON(pelykhStructure), pelykhCache),
|
|
154442
154441
|
]);
|
|
154443
154442
|
var firstNameInflector = new FirstNameInflector(inflectorRules);
|
|
154444
154443
|
var middleNameInflector = new MiddleNameInflector(inflectorRules);
|
|
@@ -154451,49 +154450,49 @@ var internal = /*#__PURE__*/Object.freeze({
|
|
|
154451
154450
|
});
|
|
154452
154451
|
|
|
154453
154452
|
/**
|
|
154454
|
-
* Inflects
|
|
154453
|
+
* Inflects the anthroponym in nominative grammatical case.
|
|
154455
154454
|
*/
|
|
154456
154455
|
function inNominative(anthroponym) {
|
|
154457
154456
|
validateAnthroponym(anthroponym);
|
|
154458
154457
|
return anthroponymInflector.inflect(anthroponym, GrammaticalCase.Nominative);
|
|
154459
154458
|
}
|
|
154460
154459
|
/**
|
|
154461
|
-
* Inflects
|
|
154460
|
+
* Inflects the anthroponym in genitive grammatical case.
|
|
154462
154461
|
*/
|
|
154463
154462
|
function inGenitive(anthroponym) {
|
|
154464
154463
|
validateAnthroponym(anthroponym);
|
|
154465
154464
|
return anthroponymInflector.inflect(anthroponym, GrammaticalCase.Genitive);
|
|
154466
154465
|
}
|
|
154467
154466
|
/**
|
|
154468
|
-
* Inflects
|
|
154467
|
+
* Inflects the anthroponym in dative grammatical case.
|
|
154469
154468
|
*/
|
|
154470
154469
|
function inDative(anthroponym) {
|
|
154471
154470
|
validateAnthroponym(anthroponym);
|
|
154472
154471
|
return anthroponymInflector.inflect(anthroponym, GrammaticalCase.Dative);
|
|
154473
154472
|
}
|
|
154474
154473
|
/**
|
|
154475
|
-
* Inflects
|
|
154474
|
+
* Inflects the anthroponym in accusative grammatical case.
|
|
154476
154475
|
*/
|
|
154477
154476
|
function inAccusative(anthroponym) {
|
|
154478
154477
|
validateAnthroponym(anthroponym);
|
|
154479
154478
|
return anthroponymInflector.inflect(anthroponym, GrammaticalCase.Accusative);
|
|
154480
154479
|
}
|
|
154481
154480
|
/**
|
|
154482
|
-
* Inflects
|
|
154481
|
+
* Inflects the anthroponym in ablative grammatical case.
|
|
154483
154482
|
*/
|
|
154484
154483
|
function inAblative(anthroponym) {
|
|
154485
154484
|
validateAnthroponym(anthroponym);
|
|
154486
154485
|
return anthroponymInflector.inflect(anthroponym, GrammaticalCase.Ablative);
|
|
154487
154486
|
}
|
|
154488
154487
|
/**
|
|
154489
|
-
* Inflects
|
|
154488
|
+
* Inflects the anthroponym in locative grammatical case.
|
|
154490
154489
|
*/
|
|
154491
154490
|
function inLocative(anthroponym) {
|
|
154492
154491
|
validateAnthroponym(anthroponym);
|
|
154493
154492
|
return anthroponymInflector.inflect(anthroponym, GrammaticalCase.Locative);
|
|
154494
154493
|
}
|
|
154495
154494
|
/**
|
|
154496
|
-
* Inflects
|
|
154495
|
+
* Inflects the anthroponym in vocative grammatical case.
|
|
154497
154496
|
*/
|
|
154498
154497
|
function inVocative(anthroponym) {
|
|
154499
154498
|
validateAnthroponym(anthroponym);
|