I just started exploring compromise and was just trying to play with NER and I create the below code:
const nlp = require(‘compromise’);
function extractTransactionData(text) {
const doc = nlp(text);
const entities = doc.out('terms').map(term => ({
text: term.text,
type: term.tag
}));
var amount, from, to;
for (var i = 0; i < entities.length; i++) {
var entity = entities[i];
if (entity.type === 'Money') {
amount = entity.text;
}
if (entity.type === 'Person') {
from = entity.text;
}
if (entity.type === 'Person' && from !== entity.text) {
to = entity.text;
}
}
return {
amount: amount,
from: from,
to: to
};
}
const text = "You owe $100 to John Smith.";
console.log(extractTransactionData(text));
I expect this code to execute and give the below expected Output:
{ amount: '$100', from: 'You', to: 'John Smith' }
but the code is breaking with TypeError: Cannot read property 'map' of undefined at /node_modules/compromise/builds/three/compromise-three.cjs:1:52703
Can someone help get this simple sample work