From 91d7abb4eb2a64f18c07239a8312017dbf2c75d2 Mon Sep 17 00:00:00 2001 From: Aziz-AXG Date: Sat, 15 Jun 2024 22:03:55 +0300 Subject: [PATCH 1/2] Add type definitions for node-nlp --- types/node-nlp/index.d.ts | 63 ++++++++++++++++++++++++++++++++++++ types/node-nlp/tsconfig.json | 13 ++++++++ 2 files changed, 76 insertions(+) create mode 100644 types/node-nlp/index.d.ts create mode 100644 types/node-nlp/tsconfig.json diff --git a/types/node-nlp/index.d.ts b/types/node-nlp/index.d.ts new file mode 100644 index 000000000..12cac5c6f --- /dev/null +++ b/types/node-nlp/index.d.ts @@ -0,0 +1,63 @@ +declare module "node-nlp" { + interface Explanation { + token: string; + stem: string; + weight: number; + } + + interface Classification { + intent: string; + score: number; + } + + interface Answer { + answer: string; + } + + interface Sentiment { + score: number; + numWords: number; + numHits: number; + average: number; + type: string; + locale: string; + vote: string; + } + + interface NluAnswer { + classifications: Classification[]; + } + + interface NlpResult { + locale: string; + utterance: string; + languageGuessed: boolean; + localeIso2: string; + language: string; + explanation: Explanation[]; + classifications: Classification[]; + intent: string; + score: number; + domain: string; + entities: any[]; + sourceEntities: any[]; + answers: Answer[]; + answer: string; + actions: any[]; + sentiment: Sentiment; + nluAnswer?: NluAnswer; + } + + interface NlpManagerOptions { + languages: string[]; + } + + class NlpManager { + constructor(options?: NlpManagerOptions); + + addDocument(locale: string, utterance: string, intent: string): void; + addAnswer(locale: string, intent: string, answer: string): void; + process(locale: string, utterance: string): Promise; + train(): Promise; + } +} \ No newline at end of file diff --git a/types/node-nlp/tsconfig.json b/types/node-nlp/tsconfig.json new file mode 100644 index 000000000..5055e354f --- /dev/null +++ b/types/node-nlp/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "strict": true, + "module": "commonjs", + "target": "es6", + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "skipLibCheck": true, + "baseUrl": "../", + "typeRoots": ["../"] + }, + "include": ["index.d.ts"] +} \ No newline at end of file From 9cbd8ab62c0d2e8149b6dff35995c24f659e1adf Mon Sep 17 00:00:00 2001 From: Aziz-AXG Date: Fri, 21 Jun 2024 16:03:23 +0300 Subject: [PATCH 2/2] Add the type definitions in the correct location --- packages/node-nlp/package.json | 1 + {types/node-nlp => packages/node-nlp/src}/index.d.ts | 0 {types => packages}/node-nlp/tsconfig.json | 10 ++++++---- 3 files changed, 7 insertions(+), 4 deletions(-) rename {types/node-nlp => packages/node-nlp/src}/index.d.ts (100%) rename {types => packages}/node-nlp/tsconfig.json (66%) diff --git a/packages/node-nlp/package.json b/packages/node-nlp/package.json index 006da26b6..6ce989d0d 100644 --- a/packages/node-nlp/package.json +++ b/packages/node-nlp/package.json @@ -21,6 +21,7 @@ ], "license": "MIT", "main": "src/index.js", + "types": "src/index.d.ts", "scripts": { "test": "echo \"Error: run tests from root\" && exit 1" }, diff --git a/types/node-nlp/index.d.ts b/packages/node-nlp/src/index.d.ts similarity index 100% rename from types/node-nlp/index.d.ts rename to packages/node-nlp/src/index.d.ts diff --git a/types/node-nlp/tsconfig.json b/packages/node-nlp/tsconfig.json similarity index 66% rename from types/node-nlp/tsconfig.json rename to packages/node-nlp/tsconfig.json index 5055e354f..8c3413766 100644 --- a/types/node-nlp/tsconfig.json +++ b/packages/node-nlp/tsconfig.json @@ -6,8 +6,10 @@ "noEmit": true, "forceConsistentCasingInFileNames": true, "skipLibCheck": true, - "baseUrl": "../", - "typeRoots": ["../"] + "baseUrl": ".", + "paths": { + "*": ["src/*"] + } }, - "include": ["index.d.ts"] -} \ No newline at end of file + "include": ["src/**/*"] +}