shevchenko 2.1.0 → 2.1.2
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 +121 -32
- package/dist/cjs/shevchenko.js.map +1 -1
- package/dist/es/shevchenko.js +121 -32
- package/dist/es/shevchenko.js.map +1 -1
- package/dist/umd/shevchenko.min.js +3 -3
- package/dist/umd/shevchenko.min.js.map +1 -1
- package/nuxt/.eslintrc.json +27 -0
- package/nuxt/.prettierrc.json +6 -0
- package/nuxt/README.md +27 -0
- package/nuxt/app.config.ts +3 -0
- package/nuxt/app.vue +5 -0
- package/nuxt/assets/img/shevchenko_pixelized_304x304.jpg +0 -0
- package/nuxt/assets/img/shevchenko_pixelized_304x304.png +0 -0
- package/nuxt/assets/img/shevchenko_pixelized_608x608.jpg +0 -0
- package/nuxt/assets/style/main.scss +3 -0
- package/nuxt/components/about-modal.vue +58 -0
- package/nuxt/components/api-spec.vue +25 -0
- package/nuxt/components/contact-me-button.vue +11 -0
- package/nuxt/components/contact-me-modal.vue +63 -0
- package/nuxt/components/copy-button.vue +38 -0
- package/nuxt/components/declension-demo.vue +32 -0
- package/nuxt/components/declension-form.vue +91 -0
- package/nuxt/components/declension-preview.vue +170 -0
- package/nuxt/components/declension-results.vue +116 -0
- package/nuxt/components/error-404.vue +15 -0
- package/nuxt/components/github-issue-count.vue +18 -0
- package/nuxt/components/how-it-works.vue +51 -0
- package/nuxt/components/installation-instructions.vue +33 -0
- package/nuxt/components/library-docs.vue +27 -0
- package/nuxt/components/page-copyright.vue +15 -0
- package/nuxt/components/page-footer.vue +32 -0
- package/nuxt/components/page-header.vue +4 -0
- package/nuxt/components/preview-banner.vue +32 -0
- package/nuxt/components/share-links.vue +108 -0
- package/nuxt/components/top-nav-bar.vue +165 -0
- package/nuxt/components/ukrainian-flag.vue +37 -0
- package/nuxt/components/usage-example.vue +32 -0
- package/nuxt/composables/declension.ts +81 -0
- package/nuxt/composables/page-i18n.ts +11 -0
- package/nuxt/composables/page-meta.ts +5 -0
- package/nuxt/composables/route-utils.ts +17 -0
- package/nuxt/config.ts +20 -0
- package/nuxt/error.vue +25 -0
- package/nuxt/layouts/default.vue +5 -0
- package/nuxt/locales/en-US.json +60 -0
- package/nuxt/locales/uk-UA.json +62 -0
- package/nuxt/nuxt.config.ts +99 -0
- package/nuxt/package-lock.json +19524 -0
- package/nuxt/package.json +37 -0
- package/nuxt/pages/en-US/index.vue +41 -0
- package/nuxt/pages/index.vue +68 -0
- package/nuxt/plugins/i18n.ts +26 -0
- package/nuxt/public/.nojekyll +0 -0
- package/nuxt/public/CNAME +1 -0
- package/nuxt/public/android-icon-144x144.png +0 -0
- package/nuxt/public/android-icon-192x192.png +0 -0
- package/nuxt/public/android-icon-36x36.png +0 -0
- package/nuxt/public/android-icon-48x48.png +0 -0
- package/nuxt/public/android-icon-72x72.png +0 -0
- package/nuxt/public/android-icon-96x96.png +0 -0
- package/nuxt/public/apple-icon-114x114.png +0 -0
- package/nuxt/public/apple-icon-120x120.png +0 -0
- package/nuxt/public/apple-icon-144x144.png +0 -0
- package/nuxt/public/apple-icon-152x152.png +0 -0
- package/nuxt/public/apple-icon-180x180.png +0 -0
- package/nuxt/public/apple-icon-57x57.png +0 -0
- package/nuxt/public/apple-icon-60x60.png +0 -0
- package/nuxt/public/apple-icon-72x72.png +0 -0
- package/nuxt/public/apple-icon-76x76.png +0 -0
- package/nuxt/public/apple-icon-precomposed.png +0 -0
- package/nuxt/public/apple-icon.png +0 -0
- package/nuxt/public/browserconfig.xml +2 -0
- package/nuxt/public/favicon-16x16.png +0 -0
- package/nuxt/public/favicon-32x32.png +0 -0
- package/nuxt/public/favicon-96x96.png +0 -0
- package/nuxt/public/favicon.ico +0 -0
- package/nuxt/public/manifest.json +41 -0
- package/nuxt/public/ms-icon-144x144.png +0 -0
- package/nuxt/public/ms-icon-150x150.png +0 -0
- package/nuxt/public/ms-icon-310x310.png +0 -0
- package/nuxt/public/ms-icon-70x70.png +0 -0
- package/nuxt/public/preview-608x608.jpg +0 -0
- package/nuxt/scripts/postgenerate.js +7 -0
- package/nuxt/scripts/publish.js +7 -0
- package/nuxt/server/plugins/google-tag-manager.js +37 -0
- package/nuxt/tsconfig.json +11 -0
- package/package.json +3 -2
- 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 +7202 -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,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"private": true,
|
|
3
|
+
"scripts": {
|
|
4
|
+
"build": "nuxt build",
|
|
5
|
+
"dev": "nuxt dev",
|
|
6
|
+
"generate": "nuxt generate",
|
|
7
|
+
"postgenerate": "node ./scripts/postgenerate.js",
|
|
8
|
+
"publish": "node ./scripts/publish.js",
|
|
9
|
+
"serve": "serve .output/public",
|
|
10
|
+
"preview": "nuxt preview",
|
|
11
|
+
"postinstall": "nuxt prepare",
|
|
12
|
+
"lint": "eslint --fix \"**/*.{ts,vue}\""
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@nuxtjs/eslint-config-typescript": "^11.0.0",
|
|
16
|
+
"@typescript-eslint/eslint-plugin": "^5.42.0",
|
|
17
|
+
"@typescript-eslint/parser": "^5.42.0",
|
|
18
|
+
"@vue/eslint-config-typescript": "^11.0.2",
|
|
19
|
+
"@vueuse/core": "^9.4.0",
|
|
20
|
+
"@vueuse/nuxt": "^9.4.0",
|
|
21
|
+
"eslint": "^8.26.0",
|
|
22
|
+
"eslint-config-prettier": "^8.5.0",
|
|
23
|
+
"eslint-config-xo": "^0.42.0",
|
|
24
|
+
"eslint-config-xo-typescript": "^0.53.0",
|
|
25
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
26
|
+
"eslint-plugin-unicorn": "^43.0.2",
|
|
27
|
+
"eslint-plugin-vue": "^9.7.0",
|
|
28
|
+
"nuxt": "^3.0.0",
|
|
29
|
+
"prettier": "^2.7.1",
|
|
30
|
+
"sass": "^1.56.0",
|
|
31
|
+
"serve": "^14.0.1",
|
|
32
|
+
"shevchenko": "^2.1.1",
|
|
33
|
+
"typescript": "^4.8.4",
|
|
34
|
+
"vue-i18n": "^9.2.2",
|
|
35
|
+
"vue-router": "^4.1.6"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { useI18n } from 'vue-i18n';
|
|
4
|
+
import IndexPage from '~/pages/index.vue';
|
|
5
|
+
import { usePageI18n } from '~/composables/page-i18n';
|
|
6
|
+
import { useRouteUtils } from '~/composables/route-utils';
|
|
7
|
+
import { usePageMeta } from '~/composables/page-meta';
|
|
8
|
+
|
|
9
|
+
function setup(...args) {
|
|
10
|
+
const setupResult = IndexPage.setup.call(this, ...args);
|
|
11
|
+
|
|
12
|
+
definePageMeta({
|
|
13
|
+
alias: ['/en', '/en.html'],
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
usePageI18n({
|
|
17
|
+
locale: 'en-US',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const { t: $t } = useI18n();
|
|
21
|
+
const { buildPageTitle } = usePageMeta();
|
|
22
|
+
|
|
23
|
+
const pageTitle = computed(() => {
|
|
24
|
+
const title = $t('app.name').toString();
|
|
25
|
+
return buildPageTitle(title);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const { buildPageUrl } = useRouteUtils();
|
|
29
|
+
useHead({
|
|
30
|
+
title: pageTitle,
|
|
31
|
+
link: [
|
|
32
|
+
//
|
|
33
|
+
{ rel: 'canonical', href: buildPageUrl('/en-US') },
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return setupResult;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default { ...IndexPage, setup };
|
|
41
|
+
</script>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, onMounted } from 'vue';
|
|
3
|
+
import { useI18n } from 'vue-i18n';
|
|
4
|
+
import { usePageI18n } from '~/composables/page-i18n';
|
|
5
|
+
import { buildPageUrl, useRouteUtils } from '~/composables/route-utils';
|
|
6
|
+
import { usePageMeta } from '~/composables/page-meta';
|
|
7
|
+
import { Anthroponym } from 'shevchenko';
|
|
8
|
+
|
|
9
|
+
usePageI18n({
|
|
10
|
+
locale: 'uk-UA',
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const appConfig = useAppConfig();
|
|
14
|
+
const { t: $t } = useI18n();
|
|
15
|
+
const route = useRoute();
|
|
16
|
+
const { pageUrl } = useRouteUtils();
|
|
17
|
+
const router = useRouter();
|
|
18
|
+
const { buildPageTitle } = usePageMeta();
|
|
19
|
+
|
|
20
|
+
const defaultPageTitle = computed(() => {
|
|
21
|
+
const title = $t('app.name').toString();
|
|
22
|
+
return buildPageTitle(title);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const pageTitle = ref(defaultPageTitle.value);
|
|
26
|
+
|
|
27
|
+
useHead({
|
|
28
|
+
title: pageTitle,
|
|
29
|
+
link: [
|
|
30
|
+
//
|
|
31
|
+
{ rel: 'canonical', href: buildPageUrl('/') },
|
|
32
|
+
],
|
|
33
|
+
meta: [
|
|
34
|
+
{ property: 'og:image', content: buildPageUrl('/preview-608x608.jpg') },
|
|
35
|
+
{ property: 'og:image:width', content: '608' },
|
|
36
|
+
{ property: 'og:image:height', content: '608' },
|
|
37
|
+
{ property: 'og:type', content: 'website' },
|
|
38
|
+
{ property: 'og:url', content: pageUrl },
|
|
39
|
+
{ property: 'og:site_name', content: appConfig.library.name },
|
|
40
|
+
{ property: 'og:title', content: pageTitle },
|
|
41
|
+
{ property: 'og:description', content: pageTitle },
|
|
42
|
+
{ name: 'twitter:image', content: buildPageUrl('/preview-608x608.jpg') },
|
|
43
|
+
{ name: 'twitter:card', content: 'summary' },
|
|
44
|
+
{ name: 'twitter:title', content: pageTitle },
|
|
45
|
+
],
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
async function updatePageTitle(anthroponym: Partial<Anthroponym>): Promise<void> {
|
|
49
|
+
// For some reason, the route query is not updated when all query keys remain the same.
|
|
50
|
+
// The next line of code forcibly resets the route query to fix the bug.
|
|
51
|
+
await router.replace({ query: {} });
|
|
52
|
+
|
|
53
|
+
await router.replace({ query: { ...anthroponym } });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
onMounted(() => updatePageTitle(route.query));
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<template>
|
|
60
|
+
<PageHeader />
|
|
61
|
+
<PreviewBanner />
|
|
62
|
+
<DeclensionDemo :initial-anthroponym="$route.query" @declension="updatePageTitle" />
|
|
63
|
+
<HowItWorks />
|
|
64
|
+
<LibraryDocs />
|
|
65
|
+
<PageFooter />
|
|
66
|
+
<ContactMeModal />
|
|
67
|
+
<AboutModal />
|
|
68
|
+
</template>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createI18n } from 'vue-i18n';
|
|
2
|
+
import enUS from '~/locales/en-US.json';
|
|
3
|
+
import ukUA from '~/locales/uk-UA.json';
|
|
4
|
+
|
|
5
|
+
export type LocaleName = 'en-US' | 'uk-UA';
|
|
6
|
+
type MessageSchema = typeof enUS;
|
|
7
|
+
type MessageDictionary = any;
|
|
8
|
+
|
|
9
|
+
export const defaultLocale: LocaleName = 'uk-UA';
|
|
10
|
+
export const fallbackLocale: LocaleName = 'en-US';
|
|
11
|
+
|
|
12
|
+
export default defineNuxtPlugin(({ vueApp }) => {
|
|
13
|
+
const i18n = createI18n<MessageSchema, LocaleName>({
|
|
14
|
+
legacy: false,
|
|
15
|
+
globalInjection: true,
|
|
16
|
+
messageResolver: (messages: MessageDictionary, path) => {
|
|
17
|
+
const message = messages[path];
|
|
18
|
+
return message != null ? message : null;
|
|
19
|
+
},
|
|
20
|
+
locale: defaultLocale,
|
|
21
|
+
fallbackLocale: fallbackLocale,
|
|
22
|
+
messages: { 'en-US': enUS, 'uk-UA': ukUA },
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
vueApp.use(i18n);
|
|
26
|
+
});
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
shevchenko-js.tooleks.com
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<browserconfig><msapplication><tile><square70x70logo src="/ms-icon-70x70.png"/><square150x150logo src="/ms-icon-150x150.png"/><square310x310logo src="/ms-icon-310x310.png"/><TileColor>#ffffff</TileColor></tile></msapplication></browserconfig>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "shevchenko-js.tooleks.com",
|
|
3
|
+
"icons": [
|
|
4
|
+
{
|
|
5
|
+
"src": "\/android-icon-36x36.png",
|
|
6
|
+
"sizes": "36x36",
|
|
7
|
+
"type": "image\/png",
|
|
8
|
+
"density": "0.75"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"src": "\/android-icon-48x48.png",
|
|
12
|
+
"sizes": "48x48",
|
|
13
|
+
"type": "image\/png",
|
|
14
|
+
"density": "1.0"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"src": "\/android-icon-72x72.png",
|
|
18
|
+
"sizes": "72x72",
|
|
19
|
+
"type": "image\/png",
|
|
20
|
+
"density": "1.5"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"src": "\/android-icon-96x96.png",
|
|
24
|
+
"sizes": "96x96",
|
|
25
|
+
"type": "image\/png",
|
|
26
|
+
"density": "2.0"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"src": "\/android-icon-144x144.png",
|
|
30
|
+
"sizes": "144x144",
|
|
31
|
+
"type": "image\/png",
|
|
32
|
+
"density": "3.0"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"src": "\/android-icon-192x192.png",
|
|
36
|
+
"sizes": "192x192",
|
|
37
|
+
"type": "image\/png",
|
|
38
|
+
"density": "4.0"
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { defineNitroPlugin } from 'nitropack/runtime/plugin';
|
|
2
|
+
|
|
3
|
+
const headCode = `
|
|
4
|
+
<!-- Google Tag Manager -->
|
|
5
|
+
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
|
6
|
+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
|
7
|
+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
|
8
|
+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
|
|
9
|
+
})(window,document,'script','dataLayer','GTM-WGR7576');</script>
|
|
10
|
+
<!-- End Google Tag Manager -->
|
|
11
|
+
<!-- Google tag (gtag.js) -->
|
|
12
|
+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-RZ36XWPBER"></script>
|
|
13
|
+
<script>
|
|
14
|
+
window.dataLayer = window.dataLayer || [];
|
|
15
|
+
function gtag(){dataLayer.push(arguments);}
|
|
16
|
+
gtag('js', new Date());
|
|
17
|
+
|
|
18
|
+
gtag('config', 'G-RZ36XWPBER');
|
|
19
|
+
</script>
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
const bodyCode = `
|
|
23
|
+
<!-- Google Tag Manager (noscript) -->
|
|
24
|
+
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-WGR7576"
|
|
25
|
+
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
|
|
26
|
+
<!-- End Google Tag Manager (noscript) -->
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Injects Google Tag Manager code snippets into head and body HTML elements.
|
|
31
|
+
*/
|
|
32
|
+
export default defineNitroPlugin((nitroApp) => {
|
|
33
|
+
nitroApp.hooks.hook('render:html', (html) => {
|
|
34
|
+
html.head.unshift(headCode.trim());
|
|
35
|
+
html.bodyPrepend.unshift(bodyCode.trim());
|
|
36
|
+
});
|
|
37
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shevchenko",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "JavaScript library for declension of Ukrainian anthroponyms",
|
|
5
5
|
"browser": "./dist/umd/shevchenko.min.js",
|
|
6
6
|
"main": "./dist/cjs/shevchenko.js",
|
|
@@ -64,10 +64,11 @@
|
|
|
64
64
|
"@types/synaptic": "^1.0.3",
|
|
65
65
|
"axios": "^0.21.0",
|
|
66
66
|
"chai": "^4.2.0",
|
|
67
|
-
"ejs": "^3.1.
|
|
67
|
+
"ejs": "^3.1.7",
|
|
68
68
|
"gulp": "^4.0.2",
|
|
69
69
|
"i18n": "^0.13.2",
|
|
70
70
|
"mocha": "^8.2.1",
|
|
71
|
+
"nuxi": "*",
|
|
71
72
|
"rimraf": "^3.0.2",
|
|
72
73
|
"rollup": "^2.34.2",
|
|
73
74
|
"rollup-plugin-terser": "^7.0.2",
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Anthroponym, GrammaticalCase } from '../core';
|
|
2
|
+
import { FirstNameInflector } from './first-name-inflector';
|
|
3
|
+
import { LastNameInflector } from './last-name-inflector';
|
|
4
|
+
import { MiddleNameInflector } from './middle-name-inflector';
|
|
5
|
+
|
|
6
|
+
export class AnthroponymInflector {
|
|
7
|
+
private readonly firstNameInflector: FirstNameInflector;
|
|
8
|
+
private readonly middleNameInflector: MiddleNameInflector;
|
|
9
|
+
private readonly lastNameInflector: LastNameInflector;
|
|
10
|
+
|
|
11
|
+
// tslint:disable-next-line max-line-length
|
|
12
|
+
constructor(firstNameInflector: FirstNameInflector, middleNameInflector: MiddleNameInflector, lastNameInflector: LastNameInflector) {
|
|
13
|
+
this.firstNameInflector = firstNameInflector;
|
|
14
|
+
this.middleNameInflector = middleNameInflector;
|
|
15
|
+
this.lastNameInflector = lastNameInflector;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Inflects the anthroponym in the given grammatical case.
|
|
20
|
+
*/
|
|
21
|
+
inflect(anthroponym: Anthroponym, grammaticalCase: GrammaticalCase): Anthroponym {
|
|
22
|
+
const result: Anthroponym = { gender: anthroponym.gender };
|
|
23
|
+
|
|
24
|
+
if (anthroponym.firstName != null) {
|
|
25
|
+
result.firstName = this.firstNameInflector.inflect(anthroponym.firstName, anthroponym.gender, grammaticalCase);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (anthroponym.middleName != null) {
|
|
29
|
+
result.middleName = this.middleNameInflector.inflect(anthroponym.middleName, anthroponym.gender, grammaticalCase);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (anthroponym.lastName != null) {
|
|
33
|
+
result.lastName = this.lastNameInflector.inflect(anthroponym.lastName, anthroponym.gender, grammaticalCase);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { InflectorCommandRunner } from './inflector-command-runner';
|
|
2
|
+
import { InflectorCommand } from './inflector.types';
|
|
3
|
+
|
|
4
|
+
export class AppendCommandRunner implements InflectorCommandRunner {
|
|
5
|
+
private readonly command: InflectorCommand;
|
|
6
|
+
|
|
7
|
+
constructor(command: InflectorCommand) {
|
|
8
|
+
this.command = command;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Appends the command value to the given value.
|
|
13
|
+
* Returns a new value.
|
|
14
|
+
*/
|
|
15
|
+
exec(value: string): string {
|
|
16
|
+
return value + this.command.value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { InflectorCommand, InflectorCommandType } from './inflector.types';
|
|
2
|
+
import { AppendCommandRunner } from './append-command-runner';
|
|
3
|
+
import { ReplaceCommandRunner } from './replace-command-runner';
|
|
4
|
+
import { InflectorCommandRunner } from './inflector-command-runner';
|
|
5
|
+
|
|
6
|
+
export class CommandRunnerFactory {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new command runner for the given command.
|
|
9
|
+
*/
|
|
10
|
+
make(command: InflectorCommand): InflectorCommandRunner {
|
|
11
|
+
switch (command.type) {
|
|
12
|
+
case InflectorCommandType.Append: {
|
|
13
|
+
return new AppendCommandRunner(command);
|
|
14
|
+
}
|
|
15
|
+
case InflectorCommandType.Replace: {
|
|
16
|
+
return new ReplaceCommandRunner(command);
|
|
17
|
+
}
|
|
18
|
+
default: {
|
|
19
|
+
throw new TypeError('Invalid command type.');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { InflectorRule } from './inflector.types';
|
|
2
|
+
import { Gender, GrammaticalCase } from '../core';
|
|
3
|
+
import { RuleInflector } from './rule-inflector';
|
|
4
|
+
import { NameInflector } from './name-inflector';
|
|
5
|
+
|
|
6
|
+
export class FirstNameInflector extends NameInflector {
|
|
7
|
+
private readonly rules: InflectorRule[];
|
|
8
|
+
|
|
9
|
+
constructor(rules: InflectorRule[]) {
|
|
10
|
+
super();
|
|
11
|
+
this.rules = rules;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @inheritdoc
|
|
16
|
+
*/
|
|
17
|
+
protected inflectWord(word: string, gender: Gender, grammaticalCase: GrammaticalCase): string {
|
|
18
|
+
const [rule] = this.rules
|
|
19
|
+
.filter(rule => rule.gender.includes(gender))
|
|
20
|
+
.filter(rule => rule.usage.length === 0 || rule.usage.includes('firstName'))
|
|
21
|
+
.filter(rule => new RegExp(rule.pattern.find, 'gi').test(word))
|
|
22
|
+
.sort((firstRule, secondRule) => {
|
|
23
|
+
if (firstRule.usage.length === 0) {
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
if (secondRule.usage.length > 0) {
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
if (secondRule.usage.includes('firstName')) {
|
|
30
|
+
return 0;
|
|
31
|
+
}
|
|
32
|
+
return 1;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (!rule) {
|
|
36
|
+
return word;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return new RuleInflector(rule).inflect(word, grammaticalCase);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { AnthroponymInflector } from './anthroponym-inflector';
|
|
2
|
+
export { FirstNameInflector } from './first-name-inflector';
|
|
3
|
+
export { MiddleNameInflector } from './middle-name-inflector';
|
|
4
|
+
export { LastNameInflector } from './last-name-inflector';
|
|
5
|
+
export { InflectorRule } from './inflector.types';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Gender, GrammaticalCase } from '../core';
|
|
2
|
+
import { PartOfSpeech } from '../part-of-speech-recognition';
|
|
3
|
+
|
|
4
|
+
export type InflectorRule = {
|
|
5
|
+
description: string,
|
|
6
|
+
examples: string[],
|
|
7
|
+
partOfSpeech: PartOfSpeech,
|
|
8
|
+
gender: Gender[],
|
|
9
|
+
priority: number,
|
|
10
|
+
usage: string[],
|
|
11
|
+
pattern: InflectorPattern,
|
|
12
|
+
grammaticalCases: GrammaticalCases,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type InflectorPattern = {
|
|
16
|
+
find: string,
|
|
17
|
+
modify: string,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type GrammaticalCases = {
|
|
21
|
+
[GrammaticalCase.Nominative]: InflectorCommandGroup[],
|
|
22
|
+
[GrammaticalCase.Genitive]: InflectorCommandGroup[],
|
|
23
|
+
[GrammaticalCase.Dative]: InflectorCommandGroup[],
|
|
24
|
+
[GrammaticalCase.Accusative]: InflectorCommandGroup[],
|
|
25
|
+
[GrammaticalCase.Ablative]: InflectorCommandGroup[],
|
|
26
|
+
[GrammaticalCase.Locative]: InflectorCommandGroup[],
|
|
27
|
+
[GrammaticalCase.Vocative]: InflectorCommandGroup[],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type InflectorCommandGroup = {
|
|
31
|
+
[groupIndex: string]: InflectorCommand;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type InflectorCommand = {
|
|
35
|
+
type: InflectorCommandType,
|
|
36
|
+
value: string,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export enum InflectorCommandType {
|
|
40
|
+
Replace = 'replace',
|
|
41
|
+
Append = 'append',
|
|
42
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { InflectorRule } from './inflector.types';
|
|
2
|
+
import { Gender, GrammaticalCase } from '../core';
|
|
3
|
+
import { PartOfSpeechRecognizer } from '../part-of-speech-recognition';
|
|
4
|
+
import { countVowels } from '../utils/lang.utils';
|
|
5
|
+
import { NameInflector } from './name-inflector';
|
|
6
|
+
import { RuleInflector } from './rule-inflector';
|
|
7
|
+
|
|
8
|
+
export class LastNameInflector extends NameInflector {
|
|
9
|
+
private readonly rules: InflectorRule[];
|
|
10
|
+
private readonly partOfSpeechRecognizer: PartOfSpeechRecognizer;
|
|
11
|
+
|
|
12
|
+
constructor(rules: InflectorRule[], partOfSpeechRecognizer: PartOfSpeechRecognizer) {
|
|
13
|
+
super();
|
|
14
|
+
this.rules = rules;
|
|
15
|
+
this.partOfSpeechRecognizer = partOfSpeechRecognizer;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @inheritdoc
|
|
20
|
+
*/
|
|
21
|
+
// tslint:disable-next-line max-line-length
|
|
22
|
+
protected inflectWord(word: string, gender: Gender, grammaticalCase: GrammaticalCase, isLastWord: boolean): string {
|
|
23
|
+
if (!isLastWord && countVowels(word) === 1) {
|
|
24
|
+
return word;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const [rule] = this.rules
|
|
28
|
+
.filter(rule => rule.gender.includes(gender))
|
|
29
|
+
.filter(rule => rule.usage.length === 0 || rule.usage.includes('lastName'))
|
|
30
|
+
.filter(rule => new RegExp(rule.pattern.find, 'gi').test(word))
|
|
31
|
+
.filter((rule) => {
|
|
32
|
+
const partOfSpeech = this.partOfSpeechRecognizer.recognize(word, gender);
|
|
33
|
+
return partOfSpeech === rule.partOfSpeech || partOfSpeech === null;
|
|
34
|
+
})
|
|
35
|
+
.sort((firstRule, secondRule) => {
|
|
36
|
+
if (firstRule.usage.length === 0) {
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
if (secondRule.usage.length > 0) {
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
if (secondRule.usage.includes('lastName')) {
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
return 1;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
if (!rule) {
|
|
49
|
+
return word;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return new RuleInflector(rule).inflect(word, grammaticalCase);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { InflectorRule } from './inflector.types';
|
|
2
|
+
import { Gender, GrammaticalCase } from '../core';
|
|
3
|
+
import { RuleInflector } from './rule-inflector';
|
|
4
|
+
import { NameInflector } from './name-inflector';
|
|
5
|
+
|
|
6
|
+
export class MiddleNameInflector extends NameInflector {
|
|
7
|
+
private readonly rules: InflectorRule[];
|
|
8
|
+
|
|
9
|
+
constructor(rules: InflectorRule[]) {
|
|
10
|
+
super();
|
|
11
|
+
this.rules = rules;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @inheritdoc
|
|
16
|
+
*/
|
|
17
|
+
protected inflectWord(word: string, gender: Gender, grammaticalCase: GrammaticalCase): string {
|
|
18
|
+
const [rule] = this.rules
|
|
19
|
+
.filter(rule => rule.gender.includes(gender))
|
|
20
|
+
.filter(rule => rule.usage.includes('middleName'))
|
|
21
|
+
.filter(rule => new RegExp(rule.pattern.find, 'gi').test(word));
|
|
22
|
+
|
|
23
|
+
if (!rule) {
|
|
24
|
+
return word;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return new RuleInflector(rule).inflect(word, grammaticalCase);
|
|
28
|
+
}
|
|
29
|
+
}
|