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
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { PartOfSpeech } from './part-of-speech.enum';
|
|
2
|
+
import { Gender } from '../core';
|
|
3
|
+
import { NeuralNetwork } from './neural-network';
|
|
4
|
+
import { NeuralNetworkTrainingData } from './neural-network-training-data';
|
|
5
|
+
import { WordTransformer } from './word-transformer';
|
|
6
|
+
|
|
7
|
+
export interface PartOfSpeechRecognitionGuard {
|
|
8
|
+
(word: string, gender: Gender): boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class PartOfSpeechRecognitionRule {
|
|
12
|
+
readonly guard: PartOfSpeechRecognitionGuard;
|
|
13
|
+
readonly cache: NeuralNetworkTrainingData;
|
|
14
|
+
private readonly neuralNetwork: NeuralNetwork;
|
|
15
|
+
|
|
16
|
+
constructor(guard: PartOfSpeechRecognitionGuard, neuralNetwork: NeuralNetwork, cache: NeuralNetworkTrainingData) {
|
|
17
|
+
this.guard = guard;
|
|
18
|
+
this.neuralNetwork = neuralNetwork;
|
|
19
|
+
this.cache = cache;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Applies the part of speech recognizer rule to the given word.
|
|
24
|
+
* Returns a part of speech of the given word.
|
|
25
|
+
*/
|
|
26
|
+
apply(word: string): PartOfSpeech {
|
|
27
|
+
const transformedWord = new WordTransformer().transform(word);
|
|
28
|
+
if (this.cache[transformedWord]) {
|
|
29
|
+
return this.cache[transformedWord];
|
|
30
|
+
}
|
|
31
|
+
return this.neuralNetwork.activate(transformedWord);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { PartOfSpeechRecognitionRule } from './part-of-speech-recognition-rule';
|
|
2
|
+
import { Gender } from '../core';
|
|
3
|
+
import { PartOfSpeech } from './part-of-speech.enum';
|
|
4
|
+
import { WordTransformer } from './word-transformer';
|
|
5
|
+
|
|
6
|
+
export class PartOfSpeechRecognizer {
|
|
7
|
+
private readonly rules: PartOfSpeechRecognitionRule[];
|
|
8
|
+
|
|
9
|
+
constructor(rules: PartOfSpeechRecognitionRule[]) {
|
|
10
|
+
this.rules = rules;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Recognizes the part of speech of the given word.
|
|
15
|
+
* Returns part of speech of the given word.
|
|
16
|
+
* Returns null if part of speech was not recognized.
|
|
17
|
+
*/
|
|
18
|
+
recognize(word: string, gender: Gender): PartOfSpeech | null {
|
|
19
|
+
const transformedWord = new WordTransformer().transform(word);
|
|
20
|
+
const rule = this.rules.find(rule => rule.guard(transformedWord, gender));
|
|
21
|
+
if (!rule) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return rule.apply(transformedWord);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { neuralNetworkConfig } from './neural-network-config';
|
|
2
|
+
|
|
3
|
+
export class WordEncoder {
|
|
4
|
+
private readonly size: number;
|
|
5
|
+
|
|
6
|
+
constructor(size: number = neuralNetworkConfig.inputLayerSize) {
|
|
7
|
+
this.size = size;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Encodes a word for use in the neural network.
|
|
12
|
+
*/
|
|
13
|
+
encode(input: string): number[] {
|
|
14
|
+
return input
|
|
15
|
+
.toLowerCase()
|
|
16
|
+
.split('')
|
|
17
|
+
.map(char => char.charCodeAt(0).toString(2))
|
|
18
|
+
.join('')
|
|
19
|
+
.padStart(this.size, '0')
|
|
20
|
+
.split('')
|
|
21
|
+
.map(digit => Number.parseInt(digit, 2));
|
|
22
|
+
}
|
|
23
|
+
}
|