Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it( 'should throw error if config is not defined', function () {
expect( bts.definePrepTasks.bind( null, [ prepare.string.lowerCase ] ) ).to.throw( 'winkBM25S: Config must be defined before defining prepTasks.' );
// Config must be defined first to test remaining cases.
bts.defineConfig( { fldWeights: { title: 4, body: 1, tags: 2 } } );
} );
var prepTasks = [
/* eslint no-console: 0 */
// Load wink-bm25-text-search
var bm25 = require( 'wink-bm25-text-search' );
// Create search engine's instance
var engine = bm25();
// Load NLP utilities
var nlp = require( 'wink-nlp-utils' );
// Load sample data (load any other JSON data instead of sample)
var docs = require( 'wink-bm25-text-search/sample-data/demo-data-for-wink-bm25.json' );
// Define preparatory task pipe!
var pipe = [
nlp.string.lowerCase,
nlp.string.tokenize0,
nlp.tokens.removeWords,
nlp.tokens.stem,
nlp.tokens.propagateNegations
];
// Contains search query.
var query;
// Step I: Define config
// Only field weights are required in this example.
engine.defineConfig( { fldWeights: { title: 1, body: 2 } } );
// Step II: Define PrepTasks pipe.
// Set up 'default' preparatory tasks i.e. for everything else
engine.definePrepTasks( pipe );
// Step III: Add Docs
// Add documents now...
/* eslint no-console: 0 */
// Load wink-bm25-text-search
var bm25 = require( 'wink-bm25-text-search' );
// Create search engine's instance
var engine = bm25();
// Load NLP utilities
var nlp = require( 'wink-nlp-utils' );
// Load sample data (load any other JSON data instead of sample)
var docs = require( 'wink-bm25-text-search/sample-data/demo-data-for-wink-bm25.json' );
// Define preparatory task pipe!
var pipe = [
nlp.string.lowerCase,
nlp.string.tokenize0,
nlp.tokens.removeWords,
nlp.tokens.stem,
nlp.tokens.propagateNegations
];
// Contains search query.
var query;
// Step I: Define config
// Only field weights are required in this example.
engine.defineConfig( { fldWeights: { title: 1, body: 2 } } );
// Step II: Define PrepTasks pipe.
// Set up 'default' preparatory tasks i.e. for everything else
engine.definePrepTasks( pipe );
// Step III: Add Docs
describe( 'definePrepTasks() Proper Cases', function () {
var bts = bm25();
bts.defineConfig( { fldWeights: { title: 4, body: 1, tags: 2 } } );
var prepTasks = [
{ whenInputIs: [ prepare.string.tokenize0, prepare.string.stem ], expectedOutputIs: 2 },
{ whenInputIs: [ ], expectedOutputIs: 0 }
];
prepTasks.forEach( function ( ptask ) {
it( 'should return "' + ptask.expectedOutputIs + '" if the input is ' + JSON.stringify( ptask.whenInputIs ), function () {
expect( bts.definePrepTasks( ptask.whenInputIs ) ).to.equal( ptask.expectedOutputIs );
} );
} );
} );
describe( 'definePrepTasks() Error Cases', function () {
var prepTNBC = tnbc();
var prepTasks = [
{ whenInputIs: [ prepare.string.incorrect, prepare.string.lowerCase ], expectedOutputIs: 'winkNBTC: each task should be a function, instead found: undefined' },
{ whenInputIs: null, expectedOutputIs: 'winkNBTC: tasks should be an array, instead found: null' },
{ whenInputIs: undefined, expectedOutputIs: 'winkNBTC: tasks should be an array, instead found: undefined' },
{ whenInputIs: 1, expectedOutputIs: 'winkNBTC: tasks should be an array, instead found: 1' },
{ whenInputIs: { a: 3 }, expectedOutputIs: 'winkNBTC: tasks should be an array, instead found: {"a":3}' }
];
prepTasks.forEach( function ( ptask ) {
it( 'should throw "' + ptask.expectedOutputIs + '" if the input is ' + JSON.stringify( ptask.whenInputIs ), function () {
expect( prepTNBC.definePrepTasks.bind( null, ptask.whenInputIs ) ).to.throw( ptask.expectedOutputIs );
} );
} );
}
);
it( 'definePrepTasks should return 1', function () {
expect( learnTNBC.definePrepTasks( [ prepare.string.tokenize0 ] ) ).to.equal( 1 );
} );
it( 'defineConfig should return true', function () {