@@ -61,13 +61,13 @@ var tkSize = constants.tkSize;
61
61
*
62
62
* @param {object } theModel language model.
63
63
* @param {string[] } pipe of nlp annotations.
64
- * @param {string } wordVectorsJSON JSON read using node require.
64
+ * @param {object } wordEmbeddings object read using node require.
65
65
* @returns {object } conatining set of API methods for natural language processing.
66
66
* @example
67
67
* const nlp = require( 'wink-nlp' );
68
68
* var myNLP = nlp();
69
69
*/
70
- var nlp = function ( theModel , pipe , wordVectorsJSON = null ) {
70
+ var nlp = function ( theModel , pipe = null , wordEmbeddings = null ) {
71
71
72
72
var methods = Object . create ( null ) ;
73
73
// Token Regex; compiled from `model`
@@ -213,7 +213,7 @@ var nlp = function ( theModel, pipe, wordVectorsJSON = null ) {
213
213
// The `cache` is also part of document data structure.
214
214
rdd . cache = cache ;
215
215
// Each document gets a pointer to the word vectors.
216
- rdd . wordVectors = wordVectorsJSON ;
216
+ rdd . wordVectors = wordEmbeddings ;
217
217
// Document's tokens; each token is represented as an array of numbers:
218
218
// ```
219
219
// [
@@ -413,9 +413,9 @@ var nlp = function ( theModel, pipe, wordVectorsJSON = null ) {
413
413
validAnnotations . ner = typeof theModel . ner === 'function' ;
414
414
validAnnotations . cer = typeof theModel . metaCER === 'function' ;
415
415
416
- if ( wordVectorsJSON !== null ) {
417
- if ( ! helper . isObject ( wordVectorsJSON ) )
418
- throw Error ( `wink-nlp: invalid word vectors, it must be an object instead found a "${ typeof wordVectorsJSON } ".` ) ;
416
+ if ( wordEmbeddings !== null ) {
417
+ if ( ! helper . isObject ( wordEmbeddings ) )
418
+ throw Error ( `wink-nlp: invalid word vectors, it must be an object instead found a "${ typeof wordEmbeddings } ".` ) ;
419
419
420
420
let numOfKeys = 0 ;
421
421
const wordVectorKeys = Object . create ( null ) ;
@@ -427,7 +427,7 @@ var nlp = function ( theModel, pipe, wordVectorsJSON = null ) {
427
427
wordVectorKeys . size = true ;
428
428
wordVectorKeys . words = true ;
429
429
wordVectorKeys . vectors = true ;
430
- for ( const key in wordVectorsJSON ) { // eslint-disable-line guard-for-in
430
+ for ( const key in wordEmbeddings ) { // eslint-disable-line guard-for-in
431
431
numOfKeys += 1 ;
432
432
if ( ! wordVectorKeys [ key ] )
433
433
throw Error ( 'wink-nlp: invalid word vectors format.' ) ;
@@ -436,7 +436,7 @@ var nlp = function ( theModel, pipe, wordVectorsJSON = null ) {
436
436
if ( numOfKeys === 0 ) throw Error ( 'wink-nlp: empty word vectors found.' ) ;
437
437
}
438
438
439
- const tempPipe = ( pipe === undefined ) ? Object . keys ( validAnnotations ) : pipe ;
439
+ const tempPipe = ( pipe === null || pipe === undefined ) ? Object . keys ( validAnnotations ) : pipe ;
440
440
if ( helper . isArray ( tempPipe ) ) {
441
441
tempPipe . forEach ( ( at ) => {
442
442
if ( ! validAnnotations [ at ] ) throw Error ( `wink-nlp: invalid pipe annotation "${ at } " found.` ) ;
@@ -457,12 +457,12 @@ var nlp = function ( theModel, pipe, wordVectorsJSON = null ) {
457
457
methods . as = asHelpers ;
458
458
// Vector of a token method.
459
459
methods . vectorOf = function ( word , safe = true ) {
460
- if ( ! wordVectorsJSON )
460
+ if ( ! wordEmbeddings )
461
461
throw Error ( 'wink-nlp: word vectors are not loaded, use const nlp = winkNLP( model, pipe, wordVectors ) to load.' ) ;
462
462
463
- const vectors = wordVectorsJSON . vectors ;
464
- const unkVector = wordVectorsJSON . unkVector ;
465
- const sliceUpTo = wordVectorsJSON . l2NormIndex + 1 ;
463
+ const vectors = wordEmbeddings . vectors ;
464
+ const unkVector = wordEmbeddings . unkVector ;
465
+ const sliceUpTo = wordEmbeddings . l2NormIndex + 1 ;
466
466
467
467
if ( typeof word !== 'string' ) {
468
468
throw Error ( 'winkNLP: input word must be of type string.' ) ;
0 commit comments