UNPKG

@pg-english/entity

Version:

Process text to entity tokens.

33 lines (25 loc) 1.05 kB
# @pg-english/entity [![pg-english](https://i.imgur.com/UN74CCi.jpg)](https://npmjs.com/package/pg-english) Process text to entity tokens. ```javascript 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 . ```