Skip to content

Commit f55bade

Browse files
feat(wink-nlp): improve error handling of mark in learnCustomEntities
- earlier array was not being type checked
1 parent 91444ad commit f55bade

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/wink-nlp.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,14 @@ var nlp = function ( theModel, pipe ) {
352352
// Pattern is not an array.
353353
throw Error( `wink-nlp: patterns should be an array, instead found "${typeof ex.patterns}":\n\n${JSON.stringify( ex, null, 2 )}` );
354354
}
355+
// If mark is present then it should be an array of integers **and** its length must
356+
// be equal to 2 **and** start index <= end index.
357+
if ( ( ex.mark !== undefined ) &&
358+
( !helper.isIntegerArray( ex.mark ) ||
359+
( ex.mark.length !== 2 ) ||
360+
( ex.mark.length === 2 && ex.mark[ 0 ] > ex.mark[ 1 ] ) ) ) {
361+
throw Error( `wink-nlp: mark should be an array containing start & end indexes, instead found:\n\n${JSON.stringify( ex.mark, null, 2 )}` );
362+
}
355363
} else {
356364
// Example is not an object.
357365
throw Error( `wink-nlp: each example should be an object, instead found a "${typeof ex}":\n\n${JSON.stringify( ex, null, 2 )}` );

0 commit comments

Comments
 (0)