-
Notifications
You must be signed in to change notification settings - Fork 86
NSpM Telegram Bot
We would like to draw your attention to our project, the DBPedia Query Bot. During our computer science studies, we had the task to tackle a project that has something to do with semantic web. So we decided to create a Telegram Chatbot that can query DBPedia. We not only wanted the Bot to query with SPARQL but also to query by natural language. Therefore we used the NSpM to translate natural language to SPARQL. The source code of our project can be found at https://github.com/gluecksbaerchi/NSpM-telegram-bot.
@article{gumpel-zingler-2018,
author = {G\"umpel, Carolin and Zingler, Ronny and Marx, Edgard and Soru, Tommaso},
abstract = {The Semantic Web community has successfully deployed a significant number of RDF datasets on the Web. However, for ordinary users, to access information available on this datasets, it is still a cumbersome and time-demanding task that requires the knowledge of description frameworks and the use of formal languages. We introduce the Neural SPARQL Machine (NSpM) Telegram Chatbot, a chatbot built on top the open-source Telegram platform that facilitates the natural language querying of RDF datasets through the NSpM architecture. We show the different APIs implemented by the proposed chatbot as well as the processing steps from a natural language query to its corresponding answer. Additionally, we demonstrate how to instantiate as well as how to query other RDF datasets.},
booktitle = {Workshop on Linked Data Management co-located with the W3C WEBBR 2018},
url = {https://www.researchgate.net/publication/334561410_The_Neural_SPARQL_Machine_Telegram_Chatbot},
title = {The Neural SPARQL Machine Telegram Chatbot},
Keywords = {2018 aksw liberai nspm dbnqa chatbot group_aksw marx pcponweb soru},
year = 2018
}
pull the repository located at https://github.com/gluecksbaerchi/NSpM-telegram-bot
You need to have docker and docker-compose installed an running. You need a telegram account and a telegram client running on mobile or desktop.
First, you will need to get a BOT-TOKEN. Therefore you need to talk to the Botfather, which is another Telegram Bot. There are many Tutorials on how to create a new Bot and get a TOKEN
https://telegram.me/BotFather //adds @botfather to your chats
If you've got the Token you need to add it to the project. There is an environment variable in the docker-compose.yml file.
environment:
- BOT_TOKEN= [INSERT TOKEN HERE]
Now you can start the project by executing following instruction in your terminal.
cd [PATH_TO_PROJECT]
sudo docker-compose up
To talk to your bot you need to add him to your chatlist
https://telegram.me/[YOUR BOT NAME]
If everythings gone right you are now able to talk to the DBPedia Query Bot.
If the NSpM and Telegram Sevices are working properly you should be able to talk to the Bot. The first time you start a conversation you will see the following welcome window.
As you can see the Bot asks you to type the command /start. In Telegram commands are messages starting with "/". They can be defined by you.
As return to your command you will get this window and the bot will tell you, which commands he understand. These are
- /help
- /ask
- /query
- /cat
When you type the command /help the bot will ask you where he can help you. You can decide weather you want to know how to ask a question or how to query by SPARQL. The bot will now answer with an alert window as seen in the next picture.
If you want to ask the bot a question you will have to type the command /ask followed by your question. In this stage of progress you can only ask about monuments becaus the neurals net training data is about monuments. You will now get the answer and can decide weather you will store this answer and the corresponding question to training data or not.
To query by SPARQL you have to type /query followed by your SPARQL query. If everything works fine the bot will tell you the answer.
This command is a little gimmick i included because i wanted to know what Telegraf can do. You will have to try this with no further explanation.
The Telegram Service contains the backend for your Telegram Bot. It uses NodeJS and Telegraf (NodeJS Telegram Bot API). When a user types a message to your bot, the Telegram Service will know and decide how to handle the message.
- bot.js
- http_service.js
- message_service.js
The bot.js uses Telegraf to build the Bot and to install event-handling. Every command that is supported and every message that will get an answer can be found there.
bot.command('start', (ctx) => {
ctx.reply(messages.start_msg);
});
For example this code snippet tells the bot if he gets the command /start how to answer
The http_service.js forms the interface to the NSpM Service. There are functions like
- post_question()
- post_query()
- post_training()
to connect to the NSpM Service via HTTP and get the infos you need to answer to the user.
The message_service is basically an array of strings which contains all phrases the bot know.
The NSpM Service is a simple API for asking questions to DBpedia. Natural language queries are translated into SPARQL queries using the AKSW/NSpM project. The Telegram Service forwards the user questions to the NSpM Service to get an answer.
Transform natural language question to SPARQL query using NSpM and request DBpedia with the result.
Parameter:
- question: question (required) - question in natural language
- preferredLanguage (optional) - answer in this language if possible, default: en
Response:
- query: the query sent to DBpedia
- value: the answer for the query, it has the type given in "type"
- type: boolean | string | uri_list
- status: ok | error
Direct SPARQL request on DBpedia.
Parameter:
- question: question (required) - the SPARQL query
- preferredLanguage (optional) - answer in this language if possible, default: en
Response:
- query: the query sent to DBpedia
- value: the answer for the query, it has the type given in "type"
- type: boolean | string | uri_list
- status: ok | error
Save a natural language question with it’s corresponding SPARQL query for training the network.
Parameter:
- question (required) - question in natural language
- query (required) - SPARQL query
Response:
- status 400 if question or query not given
- status 200 else