shevchenko 2.1.2 → 2.2.0
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/.eslintrc.json +53 -0
- package/.prettierrc.json +5 -0
- package/dist/cjs/shevchenko.js +1307 -122
- package/dist/cjs/shevchenko.js.map +1 -1
- package/dist/es/shevchenko.js +1310 -128
- package/dist/es/shevchenko.js.map +1 -1
- package/dist/types/anthroponym-inflection/anthroponym-inflector.d.ts.map +1 -1
- package/dist/types/anthroponym-inflection/command-runner-factory.d.ts +1 -1
- package/dist/types/anthroponym-inflection/command-runner-factory.d.ts.map +1 -1
- package/dist/types/anthroponym-inflection/first-name-inflector.d.ts +1 -1
- package/dist/types/anthroponym-inflection/first-name-inflector.d.ts.map +1 -1
- package/dist/types/anthroponym-inflection/last-name-inflector.d.ts +1 -1
- package/dist/types/anthroponym-inflection/last-name-inflector.d.ts.map +1 -1
- package/dist/types/anthroponym-inflection/middle-name-inflector.d.ts +1 -1
- package/dist/types/anthroponym-inflection/middle-name-inflector.d.ts.map +1 -1
- package/dist/types/anthroponym-inflection/name-inflector.d.ts.map +1 -1
- package/dist/types/anthroponym-inflection/replace-command-runner.d.ts +1 -1
- package/dist/types/anthroponym-inflection/replace-command-runner.d.ts.map +1 -1
- package/dist/types/anthroponym-inflection/rule-inflector.d.ts.map +1 -1
- package/dist/types/bootstrap.d.ts.map +1 -1
- package/dist/types/core/validator.d.ts.map +1 -1
- package/dist/types/gender-detection/detect-gender.d.ts +11 -0
- package/dist/types/gender-detection/detect-gender.d.ts.map +1 -0
- package/dist/types/gender-detection/index.d.ts +2 -0
- package/dist/types/gender-detection/index.d.ts.map +1 -0
- package/dist/types/part-of-speech-recognition/neural-network.d.ts +1 -1
- package/dist/types/part-of-speech-recognition/neural-network.d.ts.map +1 -1
- package/dist/types/part-of-speech-recognition/part-of-speech-decoder.d.ts.map +1 -1
- package/dist/types/part-of-speech-recognition/part-of-speech-recognition-rule.d.ts +1 -1
- package/dist/types/part-of-speech-recognition/part-of-speech-recognition-rule.d.ts.map +1 -1
- package/dist/types/part-of-speech-recognition/part-of-speech-recognizer.d.ts +1 -1
- package/dist/types/part-of-speech-recognition/part-of-speech-recognizer.d.ts.map +1 -1
- package/dist/types/shevchenko.d.ts +3 -2
- package/dist/types/shevchenko.d.ts.map +1 -1
- package/dist/types/utils/string.utils.d.ts.map +1 -1
- package/dist/umd/shevchenko.min.js +4 -4
- package/dist/umd/shevchenko.min.js.map +1 -1
- package/nuxt/components/declension-demo.vue +7 -1
- package/nuxt/components/declension-form.vue +77 -10
- package/nuxt/components/declension-results.vue +26 -7
- package/nuxt/components/how-it-works.vue +10 -10
- package/nuxt/composables/declension.ts +47 -4
- package/nuxt/data/female-first-names.json +556 -0
- package/nuxt/data/male-first-names.json +603 -0
- package/nuxt/locales/en-US.json +6 -3
- package/nuxt/locales/uk-UA.json +8 -5
- package/nuxt/package-lock.json +7 -7
- package/nuxt/package.json +2 -2
- package/package.json +13 -10
- package/src/anthroponym-inflection/anthroponym-inflector.ts +20 -5
- package/src/anthroponym-inflection/command-runner-factory.ts +2 -2
- package/src/anthroponym-inflection/first-name-inflector.ts +5 -5
- package/src/anthroponym-inflection/inflector.types.ts +19 -19
- package/src/anthroponym-inflection/last-name-inflector.ts +10 -6
- package/src/anthroponym-inflection/middle-name-inflector.ts +5 -5
- package/src/anthroponym-inflection/name-inflector.ts +9 -3
- package/src/anthroponym-inflection/replace-command-runner.ts +1 -1
- package/src/anthroponym-inflection/rule-inflector.ts +2 -2
- package/src/bootstrap.ts +10 -10
- package/src/core/validator.ts +12 -5
- package/src/gender-detection/detect-gender.ts +43 -0
- package/src/gender-detection/given-names-genders.json +1144 -0
- package/src/gender-detection/index.ts +1 -0
- package/src/part-of-speech-recognition/neural-network.ts +10 -5
- package/src/part-of-speech-recognition/part-of-speech-decoder.ts +1 -1
- package/src/part-of-speech-recognition/part-of-speech-recognition-rule.ts +6 -2
- package/src/part-of-speech-recognition/part-of-speech-recognizer.ts +2 -2
- package/src/part-of-speech-recognition/word-encoder.ts +2 -2
- package/src/resources/inflector/rules.json +27 -26
- package/src/shevchenko.ts +4 -3
- package/src/utils/string.utils.ts +3 -3
- package/test/anthroponym-inflection.js +58 -0
- package/test/gender-detection.js +29 -0
- package/test/input-validation.js +353 -0
- package/test/main.test.js +18 -0
- package/test/samples.json +7282 -0
- package/tsconfig.types.json +9 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { detectGender, GenderlessAnthroponym } from './detect-gender';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import synaptic from 'synaptic';
|
|
2
|
-
import { PartOfSpeech } from './part-of-speech.enum';
|
|
3
|
-
import { WordEncoder } from './word-encoder';
|
|
4
|
-
import { PartOfSpeechDecoder } from './part-of-speech-decoder';
|
|
5
2
|
import { neuralNetworkConfig } from './neural-network-config';
|
|
6
|
-
import { PartOfSpeechEncoder } from './part-of-speech-encoder';
|
|
7
3
|
import { NeuralNetworkTrainingData } from './neural-network-training-data';
|
|
4
|
+
import { PartOfSpeechDecoder } from './part-of-speech-decoder';
|
|
5
|
+
import { PartOfSpeechEncoder } from './part-of-speech-encoder';
|
|
6
|
+
import { PartOfSpeech } from './part-of-speech.enum';
|
|
7
|
+
import { WordEncoder } from './word-encoder';
|
|
8
8
|
|
|
9
9
|
export class NeuralNetwork {
|
|
10
10
|
private network: synaptic.Network;
|
|
@@ -20,6 +20,7 @@ export class NeuralNetwork {
|
|
|
20
20
|
/**
|
|
21
21
|
* Creates a neural network from JSON.
|
|
22
22
|
*/
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
24
|
static fromJSON(structure: any): NeuralNetwork {
|
|
24
25
|
const instance = new this();
|
|
25
26
|
instance.network = synaptic.Network.fromJSON(structure);
|
|
@@ -43,7 +44,11 @@ export class NeuralNetwork {
|
|
|
43
44
|
/**
|
|
44
45
|
* Trains the neural network using the given training data.
|
|
45
46
|
*/
|
|
46
|
-
train(
|
|
47
|
+
train(
|
|
48
|
+
trainingData: NeuralNetworkTrainingData,
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
|
+
trainingOptions: any,
|
|
51
|
+
): NeuralNetwork {
|
|
47
52
|
const trainingSet = Object.entries(trainingData).map(([word, partOfSpeech]) => {
|
|
48
53
|
return {
|
|
49
54
|
input: new WordEncoder().encode(word),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { PartOfSpeech } from './part-of-speech.enum';
|
|
2
1
|
import { Gender } from '../core';
|
|
3
2
|
import { NeuralNetwork } from './neural-network';
|
|
4
3
|
import { NeuralNetworkTrainingData } from './neural-network-training-data';
|
|
4
|
+
import { PartOfSpeech } from './part-of-speech.enum';
|
|
5
5
|
import { WordTransformer } from './word-transformer';
|
|
6
6
|
|
|
7
7
|
export interface PartOfSpeechRecognitionGuard {
|
|
@@ -13,7 +13,11 @@ export class PartOfSpeechRecognitionRule {
|
|
|
13
13
|
readonly cache: NeuralNetworkTrainingData;
|
|
14
14
|
private readonly neuralNetwork: NeuralNetwork;
|
|
15
15
|
|
|
16
|
-
constructor(
|
|
16
|
+
constructor(
|
|
17
|
+
guard: PartOfSpeechRecognitionGuard,
|
|
18
|
+
neuralNetwork: NeuralNetwork,
|
|
19
|
+
cache: NeuralNetworkTrainingData,
|
|
20
|
+
) {
|
|
17
21
|
this.guard = guard;
|
|
18
22
|
this.neuralNetwork = neuralNetwork;
|
|
19
23
|
this.cache = cache;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PartOfSpeechRecognitionRule } from './part-of-speech-recognition-rule';
|
|
2
1
|
import { Gender } from '../core';
|
|
2
|
+
import { PartOfSpeechRecognitionRule } from './part-of-speech-recognition-rule';
|
|
3
3
|
import { PartOfSpeech } from './part-of-speech.enum';
|
|
4
4
|
import { WordTransformer } from './word-transformer';
|
|
5
5
|
|
|
@@ -17,7 +17,7 @@ export class PartOfSpeechRecognizer {
|
|
|
17
17
|
*/
|
|
18
18
|
recognize(word: string, gender: Gender): PartOfSpeech | null {
|
|
19
19
|
const transformedWord = new WordTransformer().transform(word);
|
|
20
|
-
const rule = this.rules.find(rule => rule.guard(transformedWord, gender));
|
|
20
|
+
const rule = this.rules.find((rule) => rule.guard(transformedWord, gender));
|
|
21
21
|
if (!rule) {
|
|
22
22
|
return null;
|
|
23
23
|
}
|
|
@@ -14,10 +14,10 @@ export class WordEncoder {
|
|
|
14
14
|
return input
|
|
15
15
|
.toLowerCase()
|
|
16
16
|
.split('')
|
|
17
|
-
.map(char => char.charCodeAt(0).toString(2))
|
|
17
|
+
.map((char) => char.charCodeAt(0).toString(2))
|
|
18
18
|
.join('')
|
|
19
19
|
.padStart(this.size, '0')
|
|
20
20
|
.split('')
|
|
21
|
-
.map(digit => Number.parseInt(digit, 2));
|
|
21
|
+
.map((digit) => Number.parseInt(digit, 2));
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -316,9 +316,9 @@
|
|
|
316
316
|
}
|
|
317
317
|
},
|
|
318
318
|
{
|
|
319
|
-
"description": "друга відміна / чоловічий рід / м'яка група /
|
|
319
|
+
"description": "друга відміна / чоловічий рід / м'яка група / на -(голосна)вень",
|
|
320
320
|
"examples": [
|
|
321
|
-
"
|
|
321
|
+
"півень"
|
|
322
322
|
],
|
|
323
323
|
"partOfSpeech": "noun",
|
|
324
324
|
"gender": [
|
|
@@ -327,7 +327,7 @@
|
|
|
327
327
|
"priority": 6,
|
|
328
328
|
"usage": [],
|
|
329
329
|
"pattern": {
|
|
330
|
-
"find": "
|
|
330
|
+
"find": "(а|е|є|и|і|ї|о|у|ю|я)вень$",
|
|
331
331
|
"modify": "(.{1})(.{1})(.{1})$"
|
|
332
332
|
},
|
|
333
333
|
"grammaticalCases": {
|
|
@@ -336,7 +336,7 @@
|
|
|
336
336
|
{
|
|
337
337
|
"0": {
|
|
338
338
|
"type": "replace",
|
|
339
|
-
"value": "
|
|
339
|
+
"value": ""
|
|
340
340
|
},
|
|
341
341
|
"2": {
|
|
342
342
|
"type": "replace",
|
|
@@ -348,7 +348,7 @@
|
|
|
348
348
|
{
|
|
349
349
|
"0": {
|
|
350
350
|
"type": "replace",
|
|
351
|
-
"value": "
|
|
351
|
+
"value": ""
|
|
352
352
|
},
|
|
353
353
|
"2": {
|
|
354
354
|
"type": "replace",
|
|
@@ -358,7 +358,7 @@
|
|
|
358
358
|
{
|
|
359
359
|
"0": {
|
|
360
360
|
"type": "replace",
|
|
361
|
-
"value": "
|
|
361
|
+
"value": ""
|
|
362
362
|
},
|
|
363
363
|
"2": {
|
|
364
364
|
"type": "replace",
|
|
@@ -370,7 +370,7 @@
|
|
|
370
370
|
{
|
|
371
371
|
"0": {
|
|
372
372
|
"type": "replace",
|
|
373
|
-
"value": "
|
|
373
|
+
"value": ""
|
|
374
374
|
},
|
|
375
375
|
"2": {
|
|
376
376
|
"type": "replace",
|
|
@@ -382,7 +382,7 @@
|
|
|
382
382
|
{
|
|
383
383
|
"0": {
|
|
384
384
|
"type": "replace",
|
|
385
|
-
"value": "
|
|
385
|
+
"value": ""
|
|
386
386
|
},
|
|
387
387
|
"2": {
|
|
388
388
|
"type": "replace",
|
|
@@ -394,21 +394,21 @@
|
|
|
394
394
|
{
|
|
395
395
|
"0": {
|
|
396
396
|
"type": "replace",
|
|
397
|
-
"value": "
|
|
397
|
+
"value": ""
|
|
398
398
|
},
|
|
399
399
|
"2": {
|
|
400
400
|
"type": "replace",
|
|
401
|
-
"value": "
|
|
401
|
+
"value": "еві"
|
|
402
402
|
}
|
|
403
403
|
},
|
|
404
404
|
{
|
|
405
405
|
"0": {
|
|
406
406
|
"type": "replace",
|
|
407
|
-
"value": "
|
|
407
|
+
"value": ""
|
|
408
408
|
},
|
|
409
409
|
"2": {
|
|
410
410
|
"type": "replace",
|
|
411
|
-
"value": "
|
|
411
|
+
"value": "ю"
|
|
412
412
|
}
|
|
413
413
|
}
|
|
414
414
|
],
|
|
@@ -416,7 +416,7 @@
|
|
|
416
416
|
{
|
|
417
417
|
"0": {
|
|
418
418
|
"type": "replace",
|
|
419
|
-
"value": "
|
|
419
|
+
"value": ""
|
|
420
420
|
},
|
|
421
421
|
"2": {
|
|
422
422
|
"type": "replace",
|
|
@@ -427,9 +427,10 @@
|
|
|
427
427
|
}
|
|
428
428
|
},
|
|
429
429
|
{
|
|
430
|
-
"description": "друга відміна / чоловічий рід / м'яка група / на -(голосна)
|
|
430
|
+
"description": "друга відміна / чоловічий рід / м'яка група / на -(голосна)лець",
|
|
431
431
|
"examples": [
|
|
432
|
-
"
|
|
432
|
+
"стрілець",
|
|
433
|
+
"білець"
|
|
433
434
|
],
|
|
434
435
|
"partOfSpeech": "noun",
|
|
435
436
|
"gender": [
|
|
@@ -438,7 +439,7 @@
|
|
|
438
439
|
"priority": 6,
|
|
439
440
|
"usage": [],
|
|
440
441
|
"pattern": {
|
|
441
|
-
"find": "(а|е|є|и|і|ї|о|у|ю|я)
|
|
442
|
+
"find": "(а|е|є|и|і|ї|о|у|ю|я)лець$",
|
|
442
443
|
"modify": "(.{1})(.{1})(.{1})$"
|
|
443
444
|
},
|
|
444
445
|
"grammaticalCases": {
|
|
@@ -447,7 +448,7 @@
|
|
|
447
448
|
{
|
|
448
449
|
"0": {
|
|
449
450
|
"type": "replace",
|
|
450
|
-
"value": ""
|
|
451
|
+
"value": "ь"
|
|
451
452
|
},
|
|
452
453
|
"2": {
|
|
453
454
|
"type": "replace",
|
|
@@ -459,7 +460,7 @@
|
|
|
459
460
|
{
|
|
460
461
|
"0": {
|
|
461
462
|
"type": "replace",
|
|
462
|
-
"value": ""
|
|
463
|
+
"value": "ь"
|
|
463
464
|
},
|
|
464
465
|
"2": {
|
|
465
466
|
"type": "replace",
|
|
@@ -469,7 +470,7 @@
|
|
|
469
470
|
{
|
|
470
471
|
"0": {
|
|
471
472
|
"type": "replace",
|
|
472
|
-
"value": ""
|
|
473
|
+
"value": "ь"
|
|
473
474
|
},
|
|
474
475
|
"2": {
|
|
475
476
|
"type": "replace",
|
|
@@ -481,7 +482,7 @@
|
|
|
481
482
|
{
|
|
482
483
|
"0": {
|
|
483
484
|
"type": "replace",
|
|
484
|
-
"value": ""
|
|
485
|
+
"value": "ь"
|
|
485
486
|
},
|
|
486
487
|
"2": {
|
|
487
488
|
"type": "replace",
|
|
@@ -493,7 +494,7 @@
|
|
|
493
494
|
{
|
|
494
495
|
"0": {
|
|
495
496
|
"type": "replace",
|
|
496
|
-
"value": ""
|
|
497
|
+
"value": "ь"
|
|
497
498
|
},
|
|
498
499
|
"2": {
|
|
499
500
|
"type": "replace",
|
|
@@ -505,21 +506,21 @@
|
|
|
505
506
|
{
|
|
506
507
|
"0": {
|
|
507
508
|
"type": "replace",
|
|
508
|
-
"value": ""
|
|
509
|
+
"value": "ь"
|
|
509
510
|
},
|
|
510
511
|
"2": {
|
|
511
512
|
"type": "replace",
|
|
512
|
-
"value": "
|
|
513
|
+
"value": "ю"
|
|
513
514
|
}
|
|
514
515
|
},
|
|
515
516
|
{
|
|
516
517
|
"0": {
|
|
517
518
|
"type": "replace",
|
|
518
|
-
"value": ""
|
|
519
|
+
"value": "ь"
|
|
519
520
|
},
|
|
520
521
|
"2": {
|
|
521
522
|
"type": "replace",
|
|
522
|
-
"value": "
|
|
523
|
+
"value": "еві"
|
|
523
524
|
}
|
|
524
525
|
}
|
|
525
526
|
],
|
|
@@ -527,7 +528,7 @@
|
|
|
527
528
|
{
|
|
528
529
|
"0": {
|
|
529
530
|
"type": "replace",
|
|
530
|
-
"value": ""
|
|
531
|
+
"value": "ь"
|
|
531
532
|
},
|
|
532
533
|
"2": {
|
|
533
534
|
"type": "replace",
|
package/src/shevchenko.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { Anthroponym, Gender, GrammaticalCase, validateAnthroponym } from './core';
|
|
2
1
|
import { anthroponymInflector } from './bootstrap';
|
|
2
|
+
import { Anthroponym, GrammaticalCase, validateAnthroponym } from './core';
|
|
3
|
+
|
|
4
|
+
export { Anthroponym, Gender } from './core';
|
|
5
|
+
export { detectGender, GenderlessAnthroponym } from './gender-detection';
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* Inflects the anthroponym in nominative grammatical case.
|
|
@@ -57,7 +60,5 @@ export function inVocative(anthroponym: Anthroponym): Anthroponym {
|
|
|
57
60
|
return anthroponymInflector.inflect(anthroponym, GrammaticalCase.Vocative);
|
|
58
61
|
}
|
|
59
62
|
|
|
60
|
-
export { Anthroponym, Gender };
|
|
61
|
-
|
|
62
63
|
// Not a part of public API.
|
|
63
64
|
export * as Internal from './internal';
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Returns destination string after modification.
|
|
4
4
|
*/
|
|
5
5
|
export function copyLetterCase(src: string, dest: string): string {
|
|
6
|
-
let result
|
|
6
|
+
let result = '';
|
|
7
7
|
|
|
8
8
|
const srcLetterCases: string[] = [];
|
|
9
9
|
const srcChars = src.split('');
|
|
@@ -37,13 +37,13 @@ export function copyLetterCase(src: string, dest: string): string {
|
|
|
37
37
|
/**
|
|
38
38
|
* Detects if a character is in the upper case at the specified index.
|
|
39
39
|
*/
|
|
40
|
-
export function isUpperCase(src: string, pos
|
|
40
|
+
export function isUpperCase(src: string, pos = 0): boolean {
|
|
41
41
|
return src.charAt(pos) === src.charAt(pos).toUpperCase();
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* Detects if a character is in the lower case at the specified index.
|
|
46
46
|
*/
|
|
47
|
-
export function isLowerCase(src: string, pos
|
|
47
|
+
export function isLowerCase(src: string, pos = 0): boolean {
|
|
48
48
|
return src.charAt(pos) === src.charAt(pos).toLowerCase();
|
|
49
49
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
+
const samples = require('./samples.json');
|
|
3
|
+
|
|
4
|
+
module.exports = (shevchenko) => {
|
|
5
|
+
samples.forEach((sample) => {
|
|
6
|
+
const anthroponym = { gender: sample.gender, ...sample.grammaticalCases.nominative };
|
|
7
|
+
describe(`"${anthroponym.firstName} ${anthroponym.middleName} ${anthroponym.lastName}" inflection`, () => {
|
|
8
|
+
it(`should inflect in nominative grammatical case`, () => {
|
|
9
|
+
const result = shevchenko.inNominative(anthroponym);
|
|
10
|
+
expect(result.firstName).toStrictEqual(sample.grammaticalCases.nominative.firstName);
|
|
11
|
+
expect(result.middleName).toStrictEqual(sample.grammaticalCases.nominative.middleName);
|
|
12
|
+
expect(result.lastName).toStrictEqual(sample.grammaticalCases.nominative.lastName);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it(`should inflect in genitive grammatical case`, () => {
|
|
16
|
+
const result = shevchenko.inGenitive(anthroponym);
|
|
17
|
+
expect(result.firstName).toStrictEqual(sample.grammaticalCases.genitive.firstName);
|
|
18
|
+
expect(result.middleName).toStrictEqual(sample.grammaticalCases.genitive.middleName);
|
|
19
|
+
expect(result.lastName).toStrictEqual(sample.grammaticalCases.genitive.lastName);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it(`should inflect in dative grammatical case`, () => {
|
|
23
|
+
const result = shevchenko.inDative(anthroponym);
|
|
24
|
+
expect(result.firstName).toStrictEqual(sample.grammaticalCases.dative.firstName);
|
|
25
|
+
expect(result.middleName).toStrictEqual(sample.grammaticalCases.dative.middleName);
|
|
26
|
+
expect(result.lastName).toStrictEqual(sample.grammaticalCases.dative.lastName);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it(`should inflect in accusative grammatical case`, () => {
|
|
30
|
+
const result = shevchenko.inAccusative(anthroponym);
|
|
31
|
+
expect(result.firstName).toStrictEqual(sample.grammaticalCases.accusative.firstName);
|
|
32
|
+
expect(result.middleName).toStrictEqual(sample.grammaticalCases.accusative.middleName);
|
|
33
|
+
expect(result.lastName).toStrictEqual(sample.grammaticalCases.accusative.lastName);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it(`should inflect in ablative grammatical case`, () => {
|
|
37
|
+
const result = shevchenko.inAblative(anthroponym);
|
|
38
|
+
expect(result.firstName).toStrictEqual(sample.grammaticalCases.ablative.firstName);
|
|
39
|
+
expect(result.middleName).toStrictEqual(sample.grammaticalCases.ablative.middleName);
|
|
40
|
+
expect(result.lastName).toStrictEqual(sample.grammaticalCases.ablative.lastName);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it(`should inflect in locative grammatical case`, () => {
|
|
44
|
+
const result = shevchenko.inLocative(anthroponym);
|
|
45
|
+
expect(result.firstName).toStrictEqual(sample.grammaticalCases.locative.firstName);
|
|
46
|
+
expect(result.middleName).toStrictEqual(sample.grammaticalCases.locative.middleName);
|
|
47
|
+
expect(result.lastName).toStrictEqual(sample.grammaticalCases.locative.lastName);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it(`should inflect in vocative grammatical case`, () => {
|
|
51
|
+
const result = shevchenko.inVocative(anthroponym);
|
|
52
|
+
expect(result.firstName).toStrictEqual(sample.grammaticalCases.vocative.firstName);
|
|
53
|
+
expect(result.middleName).toStrictEqual(sample.grammaticalCases.vocative.middleName);
|
|
54
|
+
expect(result.lastName).toStrictEqual(sample.grammaticalCases.vocative.lastName);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module.exports = (shevchenko) => {
|
|
2
|
+
describe(`gender detection`, () => {
|
|
3
|
+
it('should return the grammatical gender', () => {
|
|
4
|
+
expect(shevchenko.detectGender({ firstName: 'Тарас' })).toBe(shevchenko.Gender.Male);
|
|
5
|
+
expect(shevchenko.detectGender({ middleName: 'Григорович' })).toBe(shevchenko.Gender.Male);
|
|
6
|
+
expect(shevchenko.detectGender({ firstName: 'Тарас', middleName: 'Григорович' })).toBe(
|
|
7
|
+
shevchenko.Gender.Male,
|
|
8
|
+
);
|
|
9
|
+
expect(shevchenko.detectGender({ firstName: 'Лариса', middleName: 'Григорович' })).toBe(
|
|
10
|
+
shevchenko.Gender.Male,
|
|
11
|
+
);
|
|
12
|
+
expect(shevchenko.detectGender({ firstName: 'Лариса' })).toBe(shevchenko.Gender.Female);
|
|
13
|
+
expect(shevchenko.detectGender({ middleName: 'Петрівна' })).toBe(shevchenko.Gender.Female);
|
|
14
|
+
expect(shevchenko.detectGender({ firstName: 'Лариса', middleName: 'Петрівна' })).toBe(
|
|
15
|
+
shevchenko.Gender.Female,
|
|
16
|
+
);
|
|
17
|
+
expect(shevchenko.detectGender({ firstName: 'Тарас', middleName: 'Петрівна' })).toBe(
|
|
18
|
+
shevchenko.Gender.Female,
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should return null if the grammatical gender cannot be detected', () => {
|
|
23
|
+
expect(shevchenko.detectGender({ lastName: 'Шевченко' })).toBe(null);
|
|
24
|
+
expect(shevchenko.detectGender({ lastName: 'Косач' })).toBe(null);
|
|
25
|
+
expect(shevchenko.detectGender({ firstName: 'Тара' })).toBe(null);
|
|
26
|
+
expect(shevchenko.detectGender({ firstName: 'Лара' })).toBe(null);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
};
|