shevchenko 2.1.0 → 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/dist/cjs/shevchenko.js +1 -1
- package/dist/es/shevchenko.js +1 -1
- package/dist/umd/shevchenko.min.js +1 -1
- package/package.json +1 -1
- 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
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Anthroponym, Gender, GrammaticalCase, validateAnthroponym } from './core';
|
|
2
|
+
import { anthroponymInflector } from './bootstrap';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Inflects the anthroponym in nominative grammatical case.
|
|
6
|
+
*/
|
|
7
|
+
export function inNominative(anthroponym: Anthroponym): Anthroponym {
|
|
8
|
+
validateAnthroponym(anthroponym);
|
|
9
|
+
return anthroponymInflector.inflect(anthroponym, GrammaticalCase.Nominative);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Inflects the anthroponym in genitive grammatical case.
|
|
14
|
+
*/
|
|
15
|
+
export function inGenitive(anthroponym: Anthroponym): Anthroponym {
|
|
16
|
+
validateAnthroponym(anthroponym);
|
|
17
|
+
return anthroponymInflector.inflect(anthroponym, GrammaticalCase.Genitive);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Inflects the anthroponym in dative grammatical case.
|
|
22
|
+
*/
|
|
23
|
+
export function inDative(anthroponym: Anthroponym): Anthroponym {
|
|
24
|
+
validateAnthroponym(anthroponym);
|
|
25
|
+
return anthroponymInflector.inflect(anthroponym, GrammaticalCase.Dative);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Inflects the anthroponym in accusative grammatical case.
|
|
30
|
+
*/
|
|
31
|
+
export function inAccusative(anthroponym: Anthroponym): Anthroponym {
|
|
32
|
+
validateAnthroponym(anthroponym);
|
|
33
|
+
return anthroponymInflector.inflect(anthroponym, GrammaticalCase.Accusative);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Inflects the anthroponym in ablative grammatical case.
|
|
38
|
+
*/
|
|
39
|
+
export function inAblative(anthroponym: Anthroponym): Anthroponym {
|
|
40
|
+
validateAnthroponym(anthroponym);
|
|
41
|
+
return anthroponymInflector.inflect(anthroponym, GrammaticalCase.Ablative);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Inflects the anthroponym in locative grammatical case.
|
|
46
|
+
*/
|
|
47
|
+
export function inLocative(anthroponym: Anthroponym): Anthroponym {
|
|
48
|
+
validateAnthroponym(anthroponym);
|
|
49
|
+
return anthroponymInflector.inflect(anthroponym, GrammaticalCase.Locative);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Inflects the anthroponym in vocative grammatical case.
|
|
54
|
+
*/
|
|
55
|
+
export function inVocative(anthroponym: Anthroponym): Anthroponym {
|
|
56
|
+
validateAnthroponym(anthroponym);
|
|
57
|
+
return anthroponymInflector.inflect(anthroponym, GrammaticalCase.Vocative);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { Anthroponym, Gender };
|
|
61
|
+
|
|
62
|
+
// Not a part of public API.
|
|
63
|
+
export * as Internal from './internal';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const PATTERN_VOWELS = /[аоуеиіяюєї]/gi;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Counts vowel sounds in the given word.
|
|
5
|
+
* Returns a number of vowels.
|
|
6
|
+
*/
|
|
7
|
+
export function countVowels(word: string): number {
|
|
8
|
+
const matches = word.match(PATTERN_VOWELS);
|
|
9
|
+
if (matches == null) {
|
|
10
|
+
return 0;
|
|
11
|
+
}
|
|
12
|
+
return matches.length;
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Counts a number of groups in the given regular expression.
|
|
3
|
+
*/
|
|
4
|
+
export function countGroups(src: RegExp | string): number {
|
|
5
|
+
const pattern = new RegExp(`${src.toString()}|`);
|
|
6
|
+
const matches = pattern.exec('');
|
|
7
|
+
if (matches == null) {
|
|
8
|
+
return 0;
|
|
9
|
+
}
|
|
10
|
+
return matches.length - 1;
|
|
11
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copies letter cases from source to destination string.
|
|
3
|
+
* Returns destination string after modification.
|
|
4
|
+
*/
|
|
5
|
+
export function copyLetterCase(src: string, dest: string): string {
|
|
6
|
+
let result: string = '';
|
|
7
|
+
|
|
8
|
+
const srcLetterCases: string[] = [];
|
|
9
|
+
const srcChars = src.split('');
|
|
10
|
+
for (let pos = 0; pos < srcChars.length; pos += 1) {
|
|
11
|
+
const srcChar = srcChars[pos];
|
|
12
|
+
if (isLowerCase(srcChar)) {
|
|
13
|
+
srcLetterCases.push('lowercase');
|
|
14
|
+
} else if (isUpperCase(srcChar)) {
|
|
15
|
+
srcLetterCases.push('uppercase');
|
|
16
|
+
} else {
|
|
17
|
+
srcLetterCases.push('special');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const destChars = dest.split('');
|
|
22
|
+
for (let pos = 0; pos < destChars.length; pos += 1) {
|
|
23
|
+
const destChar = destChars[pos];
|
|
24
|
+
const srcLetterCase = srcLetterCases[pos] || srcLetterCases[srcLetterCases.length - 1];
|
|
25
|
+
if (srcLetterCase === 'lowercase') {
|
|
26
|
+
result += destChar.toLowerCase();
|
|
27
|
+
} else if (srcLetterCase === 'uppercase') {
|
|
28
|
+
result += destChar.toUpperCase();
|
|
29
|
+
} else {
|
|
30
|
+
result += destChar.toString();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Detects if a character is in the upper case at the specified index.
|
|
39
|
+
*/
|
|
40
|
+
export function isUpperCase(src: string, pos: number = 0): boolean {
|
|
41
|
+
return src.charAt(pos) === src.charAt(pos).toUpperCase();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Detects if a character is in the lower case at the specified index.
|
|
46
|
+
*/
|
|
47
|
+
export function isLowerCase(src: string, pos: number = 0): boolean {
|
|
48
|
+
return src.charAt(pos) === src.charAt(pos).toLowerCase();
|
|
49
|
+
}
|