10BC0 feat(*): improve error handling in contextual vectors · winkjs/wink-nlp@64d1f40 · GitHub
[go: up one dir, main page]

Skip to content

Commit 64d1f40

Browse files
feat(*): improve error handling in contextual vectors
and update typescript defn Co-authored-by: Rachna <rachna@graype.in>
1 parent cb602a5 commit 64d1f40

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/doc-v2.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,14 @@ var doc = function ( docData, addons ) {
459459
// eslint-disable-next-line complexity
460460
contextualVectors = function ( { lemma = true, specificWordVectors = [], similarWordVectors = false, wordVectorsLimit = 0 } = {} ) {
461461
// Error handling!
462+
if ( docData.wordVectors === null )
463+
throw Error( 'wink-nlp: word vectors are not loaded: load them winkNLP\'s instantiation time.' );
462464
if ( !Array.isArray( specificWordVectors ) )
463465
throw Error( `wink-nlp: expecting a valid Javascript array for similarWordVectos, instead found "${typeof specificWordVectors}".`);
464466
if ( !Number.isInteger( wordVectorsLimit ) || wordVectorsLimit >= docData.wordVectors.size )
465467
throw Error( 'wink-nlp: invalid value or type encountered for wordVectorsLimit.' );
468+
if ( lemma && !docData.currPipe.pos )
469+
throw Error( 'wink-nlp: Can\'t create lemma vectors without pos: add a "pos" to NLP pipe.' );
466470
// Initialize contextual vectors.
467471
const cv = Object.create( null );
468472
// Following properties are constants, therefore can be directly copied.

test/contextual-vectors-specs.js

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

types/index.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,13 @@ declare module 'wink-nlp' {
271271
out<T, U>(itsf: ItsFunction<T>, asf: AsFunction<T, U>): U | T[] | string[];
272272
}
273273

274+
export interface Include {
275+
lemma?: boolean;
276+
specificWordVectors?: string[];
277+
similarWordVectors?: boolean;
278+
wordVectorsLimit?: number;
279+
}
280+
274281
export interface Document {
275282
entities(): Entities;
276283
customEntities(): CustomEntities;
@@ -282,7 +289,7 @@ declare module 'wink-nlp' {
282289
tokens(): Tokens;
283290
printTokens(): void;
284291
pipeConfig(): string[];
285-
contextualVectors(lemma: boolean, specifcWordVectors: string[], similarWordVectors: boolean, wordVectorsLimit: number): string;
292+
contextualVectors(include: Include): string;
286293
}
287294

288295
export interface CerExample {
@@ -317,6 +324,7 @@ declare module 'wink-nlp' {
317324
readDoc(text: string): Document;
318325
// returns number of learned entities
319326
learnCustomEntities(examples: CustomEntityExample[], config?: CerConfig): number;
327+
vectorOf(word: string): number[];
320328
its: ItsHelpers;
321329
as: AsHelpers;
322330
}

0 commit comments

Comments
 (0)
0