-
Notifications
You must be signed in to change notification settings - Fork 621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not able to extract entities #1320
Comments
Here you go @jayesh-patidar! This should work! Try this out. nlp.slotManager.addSlot('travel', 'fromCity', true, { en: 'From where you are traveling? {{fromCity}}' });
nlp.addDocument('en', 'I want to travel from @fromCity to @toCity', 'travel')
nlp.addNerRuleOptionTexts('en', 'fromCity', ["Israel", "USA"]);
nlp.addNerRuleOptionTexts('en', 'toCity', ["Israel", "USA"]);
nlp.addAnswer('en', 'greetings.hello', 'Greetings!');
await nlp.train();
const response = await nlp.process('en', 'I want to travel from Israel to USA');
console.log(response.entities[1].utteranceText); Hope this helps 👍 ps; this is due to documentation needing a little better organizing for this project! The method of extracting slots etc - has changed over various versions of NLP.js. But this should work with your version listed in the issue. |
Thanks for your reply @MarketingPip but in this case too you have defined the list of |
@jayesh-patidar can you post the full response object of the non working call? |
You're more than welcome! My apologizes I should have added another example to help clarify cases where a deemed entity is not defined. I am on mobile as of right now - and can't confirm but I do think / recall there being somewhere in the documentation a symbol / way to write in your corpus a "empty slot" to be filled. You'll have to dig deeper / or when I'm on computer later I'll dig into my treasure chest of random code snippets & see if I have anything else similar to last one I provided above. 👆 |
@Apollon77 Below are the responses for my code Input:
Input:
Input:
You can clearly see when I passed input as Thank you |
@jayesh-patidar - here you go! A full working example of what you need. import { containerBootstrap } from "https://cdn.skypack.dev/@nlpjs/[email protected]";
import { Nlp } from "https://cdn.skypack.dev/@nlpjs/[email protected]";
import { LangEn } from "https://cdn.skypack.dev/@nlpjs/[email protected]";
(async () => {
const container = await containerBootstrap();
container.use(Nlp);
container.use(LangEn);
const nlp = container.get('nlp');
nlp.settings.autoSave = false;
nlp.addLanguage('en');
nlp.slotManager.addSlot('travel', 'fromCity', true);
nlp.addDocument('en', 'I want to travel from %fromCity% to @toCity', 'travel')
nlp.addNerBetweenLastCondition('en', 'fromCity', 'from', 'to');
nlp.addNerAfterLastCondition('en', 'fromCity', 'from');
nlp.addNerBetweenLastCondition('en', 'toCity', 'to', 'from');
nlp.addNerAfterLastCondition('en', 'toCity', 'to');
nlp.slotManager.addSlot('travel', 'fromCity', true);
nlp.slotManager.addSlot('travel', 'toCity', true);
await nlp.train();
const response = await nlp.process('en', 'I want to travel from here to you go bro!');
console.log(response.entities[0].utteranceText); // Outputs: here
console.log(response.entities[1].utteranceText); // Outputs: you go bro!
})(); Hope this helps. Ps; you can use Regex matches for extracting slots. But matching anything ie |
@MarketingPip Thanks for your reply. And sorry for being late I tried your solution but this time it is working fine and extracting the
Earlier the syntax of adding answer was working fine for named entities. Can you please help me out here? |
For some reason I can't seem to get this working on my end. Tho I would try using some regex matching etc.. and replacing (tho this is inconvenient) - might be a work around until you get a answer from the maintainers of this repo. ie: @axa-group /// Create a for loop with all your entities.
let entities = response.entities
let replacedText = response.answer
for (let item in entities){
// Regex for example {{.*}}
replacedText = replacedText.replace(regex_for_your_entities, "entity"); // Happy journey {{fromCity}} to {{toCity}}
} Adjust that code to work with your needs and the proper regex! Wish I could help you out more but keep in mind I am not a contributor nor maintainer of this project. Hopefully we can get some more input from them. Maybe a tag / mention will help here - @jesus-seijas-sp Best of luck tho & have a great weekend @jayesh-patidar. ✌️ |
Thanks for your help @MarketingPip. Waiting to listen from someone meanwhile I will try your solution. |
Describe the bug
I want to make a chatbot from this package but it is not able to recognise the entity properly. I tried many solution but it is not working. Thanks in advance if anyone can help.
To Reproduce
Steps to reproduce the behavior:
v20.0.0
node-nlp
. I am usingv4.27.0
Expected behavior
manager.addNamedEntityText('hero', 'spiderman', 'en')
then the output will beExpected behavior
So the main problem is when I don't pass the
namedEntity
it won't recognise the entity at all. I am not very sure how it is able to identity thedate
. I want to make similar functionality as fordate
in case of all the other variables. I am not aware about the entity in text so cannot add the named entity.If anyone have any other approach to solve this then it will great help.
The text was updated successfully, but these errors were encountered: