Skip to content

Commit a4b6856

Browse files
author
Léo Guillaume
committed
feat: declaration types core, core-loader, lang-all, language
1 parent e40829e commit a4b6856

File tree

12 files changed

+1682
-34
lines changed

12 files changed

+1682
-34
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea
22
node_modules
33
dist
4+
node-nlp

package-lock.json

Lines changed: 997 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
"typescript": "^5.0.2"
3131
},
3232
"dependencies": {
33-
"node-nlp-typescript": "^0.1.29"
33+
"@nlpjs/core-loader": "^4.26.1",
34+
"@nlpjs/lang-all": "^4.26.1",
35+
"@nlpjs/language": "^4.25.0",
36+
"node-nlp": "^4.26.1",
37+
"node-nlp-typescript": "^0.1.30"
3438
}
3539
}

src/index.ts

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
1-
export class Point {
2-
x = 0
3-
y = 0
4-
move(x: number, y: number){
5-
this.x += x
6-
this.y += y
7-
return this
8-
}
9-
}
1+
/*
2+
* Copyright (c) AXA Group Operations Spain S.A.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
24+
import { Language } from './language';
25+
import { NlpUtil } from './nlp';
26+
27+
export {
28+
Language,
29+
NlpUtil
30+
};

src/language/index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) AXA Group Operations Spain S.A.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
24+
import Language from '@nlpjs/language';
25+
26+
export {
27+
Language,
28+
};

src/nlp/index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) AXA Group Operations Spain S.A.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
24+
import NlpUtil from './nlp-util';
25+
26+
export {
27+
NlpUtil
28+
}

src/nlp/nlp-util.ts

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*
2+
* Copyright (c) AXA Group Operations Spain S.A.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
24+
import {
25+
BaseStemmer,
26+
Tokenizer,
27+
defaultContainer,
28+
containerBootstrap,
29+
} from '@nlpjs/core-loader';
30+
import LangAll from '@nlpjs/lang-all';
31+
32+
interface Cultures {
33+
[key: string]: string;
34+
}
35+
36+
const cultures: Cultures = {
37+
ar: 'ar-ae', // Arabic
38+
bn: 'bn-bd', // Bengali
39+
ca: 'ca-es', // Catalan
40+
cs: 'cs-cz', // Czech
41+
da: 'da-dk', // Danish
42+
el: 'el-gr', // Greek
43+
en: 'en-us', // English
44+
eu: 'eu-es', // Basque
45+
fa: 'fa-ir', // Farsi
46+
ga: 'ga-ie', // Irish
47+
gl: 'gl-es', // Galician
48+
hi: 'hi-in', // Hindi
49+
hy: 'hy-am', // Armenian
50+
ja: 'ja-jp', // Japanese
51+
ko: 'ko-kr', // Korean
52+
pl: 'pl-pl', // Polish
53+
lt: 'lt-lt', // Lithuanian
54+
ne: 'ne-ne', // Nepali
55+
pt: 'pt-br', // Portuguese
56+
sr: 'sr-rs', // Serbian
57+
sv: 'sv-se', // Swedish
58+
ta: 'ta-in', // Tamil
59+
tl: 'tl-ph', // Tagalog
60+
uk: 'uk-ua', // Ukraine
61+
zh: 'zh-cn', // Chinese
62+
id: 'id-id', // Indonesian,
63+
ms: 'id-id', // Malay
64+
};
65+
66+
class NlpUtil {
67+
static tokenizers = {};
68+
69+
static useAutoStemmer = true;
70+
static autoStemmers = {};
71+
72+
static useAlternative = {};
73+
74+
static useNoneFeature = {
75+
bn: false,
76+
el: true,
77+
en: true,
78+
hi: false,
79+
fa: false,
80+
fr: true,
81+
ru: true,
82+
es: true,
83+
gl: true,
84+
it: true,
85+
nl: true,
86+
no: true,
87+
pt: true,
88+
pl: true,
89+
sv: true,
90+
tl: true,
91+
id: true,
92+
ja: false,
93+
ar: false,
94+
hy: false,
95+
eu: true,
96+
ca: true,
97+
cs: true,
98+
da: true,
99+
fi: true,
100+
de: true,
101+
hu: true,
102+
ga: true,
103+
ro: true,
104+
sl: true,
105+
ta: false,
106+
th: false,
107+
tr: true,
108+
zh: false,
109+
};
110+
111+
/**
112+
* Given a locale, get the 2 character one.
113+
* @param {String} locale Locale of the language.
114+
* @returns {String} Locale in 2 character length.
115+
*/
116+
static getTruncatedLocale(locale: string): string | undefined {
117+
return locale ? locale.substring(0, 2).toLowerCase() : undefined;
118+
}
119+
120+
static getStemmer(locale: string): BaseStemmer {
121+
if (!locale) {
122+
return new BaseStemmer();
123+
}
124+
const name = `Stemmer${locale.slice(0, 1).toUpperCase()}${locale.slice(1)}`;
125+
const Stemmer = LangAll[name];
126+
return Stemmer ? new Stemmer() : new BaseStemmer();
127+
}
128+
129+
static getTokenizer(locale: string): Tokenizer {
130+
if (!locale) {
131+
return new Tokenizer();
132+
}
133+
const name = `Tokenizer${locale.slice(0, 1).toUpperCase()}${locale.slice(
134+
1
135+
)}`;
136+
const TokenizerClass = LangAll[name];
137+
return TokenizerClass
138+
? new TokenizerClass(undefined, true)
139+
: new Tokenizer(undefined, true);
140+
}
141+
142+
static getCulture(locale: string): string {
143+
if (!locale) {
144+
return 'en-us';
145+
}
146+
return cultures[locale] || `${locale}-${locale}`;
147+
}
148+
}
149+
150+
containerBootstrap({}, true, defaultContainer);
151+
defaultContainer.use(LangAll.LangAll);
152+
153+
export default NlpUtil;

src/test.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/types/core-loader.d.ts

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright (c) AXA Group Operations Spain S.A.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
24+
25+
declare module '@nlpjs/core-loader' {
26+
import {
27+
Among,
28+
ArrToObj,
29+
BaseStemmer,
30+
Clonable,
31+
Container,
32+
defaultContainer,
33+
Normalizer,
34+
ObjToArr,
35+
Stemmer,
36+
Stopwords,
37+
Tokenizer,
38+
Timer,
39+
logger,
40+
MemoryStorage,
41+
uuid,
42+
Context,
43+
} from '@nlpjs/core';
44+
45+
export const containerBootstrap: (
46+
inputSettings?: string | Record<string, unknown>,
47+
srcMustLoadEnv?: boolean,
48+
container?: Container,
49+
preffix?: string,
50+
pipelines?: any[],
51+
parent?: Container
52+
) => Container;
53+
54+
export function hasUnicode(str: string): boolean;
55+
56+
export function unicodeToArray(str: string): string[];
57+
58+
export function asciiToArray(str: string): string[];
59+
60+
export function stringToArray(str: string): string[];
61+
62+
export function compareWildcars(str: string, pattern: string): boolean;
63+
64+
export function listFiles(dir: string): Promise<string[]>;
65+
66+
export function loadEnv(env: string): void;
67+
68+
export function listFilesAbsolute(dir: string): Promise<string[]>;
69+
70+
export function getAbsolutePath(path: string): string;
71+
72+
export const dock: {
73+
containers: { [name: string]: Container };
74+
getContainer: (name?: string) => Container | undefined;
75+
get(name: string): any;
76+
createContainer(
77+
name: string | object | undefined,
78+
settings?: string | object | undefined,
79+
srcMustLoadEnv?: boolean | undefined,
80+
preffix?: string | undefined,
81+
parent?: Container | undefined,
82+
pipelines?: any
83+
): Promise<Container>;
84+
buildChilds(container: Container): Promise<void>;
85+
terraform(settings: string | object, mustLoadEnv?: boolean): Promise<Container>;
86+
start(settings: string | object, mustLoadEnv?: boolean): Promise<Container>;
87+
};
88+
89+
export {
90+
Among,
91+
ArrToObj,
92+
BaseStemmer,
93+
Clonable,
94+
Container,
95+
defaultContainer,
96+
Normalizer,
97+
ObjToArr,
98+
Stemmer,
99+
Stopwords,
100+
Tokenizer,
101+
Timer,
102+
logger,
103+
MemoryStorage,
104+
uuid,
105+
Context,
106+
};
107+
}

0 commit comments

Comments
 (0)