Skip to content

Commit 8511cc4

Browse files
author
Léo Guillaume
committed
feat: add utils
1 parent 0b6ba83 commit 8511cc4

File tree

7 files changed

+147
-3
lines changed

7 files changed

+147
-3
lines changed

src/index.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2222
*/
2323

24-
import { Language } from './language';
25-
import { NlpUtil, NlpManager, NlpExcelReader } from './nlp';
26-
import { XTableUtils, XTable, XDoc } from './xtables';
24+
import { Language } from './language'
25+
import { NlpUtil, NlpManager, NlpExcelReader } from './nlp'
26+
import { XTableUtils, XTable, XDoc } from './xtables'
27+
import { removeEmojis, Evaluator, SpellCheck, Handlebars } from './util'
2728

2829
export {
2930
Language,
@@ -33,4 +34,17 @@ export {
3334
XTableUtils,
3435
XTable,
3536
XDoc,
37+
removeEmojis,
38+
Evaluator,
39+
SpellCheck,
40+
Handlebars,
41+
// ActionManager,
42+
// NlgManager,
43+
// NeuralNetwork,
44+
// SentimentAnalyzer,
45+
// SentimentManager,
46+
// Recognizer,
47+
// ConversationContext,
48+
// MemoryConversationContext,
49+
// BrainNLU,
3650
};

src/types/@nlpjs/emoji.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare module '@nlpjs/emoji' {
2+
function removeEmojis(str: string | null | undefined): string | null | undefined;
3+
4+
export { removeEmojis };
5+
}

src/types/@nlpjs/evaluator.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
declare module '@nlpjs/evaluator' {
22
export class Evaluator {}
33
export class Template {}
4+
5+
export function compile(str: string): string
46
}

src/types/@nlpjs/similarity.d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
declare module '@nlpjs/similarity' {
2+
interface SimilarityResult {
3+
distance: number;
4+
text1: string;
5+
text2: string;
6+
}
7+
8+
interface Similarity {
9+
getDistance(text1: string, text2: string): Promise<SimilarityResult>;
10+
}
11+
12+
interface SpellCheckSettings {
13+
features?: Similarity[];
14+
}
15+
16+
class SpellCheck {
17+
constructor(settings?: SpellCheckSettings);
18+
}
19+
20+
export { SpellCheck, Similarity, SimilarityResult, SpellCheckSettings };
21+
}

src/util/handlebars.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 { compile } from '@nlpjs/evaluator'
25+
26+
class Handlebars {
27+
static compile(str: string) {
28+
return compile(str);
29+
}
30+
}
31+
32+
export {
33+
Handlebars,
34+
};

src/util/index.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 { removeEmojis } from '@nlpjs/emoji'
25+
import { Evaluator } from '@nlpjs/evaluator'
26+
import { SpellCheck } from './spell-check'
27+
import { Handlebars } from './handlebars'
28+
29+
export {
30+
removeEmojis,
31+
Evaluator,
32+
SpellCheck,
33+
Handlebars,
34+
};

src/util/spell-check.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 { SpellCheck as SpellCheckBase, SpellCheckSettings } from '@nlpjs/similarity';
25+
26+
class SpellCheck extends SpellCheckBase {
27+
constructor(settings: SpellCheckSettings = {}) {
28+
const features = Array.isArray(settings) ? settings : settings.features;
29+
super({ features });
30+
}
31+
}
32+
33+
export { SpellCheck };
34+

0 commit comments

Comments
 (0)