Created
September 14, 2021 19:47
-
-
Save cristianmiranda/2e935eeef9279e92a4a7a588a85bc7b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { NerManager } = require("node-nlp"); | |
const manager = new NerManager({ threshold: 0.7 }); | |
manager.addNamedEntityText("brand", "bosch", ["es"], ["bosch", "Robert Bosch"]); | |
manager.addNamedEntityText("brand", "hoover", ["es"], ["hoover"]); | |
manager.addNamedEntityText("brand", "philips", ["es"], ["philips"]); | |
manager.addNamedEntityText("color", "negro", ["es"], ["Negro", "negrito"]); | |
manager.addNamedEntityText("color", "naranja", ["es"], ["naranja"]); | |
manager.addNamedEntityText("model", "minivac", ["es"], ["minivac"]); | |
manager.addNamedEntityText("product", "aspiradora", ["es"], ["Aspiradora"]); | |
const power = manager.addNamedEntity('power', 'regex'); | |
power.addRegex('es', /\b(\d*\.?\d+)\s?(watt[s]?|w+)\b/gi); | |
const capacity = manager.addNamedEntity('capacity', 'regex'); | |
capacity.addRegex('es', /\b(\d*\.?\d+)\s?(lt[s]?|ls|l+)\b/gi); | |
manager.findEntities("Philips MiniVac FC6149/01 - Aspiradora (Secar, 22 W, 840 l/min, 0,5 L, Negro, Naranja, 11 min)", "es").then((entities) => { | |
console.log(entities); | |
}); | |
// ... | |
[ | |
{ | |
start: 0, | |
end: 6, | |
len: 7, | |
levenshtein: 0, | |
accuracy: 1, | |
option: 'philips', | |
sourceText: 'philips', | |
entity: 'brand', | |
utteranceText: 'Philips' | |
}, | |
{ | |
start: 8, | |
end: 14, | |
len: 7, | |
levenshtein: 0, | |
accuracy: 1, | |
option: 'minivac', | |
sourceText: 'minivac', | |
entity: 'model', | |
utteranceText: 'MiniVac' | |
}, | |
{ | |
start: 23, | |
end: 24, | |
len: 2, | |
accuracy: 0.95, | |
sourceText: '01', | |
utteranceText: '01', | |
entity: 'number', | |
resolution: { strValue: '1', value: 1, subtype: 'integer' } | |
}, | |
{ | |
start: 28, | |
end: 37, | |
len: 10, | |
levenshtein: 0, | |
accuracy: 1, | |
option: 'aspiradora', | |
sourceText: 'Aspiradora', | |
entity: 'product', | |
utteranceText: 'Aspiradora' | |
}, | |
{ | |
start: 47, | |
end: 51, | |
accuracy: 1, | |
sourceText: '22 W', | |
utteranceText: '22 W', | |
entity: 'power' | |
}, | |
{ | |
start: 53, | |
end: 58, | |
accuracy: 1, | |
sourceText: '840 l', | |
utteranceText: '840 l', | |
entity: 'capacity' | |
}, | |
{ | |
start: 66, | |
end: 69, | |
accuracy: 1, | |
sourceText: '5 L', | |
utteranceText: '5 L', | |
entity: 'capacity' | |
}, | |
{ | |
start: 71, | |
end: 75, | |
len: 5, | |
levenshtein: 0, | |
accuracy: 1, | |
option: 'negro', | |
sourceText: 'Negro', | |
entity: 'color', | |
utteranceText: 'Negro' | |
}, | |
{ | |
start: 78, | |
end: 84, | |
len: 7, | |
levenshtein: 0, | |
accuracy: 1, | |
option: 'naranja', | |
sourceText: 'naranja', | |
entity: 'color', | |
utteranceText: 'Naranja' | |
}, | |
{ | |
start: 87, | |
end: 92, | |
len: 6, | |
accuracy: 0.95, | |
sourceText: '11 min', | |
utteranceText: '11 min', | |
entity: 'time' | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment