问题
I have a real estate bot where I need to handle the following cases. - I am looking for a house with 1200 sqft - I am looking for a house with 1200 - 1500 sqft - I am looking for a house between 1200 sqft to 1500 sqft
Another case is my bot asking How many square feet are you looking for? User says 1500
A couple of questions
- How do I handle ranges and normal values with or without units
- How do I restrict the values to be in a certain range (under 10000) for example. I also have a case where I ask for a price range and I need to differentiate between square feet and price? What is the best way to do this with api.ai?
回答1:
There's a few questions here so I'm going to answer each quickly, and then answer with a longer solution given what I think you are actually trying to achieve.
How do I handle ranges and normal values with or without units?
The best way to handle multiple possible entries is to create lots of examples for the same intent and train your bot. So in the case of square feet, you might want to create varying example like the below, indicating to your bot how to recognize minimum and maximum size parameters. With enough examples, your bot should easily learn to recognize these parameters even when no units are explicitly given (ie 'sqft')
How do I restrict the values to be in a certain range (under 10000) for example.
In short, you don't, not without a custom built server side solution that sits between API.ai and the messaging platform that can do some data validation.
I also have a case where I ask for a price range and I need to differentiate between square feet and price? What is the best way to do this with api.ai?
It would be tough to train a single intent to recognize the difference between price and square feet when no units are being provided, even with a bunch of examples API.ai is likely to not be very accurate at always recognizing that when a user says 'My target is 1200' they don't mean $1,200- again that is IF you have a single intent for gathering user price and user size desires.
My advice for what you seem to be trying to achieve would be to have two separate intents, one for size and one for price, and explicitly prompt the user for each answer. This makes your application a bit more 'rigid', but the more flexibility you allow for in conversational flows the more ambiguity which is introduced, which in turn reduces the usefulness and accuracy of your bot.
So in some senses it's a trade off vs a black-and-white call, but my personal suggestion is the more structured approach described above.
If you need help building a custom server side solution to sit between API.ai and your user, let me know. It actually isn't all that difficult
来源:https://stackoverflow.com/questions/43568187/best-way-to-handle-ranges-in-api-ai