BraveyJS / Bravey

A simple JavaScript NLP-like library to help you creating your own bot.
https://braveyjs.github.io/
MIT License
78 stars 6 forks source link

New FunctionEntityRecognizer. TypeScript definition added. #19

Open thiagodp opened 6 years ago

thiagodp commented 6 years ago

The new FunctionEntityRecognizer allows to specify a function to detect entities. It is useful to deal with those cases in which a regular expression is hard to build.

As documented, the function expects a string and returns an array of { value: any, index: number }. Example:

var detectFoo = function( text ) {
  var detected = [];
  while ( the entity is detected in the text ) {
     detected.push( {
         value: <detected value here>,
         index: <detected index here>
     } );
  }
  return detected;
};
var reg = new Bravey.FunctionEntityRecognizer( "foo", detectFoo );

TypeScript definition file added, as proposed by the pull request 17 (@nippur72). Now it also contains FunctionEntityRecognizer.