rivescript-python
rivescript-python copied to clipboard
Query - words ordering in bot brain
Hi,
I would like to know if it is possible to have input match to any possible inputs having the same words possibly not in the same order.
Below is a sample example
+ [get] status [of] [the] system *
- System is doing great
+ [get] system status *
- System is doing great
+ [is] [the] system status *
- System is doing great
+ [what] [is] [the] system status *
- System is doing great
As you can see above there are multiple ways I ask for the "system status". So what am trying to do is build a system where I will break the user input to extract only keywords (most importantly not in the same order) in the text and send the keywords to rivescript. What I would like to know is how can I ignore ordering of the mandatory keywords in rivescript ?
I have been experimenting with the use of stop words. Here is a sample Python code:
stop_words = ['the', 'of', 'an','is','was']
def sanitize(user_input, stop_words):
return [w for w in user_input if w not in stop_words]
input = sanitize(user_input, stop_words)
This will take the user's input and remove the words "the, of, an, is, was" before sending it to Rivescript.
+ (system|status) (system|status)
Will allow for the command not to be in the same order
@ekt1701 Since you are trying it out, I would appreciate if you share your use case
I am experimenting with stopwords and fuzzy matching to solve riddles. I scrape the riddle and answer from http://goodriddlesnow.com/ then filter out the stop words from the answer, this works fine. I use the same stop words for the user's input.
I am using fuzzywuzzy for the fuzzy matching of the user input and answer.
Thanks @ekt1701 for your responses.
In my case am developing a bot that would interact and take actions based on users inputs. But I personally feel that the complexity of NL becomes a bottle neck for closed domain bots. So I was thinking to process the input, extract the keywords and then pass it on to the bot. That way we don't have to record all possible inputs. We only have to take care of the important keywords.
I am no bot expert and also not sure if this is the right thing to do. But still thinking to give it a try.
What you are thinking is similar to the code I posted above, except, it removes the stop words and leaves the keywords which is sent to the bot.
If you are interested, here is the complete list of stop words used in nltk.corpus:
{'ourselves', 'hers', 'between', 'yourself', 'but', 'again', 'there', 'about', 'once', 'during', 'out', 'very', 'having', 'with', 'they', 'own', 'an', 'be', 'some', 'for', 'do', 'its', 'yours', 'such', 'into', 'of', 'most', 'itself', 'other', 'off', 'is', 's', 'am', 'or', 'who', 'as', 'from', 'him', 'each', 'the', 'themselves', 'until', 'below', 'are', 'we', 'these', 'your', 'his', 'through', 'don', 'nor', 'me', 'were', 'her', 'more', 'himself', 'this', 'down', 'should', 'our', 'their', 'while', 'above', 'both', 'up', 'to', 'ours', 'had', 'she', 'all', 'no', 'when', 'at', 'any', 'before', 'them', 'same', 'and', 'been', 'have', 'in', 'will', 'on', 'does', 'yourselves', 'then', 'that', 'because', 'what', 'over', 'why', 'so', 'can', 'did', 'not', 'now', 'under', 'he', 'you', 'herself', 'has', 'just', 'where', 'too', 'only', 'myself', 'which', 'those', 'i', 'after', 'few', 'whom', 't', 'being', 'if', 'theirs', 'my', 'against', 'a', 'by', 'doing', 'it', 'how', 'further', 'was', 'here', 'than'}
I'm not sure if this is what you're looking for. Here I am not allowing user to input words (okay|ok|shit|damn|shut up|bitch) as their names. here you can have all the stopwords and block stop words
> begin
+ request
* <get met> == undefined => <set met=true>{topic=new_user}{ok}
- {ok}
< begin
> topic new_user
+ *
- Hi! I'm <bot name>!.\s
^ What is your name?{topic=asked_name}
< topic
> topic asked_name
+ *
- I only want your first name.
+ [*] (okay|ok|shit|damn|shut up|bitch) [*]
- this doesnt look like your name?
+ _
- <set name=<formal>>Nice to meet you, <get name>!{topic=random}
< topic