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.
Files changed (69) hide show
  1. package/README.md +6 -6
  2. package/dist/cjs/shevchenko.js +32 -33
  3. package/dist/cjs/shevchenko.js.map +1 -1
  4. package/dist/es/shevchenko.js +27 -27
  5. package/dist/es/shevchenko.js.map +1 -1
  6. package/dist/types/anthroponym-inflection/anthroponym-inflector.d.ts +1 -1
  7. package/dist/types/anthroponym-inflection/append-command-runner.d.ts +1 -1
  8. package/dist/types/anthroponym-inflection/command-runner-factory.d.ts +1 -1
  9. package/dist/types/anthroponym-inflection/name-inflector.d.ts +2 -2
  10. package/dist/types/anthroponym-inflection/replace-command-runner.d.ts +1 -1
  11. package/dist/types/anthroponym-inflection/rule-inflector.d.ts +1 -1
  12. package/dist/types/part-of-speech-recognition/neural-network.d.ts +3 -3
  13. package/dist/types/part-of-speech-recognition/part-of-speech-recognition-rule.d.ts +2 -2
  14. package/dist/types/part-of-speech-recognition/part-of-speech-recognizer.d.ts +2 -2
  15. package/dist/types/part-of-speech-recognition/word-transformer.d.ts +1 -1
  16. package/dist/types/shevchenko.d.ts +9 -8
  17. package/dist/types/shevchenko.d.ts.map +1 -1
  18. package/dist/types/utils/lang.utils.d.ts +1 -1
  19. package/dist/types/utils/regexp.utils.d.ts +1 -1
  20. package/dist/umd/shevchenko.min.js +5 -5
  21. package/dist/umd/shevchenko.min.js.map +1 -1
  22. package/package.json +16 -12
  23. package/src/anthroponym-inflection/anthroponym-inflector.ts +38 -0
  24. package/src/anthroponym-inflection/append-command-runner.ts +18 -0
  25. package/src/anthroponym-inflection/command-runner-factory.ts +23 -0
  26. package/src/anthroponym-inflection/first-name-inflector.ts +41 -0
  27. package/src/anthroponym-inflection/index.ts +5 -0
  28. package/src/anthroponym-inflection/inflector-command-runner.ts +3 -0
  29. package/src/anthroponym-inflection/inflector.types.ts +42 -0
  30. package/src/anthroponym-inflection/last-name-inflector.ts +54 -0
  31. package/src/anthroponym-inflection/middle-name-inflector.ts +29 -0
  32. package/src/anthroponym-inflection/name-inflector.ts +19 -0
  33. package/src/anthroponym-inflection/replace-command-runner.ts +18 -0
  34. package/src/anthroponym-inflection/rule-inflector.ts +40 -0
  35. package/src/bootstrap.ts +53 -0
  36. package/src/core/anthroponym.interface.ts +8 -0
  37. package/src/core/gender.enum.ts +4 -0
  38. package/src/core/grammatical-case.enum.ts +9 -0
  39. package/src/core/index.ts +4 -0
  40. package/src/core/validator.ts +39 -0
  41. package/src/internal.ts +1 -0
  42. package/src/part-of-speech-recognition/index.ts +5 -0
  43. package/src/part-of-speech-recognition/neural-network-config.ts +5 -0
  44. package/src/part-of-speech-recognition/neural-network-training-data.ts +5 -0
  45. package/src/part-of-speech-recognition/neural-network.ts +66 -0
  46. package/src/part-of-speech-recognition/part-of-speech-decoder.ts +26 -0
  47. package/src/part-of-speech-recognition/part-of-speech-encoder.ts +20 -0
  48. package/src/part-of-speech-recognition/part-of-speech-recognition-rule.ts +33 -0
  49. package/src/part-of-speech-recognition/part-of-speech-recognizer.ts +26 -0
  50. package/src/part-of-speech-recognition/part-of-speech.enum.ts +4 -0
  51. package/src/part-of-speech-recognition/word-encoder.ts +23 -0
  52. package/src/part-of-speech-recognition/word-transformer.ts +8 -0
  53. package/src/resources/inflector/rules.json +7114 -0
  54. package/src/resources/neural-networks/kosmii/README.md +5 -0
  55. package/src/resources/neural-networks/kosmii/cache.json +8 -0
  56. package/src/resources/neural-networks/kosmii/samples.json +9435 -0
  57. package/src/resources/neural-networks/kosmii/structure.json +47898 -0
  58. package/src/resources/neural-networks/pelykh/README.md +5 -0
  59. package/src/resources/neural-networks/pelykh/cache.json +1 -0
  60. package/src/resources/neural-networks/pelykh/samples.json +221 -0
  61. package/src/resources/neural-networks/pelykh/structure.json +47898 -0
  62. package/src/resources/neural-networks/pohorielova/README.md +5 -0
  63. package/src/resources/neural-networks/pohorielova/cache.json +542 -0
  64. package/src/resources/neural-networks/pohorielova/samples.json +32147 -0
  65. package/src/resources/neural-networks/pohorielova/structure.json +47898 -0
  66. package/src/shevchenko.ts +63 -0
  67. package/src/utils/lang.utils.ts +13 -0
  68. package/src/utils/regexp.utils.ts +11 -0
  69. package/src/utils/string.utils.ts +49 -0
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## shevchenko
2
2
 
3
- JavaScript бібліотека для відмінювання українських прізвищ, імен та по батькові / JavaScript library to inflect Ukrainian first, middle and last names
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
- gender: 'male', // or 'female'
20
- firstName: 'Тарас',
21
- middleName: 'Григорович',
22
- lastName: 'Шевченко'
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: 'male', firstName: 'Тарасе', middleName: 'Григоровичу', lastName: 'Шевченку' }
27
+ console.log(result); // { gender: "male", firstName: "Тарасе", middleName: "Григоровичу", lastName: "Шевченку" }
28
28
  ```
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @file JavaScript library to inflect Ukrainian first, middle and last names
2
+ * @file JavaScript library for declension of Ukrainian anthroponyms
3
3
  * @module shevchenko
4
- * @version 2.0.6
4
+ * @version 2.1.1
5
5
  * @author Oleksandr Tolochko <tooleks@gmail.com>
6
6
  * @license MIT
7
- * @copyright 2020 Oleksandr Tolochko <tooleks@gmail.com>
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 a given anthroponym in a given grammatical case.
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 a given regular expression.
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 a given value.
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 a given value with the command value.
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 a given command.
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 a given word in a given grammatical case using the rule.
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 a given name in a given grammatical case.
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 a given word.
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 a given training data.
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 a given word.
529
- * Returns a part of speech of a given word.
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 a given word for use in part of speech recognition process.
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 a given word.
557
- * Returns part of speech of a given word.
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 a given word.
579
- * Returns a part of speech of a given word.
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 an anthroponym in nominative grammatical case.
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 an anthroponym in genitive grammatical case.
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 an anthroponym in dative grammatical case.
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 an anthroponym in accusative grammatical case.
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 an anthroponym in ablative grammatical case.
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 an anthroponym in locative grammatical case.
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 an anthroponym in vocative grammatical case.
154495
+ * Inflects the anthroponym in vocative grammatical case.
154497
154496
  */
154498
154497
  function inVocative(anthroponym) {
154499
154498
  validateAnthroponym(anthroponym);