Skip to content

Commit

Permalink
Add support features for entity extraction. Closes #52. (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonHoughton authored and Jorge Padilla committed Aug 24, 2016
1 parent c6462d4 commit e5793f0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lib/initDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ exports.init = function(nlcFile){
}
}
}
if (p.entityfunction) {
p.entityfunction = `${name}_${p.entityfunction}`;
}
}
}
dfnObj.parameters = cls.parameters;
Expand Down
28 changes: 28 additions & 0 deletions src/lib/nlcconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@

const nlcDb = require('./nlcDb');

const NLCCONFIG_KEY = Symbol.for('hubot-ibmcloud-cognitive-lib-nlcconfig');

var globalSymbols = Object.getOwnPropertySymbols(global);
if (globalSymbols.indexOf(NLCCONFIG_KEY) < 0) {
global[NLCCONFIG_KEY] = {};
}

var singleton = {};
Object.defineProperty(singleton, 'instance', {
get: function(){
return global[NLCCONFIG_KEY];
}
});

/**
* Return array of class definitions for all classes (emit target, textfile, and parameters).
*
Expand Down Expand Up @@ -55,3 +69,17 @@ exports.getAutoApprove = function(){
exports.setAutoApprove = function(value){
return nlcDb.setAutoApprove(value);
};

/**
* Sets entity function definitions.
*/
exports.setGlobalEntityFunction = function(name, entityFunction){
singleton.instance[name] = entityFunction;
};

/**
* Returns entity function definitions.
*/
exports.getGlobalEntityFunction = function(name){
return singleton.instance[name];
};
16 changes: 16 additions & 0 deletions test/nlc.config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,20 @@ describe('Testing NLC Configuration', function() {
nlcconfig.setAutoApprove(true);
});
});

context('Verify entity function setter/getter', function() {

function testFunc(paramName, parameters) {
return ['value1', 'value2', 'value3'];
}

it('Verify entity function setter/getter correct value', function() {
nlcconfig.setGlobalEntityFunction('testfunc', testFunc);
let retFunc = nlcconfig.getGlobalEntityFunction('testfunc');
expect(typeof (retFunc)).to.eql('function');
let retFuncResult = testFunc(null, null);
expect(retFuncResult.length).to.eql(3);
expect(retFuncResult[0]).to.eql('value1');
});
});
});

0 comments on commit e5793f0

Please sign in to comment.