Introduction to CHAT BOT
In the fast-growing world of Artificial Intelligence, consumers are getting technological help in all facets of their lives.
The internet provides various ways to get information and has radically changed the way we communicate.
Innovation has enhanced our lives with more opportunities, and everything is quite simple for us. Everybody likes to collaborate and expect quick answers without much delay. You can use online networking platforms or websites regularly for various reasons to connect with others.
A chatbot is a program or service that easily connects with you to help solve your queries.
The services that a chatbot can deliver are quite diverse, from providing important life-saving health messages to checking the weather forecast to purchasing a new pair of shoes.
While interacting with a chatbot, you should feel as if you are talking with a real person.
There are two types of chatbots: bots for amusement and bots for business.
Discussion frameworks can generally be separated into two classifications: retrieval-based models and generative-based models.
AIML
AIML stands for Artificial Intelligence Markup Language. AIML is an XML based markup language meant to create artificial intelligent applications.
AIML makes it possible to create human interfaces while keeping the implementation simple to program, easy to understand and highly maintainable.
AIML was developed by the Alicebot free software community and Dr. Richard S. Wallace during 1995-2000. AIML is used to create or customize Alicebot which is a chat-box application based on A.L.I.C.E. (Artificial Linguistic Internet Computer Entity) free software.
AIML Vocabulary
AIML vocabulary uses words, space and two special characters * and _ as wild cards. AIML interpreter gives preference to pattern having _ than pattern having *. AIML tags are XML compliant and patterns are case-insensitive.
Following are the important points to be considered −
- tag signifies start of the AIML document.
- tag defines the knowledge unit.
- tag defines the pattern user is going to type.
- tag defines the response to the user if user types Hello Alice.
Example
<aiml version = “1.0.1” encoding = “UTF-8”?>
<category>
<pattern> HELLO ALICE </pattern>
<template>
Hello User!
</template>
</category>
</aiml>
Result
User: Hello Alice
Bot: Hello User
Pandorabots
Pandorabots offer an online web service for building and deploying chatbots.
The Pandorabots platform supports an open standard scripting language called Artificial Intelligence Markup Language (AIML).
The easiest way to get started with AIML is to create a Pandorabots account and then spend five minutes on the interactive Quickstart, which will walk you through both chatbot development and user interface fundamentals.
For a deeper dive, Bot Building 101 is an excellent starting point, and there is a wealth of additional AIML resources in the AIML section.
Building ChatBot Android application
Prerequisites
- AIML Basics
- Pandorabots account
- Android Studio
Step 1: Create an android project in Android Studio.
Step 2: To need to process AIML files, Download the JAR file from below link and place it in your libs folder (app/libs/)
https://drive.google.com/file/d/0BxILBrhfU04VUW9JaGVZMjVFdk0/view
Step 3: Import the AIML files which you have created using the Pandorabots account.
Step 4: Add the dependencies to your project
dependencies
{
compile fileTree(dir: ‘libs’, include: [‘*.jar’])
testCompile ‘junit:junit:4.12’
compile ‘com.android.support:appcompat-v7:23.3.0’
compile ‘com.android.support:support-v4:23.3.0’
compile ‘com.android.support:cardview-v7:23.3.0’
compile ‘com.android.support:design:23.2.1’
compile ‘me.himanshusoni.chatmessageview:chat-message-view:1.0.3’
compile files(‘libs/Ab.jar’)
}
Step 5: Creating chat UI by importing following dependency.
compile ‘me.himanshusoni.chatmessageview:chat-message-view:1.0.3’
activity_main.xml
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:app=”http://schemas.android.com/apk/res-auto”
xmlns:tools=”http://schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”.MainActivity”>
<!–List view for displaying chat messages–>
<ListView
android:id=”@+id/listView”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:layout_above=”@+id/send_message_layout”
android:divider=”@null” /> <!–To type and send the message–>
<LinearLayout
android:id=”@+id/send_message_layout”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_alignParentBottom=”true”
android:background=”#ffdddddd”
android:gravity=”center_vertical”
android:orientation=”horizontal”>
<ImageView
android:id=”@+id/iv_image”
android:layout_width=”40dp”
android:layout_height=”40dp”
android:src=”@drawable/bot” />
<EditText
android:id=”@+id/et_message”
android:layout_width=”wrap_content”
android:layout_marginLeft=”4dp”
android:layout_marginRight=”4dp”
android:layout_height=”wrap_content”
android:layout_weight=”1″ />
<android.support.design.widget.FloatingActionButton
android:id=”@+id/btn_send”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:src=”@drawable/ic_send_24dp”
android:text=”Send” />
</LinearLayout>
</RelativeLayout>
<!–item_mine_message.xml- for user message –>
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical”
android:padding=”3dp”>
<me.himanshusoni.chatmessageview.ChatMessageView xmlns:app=”http://schemas.android.com/apk/res-auto”
android:id=”@+id/chatMessageView”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
app:cmv_arrowGravity=”start”
app:cmv_arrowMargin=”3dp”
app:cmv_arrowPosition=”right”
app:cmv_backgroundColor=”#88BABABA”
app:cmv_backgroundColorPressed=”#FFBABABA”
app:cmv_contentPadding=”10dp”
app:cmv_cornerRadius=”3dp”
app:cmv_showArrow=”true”>
<TextView
android:id=”@+id/text”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Hello”
android:textAppearance=”@style/TextAppearance.AppCompat.Body1″ />
</me.himanshusoni.chatmessageview.ChatMessageView>
</LinearLayout>
Step 6: In your MainActivity and implement the below.
- Declare and define the necessary UI components in the XML
- Create functions for sending and receiving messages
- Instruct the ListView to scroll to the latest message
- Test your chat with static response
MainActivity.java
public class MainActivity extends AppCompatActivity {
private ListView mListView;
private FloatingActionButton mButtonSend;
private EditText mEditTextMessage;
private ImageView mImageView;
private ChatMessageAdapter mAdapter;@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mListView = (ListView) findViewById(R.id.listView);
mButtonSend = (FloatingActionButton) findViewById(R.id.btn_send);
mEditTextMessage = (EditText) findViewById(R.id.et_message);
mImageView = (ImageView) findViewById(R.id.iv_image);
mAdapter = new ChatMessageAdapter(this, new ArrayList<ChatMessage>());
mListView.setAdapter(mAdapter);
//code for sending the message
mButtonSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String message = mEditTextMessage.getText().toString();
sendMessage(message);
mEditTextMessage.setText(“”);
mListView.setSelection(mAdapter.getCount() – 1);
}
});
}private void sendMessage(String message) {
ChatMessage chatMessage = new ChatMessage(message, true, false);
mAdapter.add(chatMessage);
//respond as Helloworld
mimicOtherMessage(“HelloWorld”);
}
private void mimicOtherMessage(String message) {
ChatMessage chatMessage = new ChatMessage(message, false, false);
mAdapter.add(chatMessage);
}
private void sendMessage() {
ChatMessage chatMessage = new ChatMessage(null, true, true);
mAdapter.add(chatMessage);
mimicOtherMessage();
}
private void mimicOtherMessage() {
ChatMessage chatMessage = new ChatMessage(null, false, true);
mAdapter.add(chatMessage);
}
Conclusion
Chatbots or smart assistants with artificial intelligence are dramatically changing businesses. There is a wide range of chatbot building platforms that are available for various enterprises, such as e-commerce, retail, banking, leisure, travel, healthcare, and so on.
Chatbots can reach out to a large audience on messaging apps and be more effective than humans. They may develop into a capable information-gathering tool in the near future.
References
Pandorabots – https://home.pandorabots.com/dash/help/tutorials
AIML – https://www.tutorialspoint.com/aiml/index.htm
http://www.alicebot.org/aiml.html
JAR – https://goo.gl/O3bDA7