@pg-english/entity
v0.1.8
Published
Process text to entity tokens.
Downloads
162
Maintainers
Readme
@pg-english/entity
Process text to entity tokens.
const entity = require('@pg-english/entity');
// entity.process(<tokens>, <match fn>, [this]): Promise (processed tokens)
// entity(<text>, <match fn>, [this])
// -> Promise (processed text)
// <match fn>(<texts>)
// - texts: array of text
// -> Promise {type, value, hint, length}
// - type: token type (table/column/row)
// - value: token value
// - hint: token hint (identifies table)
// - length: token length (from start of texts)
function match(txts) {
var txt = txts.join(' ');
if(!txt.startsWith('ascorbic acid')) return Promise.resolve(null);
return Promise.resolve({type: 'column', value: 'ASCORBIC ACID', length: 2});
};
await entity('lemon has ascorbic acid', match);
// lemon has ASCORBIC ACID
await entity('i love ascorbic acid. chilli has ascorbic ascorbic acid.', match);
// i love ASCORBIC ACID . chilli has ascorbic ASCORBIC ACID .