I've written a chatbot in python which connects to discord, and is able to fulfil some tasks. One of the tasks is to query a list of resources of a specific computer game, and return the detailed location of the queried resource. Now I want to integrate the functionality into the chat, as seemlessly as possible. So I thought I could use NLP techniques for it.
To give an example: User 1 wants to know where he/she can find the resource "wood". So he/she asks in the discord chat: "Where can I find wood?"
My program shall now be able to identify this question as a valid query for a resource location, and respond with the location for resource "wood".
This might involve several steps:
- Determine that in fact a question is asked
- Determine the name of the resource which was asked for
- ???
I am not new to programming, however I am new to NLP. Also I'm a beginner in deep learning / already developed RNN models using tensorflow/keras.
For this project, I found nltk and spaCy, both of which are python modules used for NLP. I've learned already that text analysis consists of several distinct jobs, and not all of them might be of interest for my project. But it seems that both tokenization and pos tagging might be of interest. But somehow I am struggling to find a viable approach for the task. It already starts with how to identify if a text message is actually a question. My research indicates this is no functionality which is provided by NLP libraries out of the box, and pre-trained deep learning models are usually used to categorize sentences like that.
Ideas I've had so far:
1) Analyze every chat message sentence by sentence
Tokenize the sentence, use stemming, then pos tagging, then iterate all tokens to find out if:
- The verbs "find" (Where can I find ...) or "get" (Where can I get ...)" or "is" (Where is ...) are contained
- Check if a noun is contained, and if so, if this noun is a valid resource name (a better approach would probably to find out of the noun is actually the object related to the verb. is this possible even?)
- Check if the sentence if a question by checking if the last token is a
?
2) Use some kind of matching, like the spaCy's rule based matching
- Build several patterns which can identify the desired question/question types
- Match the patterns on every chat message
- If matched, extract the resource name
3) Use non-NLP techniques
If everything else should be unviable/too complicated, I can still come up with a hardcoded approach where I would just pre-define a couple of question types, and string-search their occurence within chat messages, and try to manually extract the resource names by using string operations.
This will probably be the most error prone and unflexible solution, but I'll keep it as a fallback.
Of course, I do want to implement a solution which is working as flexible as possible, so it can detect various forms and types of questions, without hardcoding all possible types of questions beforehand. It should be as close to "the bot just understands the chat and answers the question" as possible.
Could someone guide me towards a good solution? (not asking for complete code, but rather the techniques/steps/libraries I shall use)
Maybe as a sidenote: In a later version I want to extend the functionality. Then, it shall be possible that other users name the location of a resource in the discord chat, and the bot shall add this location to its database, if its not already contained. So the chat conversation might look like:
User 1: Where can I find cryptonite?
User 2: It can be found in lex luthors lab
Bot: Shall I add "lex luthors lab" as location for resource "cryptonite"?
User 2: @bot: yes
Bot: Done.