shevchenko 2.1.3 → 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 +1280 -96
- package/dist/cjs/shevchenko.js.map +1 -1
- package/dist/es/shevchenko.js +1283 -102
- 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/package-lock.json +7 -7
- package/nuxt/package.json +1 -1
- 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/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
|
}
|
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
|
+
};
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
module.exports = (shevchenko) => {
|
|
2
|
+
describe('shevchenko', () => {
|
|
3
|
+
it('should throw an error for empty arguments list', () => {
|
|
4
|
+
expect(() => shevchenko.inNominative()).toThrow(
|
|
5
|
+
TypeError,
|
|
6
|
+
'"anthroponym" must be an object.',
|
|
7
|
+
);
|
|
8
|
+
expect(() => shevchenko.inGenitive()).toThrow(TypeError, '"anthroponym" must be an object.');
|
|
9
|
+
expect(() => shevchenko.inDative()).toThrow(TypeError, '"anthroponym" must be an object.');
|
|
10
|
+
expect(() => shevchenko.inAccusative()).toThrow(
|
|
11
|
+
TypeError,
|
|
12
|
+
'"anthroponym" must be an object.',
|
|
13
|
+
);
|
|
14
|
+
expect(() => shevchenko.inAblative()).toThrow(TypeError, '"anthroponym" must be an object.');
|
|
15
|
+
expect(() => shevchenko.inLocative()).toThrow(TypeError, '"anthroponym" must be an object.');
|
|
16
|
+
expect(() => shevchenko.inVocative()).toThrow(TypeError, '"anthroponym" must be an object.');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should throw an error if unsupported gender provided', () => {
|
|
20
|
+
const anthroponym = {
|
|
21
|
+
gender: 'nonbinary',
|
|
22
|
+
firstName: 'Тарас',
|
|
23
|
+
middleName: 'Григорович',
|
|
24
|
+
lastName: 'Шевченко',
|
|
25
|
+
};
|
|
26
|
+
expect(() => shevchenko.inNominative(anthroponym)).toThrow(
|
|
27
|
+
TypeError,
|
|
28
|
+
'"anthroponym.gender" must be one of the following: "male", "female".',
|
|
29
|
+
);
|
|
30
|
+
expect(() => shevchenko.inGenitive(anthroponym)).toThrow(
|
|
31
|
+
TypeError,
|
|
32
|
+
'"anthroponym.gender" must be one of the following: "male", "female".',
|
|
33
|
+
);
|
|
34
|
+
expect(() => shevchenko.inDative(anthroponym)).toThrow(
|
|
35
|
+
TypeError,
|
|
36
|
+
'"anthroponym.gender" must be one of the following: "male", "female".',
|
|
37
|
+
);
|
|
38
|
+
expect(() => shevchenko.inAccusative(anthroponym)).toThrow(
|
|
39
|
+
TypeError,
|
|
40
|
+
'"anthroponym.gender" must be one of the following: "male", "female".',
|
|
41
|
+
);
|
|
42
|
+
expect(() => shevchenko.inAblative(anthroponym)).toThrow(
|
|
43
|
+
TypeError,
|
|
44
|
+
'"anthroponym.gender" must be one of the following: "male", "female".',
|
|
45
|
+
);
|
|
46
|
+
expect(() => shevchenko.inLocative(anthroponym)).toThrow(
|
|
47
|
+
TypeError,
|
|
48
|
+
'"anthroponym.gender" must be one of the following: "male", "female".',
|
|
49
|
+
);
|
|
50
|
+
expect(() => shevchenko.inVocative(anthroponym)).toThrow(
|
|
51
|
+
TypeError,
|
|
52
|
+
'"anthroponym.gender" must be one of the following: "male", "female".',
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should throw an error if none of the name fields provided', () => {
|
|
57
|
+
const anthroponym = { gender: 'male' };
|
|
58
|
+
expect(() => shevchenko.inNominative(anthroponym)).toThrow(
|
|
59
|
+
TypeError,
|
|
60
|
+
'At least one of the following fields must present: "anthroponym.firstName", "anthroponym.middleName", "anthroponym.lastName".',
|
|
61
|
+
);
|
|
62
|
+
expect(() => shevchenko.inGenitive(anthroponym)).toThrow(
|
|
63
|
+
TypeError,
|
|
64
|
+
'At least one of the following fields must present: "anthroponym.firstName", "anthroponym.middleName", "anthroponym.lastName".',
|
|
65
|
+
);
|
|
66
|
+
expect(() => shevchenko.inDative(anthroponym)).toThrow(
|
|
67
|
+
TypeError,
|
|
68
|
+
'At least one of the following fields must present: "anthroponym.firstName", "anthroponym.middleName", "anthroponym.lastName".',
|
|
69
|
+
);
|
|
70
|
+
expect(() => shevchenko.inAccusative(anthroponym)).toThrow(
|
|
71
|
+
TypeError,
|
|
72
|
+
'At least one of the following fields must present: "anthroponym.firstName", "anthroponym.middleName", "anthroponym.lastName".',
|
|
73
|
+
);
|
|
74
|
+
expect(() => shevchenko.inAblative(anthroponym)).toThrow(
|
|
75
|
+
TypeError,
|
|
76
|
+
'At least one of the following fields must present: "anthroponym.firstName", "anthroponym.middleName", "anthroponym.lastName".',
|
|
77
|
+
);
|
|
78
|
+
expect(() => shevchenko.inLocative(anthroponym)).toThrow(
|
|
79
|
+
TypeError,
|
|
80
|
+
'At least one of the following fields must present: "anthroponym.firstName", "anthroponym.middleName", "anthroponym.lastName".',
|
|
81
|
+
);
|
|
82
|
+
expect(() => shevchenko.inVocative(anthroponym)).toThrow(
|
|
83
|
+
TypeError,
|
|
84
|
+
'At least one of the following fields must present: "anthroponym.firstName", "anthroponym.middleName", "anthroponym.lastName".',
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should throw an error if provided first name is not a string', () => {
|
|
89
|
+
const anthroponym = {
|
|
90
|
+
gender: 'male',
|
|
91
|
+
firstName: null,
|
|
92
|
+
middleName: 'Григорович',
|
|
93
|
+
lastName: 'Шевченко',
|
|
94
|
+
};
|
|
95
|
+
expect(() => shevchenko.inNominative(anthroponym)).toThrow(
|
|
96
|
+
TypeError,
|
|
97
|
+
'"anthroponym.firstName" must be a string.',
|
|
98
|
+
);
|
|
99
|
+
expect(() => shevchenko.inGenitive(anthroponym)).toThrow(
|
|
100
|
+
TypeError,
|
|
101
|
+
'"anthroponym.firstName" must be a string.',
|
|
102
|
+
);
|
|
103
|
+
expect(() => shevchenko.inDative(anthroponym)).toThrow(
|
|
104
|
+
TypeError,
|
|
105
|
+
'"anthroponym.firstName" must be a string.',
|
|
106
|
+
);
|
|
107
|
+
expect(() => shevchenko.inAccusative(anthroponym)).toThrow(
|
|
108
|
+
TypeError,
|
|
109
|
+
'"anthroponym.firstName" must be a string.',
|
|
110
|
+
);
|
|
111
|
+
expect(() => shevchenko.inAblative(anthroponym)).toThrow(
|
|
112
|
+
TypeError,
|
|
113
|
+
'"anthroponym.firstName" must be a string.',
|
|
114
|
+
);
|
|
115
|
+
expect(() => shevchenko.inLocative(anthroponym)).toThrow(
|
|
116
|
+
TypeError,
|
|
117
|
+
'"anthroponym.firstName" must be a string.',
|
|
118
|
+
);
|
|
119
|
+
expect(() => shevchenko.inVocative(anthroponym)).toThrow(
|
|
120
|
+
TypeError,
|
|
121
|
+
'"anthroponym.firstName" must be a string.',
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('should throw an error if provided middle name is not a string', () => {
|
|
126
|
+
const anthroponym = {
|
|
127
|
+
gender: 'male',
|
|
128
|
+
firstName: 'Тарас',
|
|
129
|
+
middleName: null,
|
|
130
|
+
lastName: 'Шевченко',
|
|
131
|
+
};
|
|
132
|
+
expect(() => shevchenko.inNominative(anthroponym)).toThrow(
|
|
133
|
+
TypeError,
|
|
134
|
+
'"anthroponym.middleName" must be a string.',
|
|
135
|
+
);
|
|
136
|
+
expect(() => shevchenko.inGenitive(anthroponym)).toThrow(
|
|
137
|
+
TypeError,
|
|
138
|
+
'"anthroponym.middleName" must be a string.',
|
|
139
|
+
);
|
|
140
|
+
expect(() => shevchenko.inDative(anthroponym)).toThrow(
|
|
141
|
+
TypeError,
|
|
142
|
+
'"anthroponym.middleName" must be a string.',
|
|
143
|
+
);
|
|
144
|
+
expect(() => shevchenko.inAccusative(anthroponym)).toThrow(
|
|
145
|
+
TypeError,
|
|
146
|
+
'"anthroponym.middleName" must be a string.',
|
|
147
|
+
);
|
|
148
|
+
expect(() => shevchenko.inAblative(anthroponym)).toThrow(
|
|
149
|
+
TypeError,
|
|
150
|
+
'"anthroponym.middleName" must be a string.',
|
|
151
|
+
);
|
|
152
|
+
expect(() => shevchenko.inLocative(anthroponym)).toThrow(
|
|
153
|
+
TypeError,
|
|
154
|
+
'"anthroponym.middleName" must be a string.',
|
|
155
|
+
);
|
|
156
|
+
expect(() => shevchenko.inVocative(anthroponym)).toThrow(
|
|
157
|
+
TypeError,
|
|
158
|
+
'"anthroponym.middleName" must be a string.',
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('should throw an error if provided last name is not a string', () => {
|
|
163
|
+
const anthroponym = {
|
|
164
|
+
gender: 'male',
|
|
165
|
+
firstName: 'Тарас',
|
|
166
|
+
middleName: 'Григорович',
|
|
167
|
+
lastName: null,
|
|
168
|
+
};
|
|
169
|
+
expect(() => shevchenko.inNominative(anthroponym)).toThrow(
|
|
170
|
+
TypeError,
|
|
171
|
+
'"anthroponym.lastName" must be a string.',
|
|
172
|
+
);
|
|
173
|
+
expect(() => shevchenko.inGenitive(anthroponym)).toThrow(
|
|
174
|
+
TypeError,
|
|
175
|
+
'"anthroponym.lastName" must be a string.',
|
|
176
|
+
);
|
|
177
|
+
expect(() => shevchenko.inDative(anthroponym)).toThrow(
|
|
178
|
+
TypeError,
|
|
179
|
+
'"anthroponym.lastName" must be a string.',
|
|
180
|
+
);
|
|
181
|
+
expect(() => shevchenko.inAccusative(anthroponym)).toThrow(
|
|
182
|
+
TypeError,
|
|
183
|
+
'"anthroponym.lastName" must be a string.',
|
|
184
|
+
);
|
|
185
|
+
expect(() => shevchenko.inAblative(anthroponym)).toThrow(
|
|
186
|
+
TypeError,
|
|
187
|
+
'"anthroponym.lastName" must be a string.',
|
|
188
|
+
);
|
|
189
|
+
expect(() => shevchenko.inLocative(anthroponym)).toThrow(
|
|
190
|
+
TypeError,
|
|
191
|
+
'"anthroponym.lastName" must be a string.',
|
|
192
|
+
);
|
|
193
|
+
expect(() => shevchenko.inVocative(anthroponym)).toThrow(
|
|
194
|
+
TypeError,
|
|
195
|
+
'"anthroponym.lastName" must be a string.',
|
|
196
|
+
);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('should inflect anthroponym if first name provided', () => {
|
|
200
|
+
const anthroponym = { gender: 'male', firstName: 'Тарас' };
|
|
201
|
+
expect(shevchenko.inNominative(anthroponym)).toStrictEqual({
|
|
202
|
+
gender: 'male',
|
|
203
|
+
firstName: 'Тарас',
|
|
204
|
+
});
|
|
205
|
+
expect(shevchenko.inGenitive(anthroponym)).toStrictEqual({
|
|
206
|
+
gender: 'male',
|
|
207
|
+
firstName: 'Тараса',
|
|
208
|
+
});
|
|
209
|
+
expect(shevchenko.inDative(anthroponym)).toStrictEqual({
|
|
210
|
+
gender: 'male',
|
|
211
|
+
firstName: 'Тарасу',
|
|
212
|
+
});
|
|
213
|
+
expect(shevchenko.inAccusative(anthroponym)).toStrictEqual({
|
|
214
|
+
gender: 'male',
|
|
215
|
+
firstName: 'Тараса',
|
|
216
|
+
});
|
|
217
|
+
expect(shevchenko.inAblative(anthroponym)).toStrictEqual({
|
|
218
|
+
gender: 'male',
|
|
219
|
+
firstName: 'Тарасом',
|
|
220
|
+
});
|
|
221
|
+
expect(shevchenko.inLocative(anthroponym)).toStrictEqual({
|
|
222
|
+
gender: 'male',
|
|
223
|
+
firstName: 'Тарасові',
|
|
224
|
+
});
|
|
225
|
+
expect(shevchenko.inVocative(anthroponym)).toStrictEqual({
|
|
226
|
+
gender: 'male',
|
|
227
|
+
firstName: 'Тарасе',
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('should inflect anthroponym if middle name provided', () => {
|
|
232
|
+
const anthroponym = { gender: 'male', middleName: 'Григорович' };
|
|
233
|
+
expect(shevchenko.inNominative(anthroponym)).toStrictEqual({
|
|
234
|
+
gender: 'male',
|
|
235
|
+
middleName: 'Григорович',
|
|
236
|
+
});
|
|
237
|
+
expect(shevchenko.inGenitive(anthroponym)).toStrictEqual({
|
|
238
|
+
gender: 'male',
|
|
239
|
+
middleName: 'Григоровича',
|
|
240
|
+
});
|
|
241
|
+
expect(shevchenko.inDative(anthroponym)).toStrictEqual({
|
|
242
|
+
gender: 'male',
|
|
243
|
+
middleName: 'Григоровичу',
|
|
244
|
+
});
|
|
245
|
+
expect(shevchenko.inAccusative(anthroponym)).toStrictEqual({
|
|
246
|
+
gender: 'male',
|
|
247
|
+
middleName: 'Григоровича',
|
|
248
|
+
});
|
|
249
|
+
expect(shevchenko.inAblative(anthroponym)).toStrictEqual({
|
|
250
|
+
gender: 'male',
|
|
251
|
+
middleName: 'Григоровичем',
|
|
252
|
+
});
|
|
253
|
+
expect(shevchenko.inLocative(anthroponym)).toStrictEqual({
|
|
254
|
+
gender: 'male',
|
|
255
|
+
middleName: 'Григоровичу',
|
|
256
|
+
});
|
|
257
|
+
expect(shevchenko.inVocative(anthroponym)).toStrictEqual({
|
|
258
|
+
gender: 'male',
|
|
259
|
+
middleName: 'Григоровичу',
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it('should inflect anthroponym if last name provided', () => {
|
|
264
|
+
const anthroponym = { gender: 'male', lastName: 'Шевченко' };
|
|
265
|
+
expect(shevchenko.inNominative(anthroponym)).toStrictEqual({
|
|
266
|
+
gender: 'male',
|
|
267
|
+
lastName: 'Шевченко',
|
|
268
|
+
});
|
|
269
|
+
expect(shevchenko.inGenitive(anthroponym)).toStrictEqual({
|
|
270
|
+
gender: 'male',
|
|
271
|
+
lastName: 'Шевченка',
|
|
272
|
+
});
|
|
273
|
+
expect(shevchenko.inDative(anthroponym)).toStrictEqual({
|
|
274
|
+
gender: 'male',
|
|
275
|
+
lastName: 'Шевченку',
|
|
276
|
+
});
|
|
277
|
+
expect(shevchenko.inAccusative(anthroponym)).toStrictEqual({
|
|
278
|
+
gender: 'male',
|
|
279
|
+
lastName: 'Шевченка',
|
|
280
|
+
});
|
|
281
|
+
expect(shevchenko.inAblative(anthroponym)).toStrictEqual({
|
|
282
|
+
gender: 'male',
|
|
283
|
+
lastName: 'Шевченком',
|
|
284
|
+
});
|
|
285
|
+
expect(shevchenko.inLocative(anthroponym)).toStrictEqual({
|
|
286
|
+
gender: 'male',
|
|
287
|
+
lastName: 'Шевченкові',
|
|
288
|
+
});
|
|
289
|
+
expect(shevchenko.inVocative(anthroponym)).toStrictEqual({
|
|
290
|
+
gender: 'male',
|
|
291
|
+
lastName: 'Шевченку',
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it('should inflect anthroponym if full name provided', () => {
|
|
296
|
+
const anthroponym = {
|
|
297
|
+
gender: 'male',
|
|
298
|
+
firstName: 'Тарас',
|
|
299
|
+
middleName: 'Григорович',
|
|
300
|
+
lastName: 'Шевченко',
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
expect(shevchenko.inNominative(anthroponym)).toStrictEqual({
|
|
304
|
+
gender: 'male',
|
|
305
|
+
firstName: 'Тарас',
|
|
306
|
+
middleName: 'Григорович',
|
|
307
|
+
lastName: 'Шевченко',
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
expect(shevchenko.inGenitive(anthroponym)).toStrictEqual({
|
|
311
|
+
gender: 'male',
|
|
312
|
+
firstName: 'Тараса',
|
|
313
|
+
middleName: 'Григоровича',
|
|
314
|
+
lastName: 'Шевченка',
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
expect(shevchenko.inDative(anthroponym)).toStrictEqual({
|
|
318
|
+
gender: 'male',
|
|
319
|
+
firstName: 'Тарасу',
|
|
320
|
+
middleName: 'Григоровичу',
|
|
321
|
+
lastName: 'Шевченку',
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
expect(shevchenko.inAccusative(anthroponym)).toStrictEqual({
|
|
325
|
+
gender: 'male',
|
|
326
|
+
firstName: 'Тараса',
|
|
327
|
+
middleName: 'Григоровича',
|
|
328
|
+
lastName: 'Шевченка',
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
expect(shevchenko.inAblative(anthroponym)).toStrictEqual({
|
|
332
|
+
gender: 'male',
|
|
333
|
+
firstName: 'Тарасом',
|
|
334
|
+
middleName: 'Григоровичем',
|
|
335
|
+
lastName: 'Шевченком',
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
expect(shevchenko.inLocative(anthroponym)).toStrictEqual({
|
|
339
|
+
gender: 'male',
|
|
340
|
+
firstName: 'Тарасові',
|
|
341
|
+
middleName: 'Григоровичу',
|
|
342
|
+
lastName: 'Шевченкові',
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
expect(shevchenko.inVocative(anthroponym)).toStrictEqual({
|
|
346
|
+
gender: 'male',
|
|
347
|
+
firstName: 'Тарасе',
|
|
348
|
+
middleName: 'Григоровичу',
|
|
349
|
+
lastName: 'Шевченку',
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
+
const shevchenkoCjs = require('../dist/cjs/shevchenko');
|
|
3
|
+
const shevchenkoUmd = require('../dist/umd/shevchenko.min');
|
|
4
|
+
const execAnthroponymInflectionTests = require('./anthroponym-inflection');
|
|
5
|
+
const execGenderDetectionTests = require('./gender-detection');
|
|
6
|
+
const execInputValidationTests = require('./input-validation');
|
|
7
|
+
|
|
8
|
+
describe('CJS (CommonJS)', () => {
|
|
9
|
+
execInputValidationTests(shevchenkoCjs);
|
|
10
|
+
execAnthroponymInflectionTests(shevchenkoCjs);
|
|
11
|
+
execGenderDetectionTests(shevchenkoCjs);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
describe('UMD (Universal Module Definition)', () => {
|
|
15
|
+
execInputValidationTests(shevchenkoUmd);
|
|
16
|
+
execAnthroponymInflectionTests(shevchenkoUmd);
|
|
17
|
+
execGenderDetectionTests(shevchenkoUmd);
|
|
18
|
+
});
|