Tag Archives: chatbots

How to implement a chatbot in Java

So we are back on our discussion about chatbots. I will not talk about basics of chatbots that I covered here. I will directly start showing how to implement a chatbot in Java. We are going to use AIML (Artificial Intelligence Markup Language) library for this implementation. This library is opensource and provided by google.

A maven project

As a first step, let’s create a maven project in eclipse with groupId com.betterjavacode and artifactId as chatbot. Once the project is created, we can add ab.jar to project by adding the respective dependency in maven pom.xml  like below:

Google library for AIML provides default AI rules to use to implement chatbot. We will add these rules in resources directory of our project. Copy bots folder from program-ab directory into resources folder.

Chatbot Program

Now we will write the chatbot program which will be part of main method. In simple terms, once we invoke this program through main method, it will be in an infinite loop. An input command will wait for user input and then based on our aiml library chatbot will answer to what an user had input.

Now if we run this program, it will show us input to ask a question to chatbot Mr. Chatter.

Conclusion

In this article, we showed how to add a chatbot. Similarly, we can enhance this program by adding custom patterns that chatbot can respond to.

References

Chatbot Implementation

Advertisements

Chatbots and more

This is not the regular programming post, but more of a discussion post and where we are heading with our technology. Alexa, Google Home, Cortona and number of personal assistants are available at our perusal. With these kind of products, we are slowly evolving into artificial intelligence driven technology. Lot of manual labor jobs might be in danger in near future. Politics aside, I am more interested to understand this topic from technology and humane perspective. While we still struggle with lot of other ethical issues with existing technology, AI will only create social conundrums.

What I want to discuss in this post, is more about chatbots. You can think this as a scribbling post. I am just bringing some ideas forefront to build a chatbot using java.

What are chatbots?

Chatbots are crude version of personal assistants. Personal assistants help you in many ways, in process saving you time, providing you leisure. Simplest version of these chatbots are those that answer your questions like “What’s the weather like today?”, a chatbot will connect to a weather website to find out today’s weather and then answer you accordingly. Similarly, on a ecommerce site, I can ask a question by typing “Where can I find this book?”, chatbot will answer “In literature and short stories section”. A chatbot can also help build customer support, taking away the traditional customer support people. In more advance version, same chatbots can build a library based on your likings, dislikings, answers and provide more options for lifestyle.

Wikipedia definition says

A chatbot is a computer program that conducts a conversation via auditory or textual methods.

Chatbots are part of Artificial intelligence that has been popularized these days.

Design of chatbots

In this article, we will not be showing any code for chatbots, but we will be building chatbots in next post. This is a post where we bring the idea of chatbot into design. As we discussed the definition of chatbot, we will be building an agent that will chat with us in a natural language that we use for daily communication.

Me: “Hi Mr. Chatbot, how are you today?”

Mr. Chatbot: “I am fine, Mr. Mali. Thank You”

Me: “What’s the day today?”

Mr. Chatbot: “It’s Wednesday today.”

This is an example of conversation how a chatbot would answer. We will build a database which will have natural language processing ability to find out what question has been asked and based on that answer the question as accurately as possible. This chatbot is an experimental build up.

Does it mean it can falter? Glad you ask that, it definitely means it can answer erratic. But it’s ok in our experimentation world, even Google home had his off days.

We will need a chat engine and we will be using plain English to type our messages. We will use AIML (Artificial Intelligence Markup Language) to build this chatbot.

In conclusion, I would provide the implementation of this chatbot in next few posts. We will have more discussion about chatbots in future articles.

 

References

  1. AIML
  2. Chatbot