Technical Support - Artificial Intelligence
(*From now on, I'll try my best to explain about all of my Project using English)
For this project, I made 3 classes to control the Bot Mechanism (Referencing to Objects-First-with-Java-A-Practical-Introduction-Using-BlueJ-David-J-Barnes pages 155) :
- InputReader Class (Used for detect or to take any user input)
- SupportSystem Class (As a main function connecting the user input and database)
- Responder Class (Handling AI-Output and Its role as 'mini' database)
Current Version : 1.2
In the future, I'm expecting to have a bigger Responder's Database and would be separated from the Class itself, so it will be easier to make some modification inside the AI's Database and easier to manage. And then i'll try to improve the UX Design inside, so that the user can have a feeling about how 'Human' this AI.
In the future, I'm expecting to have a bigger Responder's Database and would be separated from the Class itself, so it will be easier to make some modification inside the AI's Database and easier to manage. And then i'll try to improve the UX Design inside, so that the user can have a feeling about how 'Human' this AI.
InputReader Class
In this class, pretty much the same as how the name of the class is written, the user input is expected to be a normal conversation.
Source Code
Source Code
import java.util.Scanner;
import java.lang.String;
/**
* A class for taking user input
*
* @author Satria Ade Veda Karuniawan
* @version Version 1.2
*/
public class InputReader
{
private String input;
private Scanner sc;
public InputReader()
{
sc = new Scanner(System.in);
input = "";
}
public String getInput()
{
input = sc.nextLine();
input = preProcess(input);
return input;
}
public String preProcess(String a)
{
String lower = a.toLowerCase();
return lower;
}
}
import java.lang.String;
/**
* A class for taking user input
*
* @author Satria Ade Veda Karuniawan
* @version Version 1.2
*/
public class InputReader
{
private String input;
private Scanner sc;
public InputReader()
{
sc = new Scanner(System.in);
input = "";
}
public String getInput()
{
input = sc.nextLine();
input = preProcess(input);
return input;
}
public String preProcess(String a)
{
String lower = a.toLowerCase();
return lower;
}
}
SupportSystem Class
The class role as a connector between the user input (the detector), pass it to the Responder, and return the Responder's reply as a String.
Source Code
import java.lang.InterruptedException;
import java.io.IOException;
/**
* System as a connector between the input and the response class
*
* @author Satria Ade Veda Karuniawan
* @version Version 1.2
*/
public class SupportSystem
{
private InputReader reader;
private Responder responder;
/**
* Creates a technical support system.
*/
public SupportSystem()
{
reader = new InputReader();
responder = new Responder();
start();
}
/**
* Start the technical support system. This will print a
* welcome message and enter into a dialog with the user,
* until the user ends the dialog.
*/
public void start()
{
boolean finished = false;
boolean botfoundproblem = false;
printWelcome();
while(!finished) {
System.out.println("");
System.out.print(">");
String input = reader.getInput();
//System.out.println("Input Detected : " + input);
if(input.indexOf("bye") >= 0 ||
input.indexOf("see you") >= 0 ||
input.indexOf("see ya") >= 0) {
finished = true;
}
if(botfoundproblem)
{
}
else {
String response = responder.generateResponse(input);
System.out.println("(TechSupport is typing. . .)");
for(int a = 0; a < response.length(); a++)
{
try
{
Thread.sleep(30);
}
catch(InterruptedException e)
{
}
}
System.out.print(response);
System.out.println("");
}
}
}
/**
* Print a welcome message to the screen.
*/
private void printWelcome()
{
System.out.println(
"Welcome to the NewSAVK Technical Support System.");
System.out.println();
System.out.println("Please tell us about your problem.");
System.out.println(
"We will assist you with any problem you might have.");
System.out.println(
"Please type 'bye' to exit our system.");
}
}
import java.io.IOException;
/**
* System as a connector between the input and the response class
*
* @author Satria Ade Veda Karuniawan
* @version Version 1.2
*/
public class SupportSystem
{
private InputReader reader;
private Responder responder;
/**
* Creates a technical support system.
*/
public SupportSystem()
{
reader = new InputReader();
responder = new Responder();
start();
}
/**
* Start the technical support system. This will print a
* welcome message and enter into a dialog with the user,
* until the user ends the dialog.
*/
public void start()
{
boolean finished = false;
boolean botfoundproblem = false;
printWelcome();
while(!finished) {
System.out.println("");
System.out.print(">");
String input = reader.getInput();
//System.out.println("Input Detected : " + input);
if(input.indexOf("bye") >= 0 ||
input.indexOf("see you") >= 0 ||
input.indexOf("see ya") >= 0) {
finished = true;
}
if(botfoundproblem)
{
}
else {
String response = responder.generateResponse(input);
System.out.println("(TechSupport is typing. . .)");
for(int a = 0; a < response.length(); a++)
{
try
{
Thread.sleep(30);
}
catch(InterruptedException e)
{
}
}
System.out.print(response);
System.out.println("");
}
}
}
/**
* Print a welcome message to the screen.
*/
private void printWelcome()
{
System.out.println(
"Welcome to the NewSAVK Technical Support System.");
System.out.println();
System.out.println("Please tell us about your problem.");
System.out.println(
"We will assist you with any problem you might have.");
System.out.println(
"Please type 'bye' to exit our system.");
}
}
Responder Class
Responder act as the AI's brain, checking the 'mini' database (as brain's memory), and give a reply, But the algorithm to find the correct reply is rather simple.
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Random;
import java.util.Iterator;
/**
* This Class explain how the AI would response depend on the user input.
*
* @author Satria Ade Veda Karuniawan
* @version Version 1.2
*/
public class Responder
{
private Map<String, String> responseMap;
private Random randomGenerator;
public Responder()
{
responseMap = new HashMap<String, String>();
fillResponseMap();
}
/**
* Enter all the known keywords and their associated
* responses into our response map.
*/
public String generateResponse(String input)
{
// Pick a random number for the index in the default response
// list. The number will be between 0 (inclusive) and the size
// of the list (exclusive).
String response = "";
for(Map.Entry<String, String> data : responseMap.entrySet())
{
if(input.indexOf(data.getKey()) >= 0)
{
response = data.getValue();
break;
}
}
return response;
}
private void fillResponseMap()
{
responseMap.put("problem",
"Can you explain in detail about your problem? \n" +
"Please be more specific.");
responseMap.put("slow",
"I think this has to do with your hardware. \n" +
"Upgrading your processor should solve all " +
"performance problems. \n" +
"Have you got a problem with our software?");
responseMap.put("bug",
"Well, you know, all software has some bugs. \n" +
"But our software engineers are working very " +
"hard to fix them. \n" +
"Can you describe the problem a bit further?");
responseMap.put("expensive",
"The cost of our product is quite competitive. \n" +
"Have you looked around and " +
"really compared our features?");
responseMap.put("windows",
"That can be happened whether you use unoriginal windows \n" +
"or you need to do further Update");
responseMap.put("what is your name",
"Why do you want to know my name?");
responseMap.put("hello",
"Hi there!");
responseMap.put("i want",
"Is there any reason why you want this?");
responseMap.put("i hate",
"Why do you hate it?");
responseMap.put("i love chatting",
"Good, me too!");
responseMap.put("i mean",
"Oh, i didn't know you meant that");
responseMap.put("i didn't mean",
"Ok, what did you mean then?");
responseMap.put("i guess",
"Aren't you sure?");
responseMap.put("fine",
"I'm glad to hear it!");
responseMap.put("can you think",
"Are you asking me if possess the capacity of thinking?");
responseMap.put("can you think of",
"I don't know if i can do that.");
responseMap.put("how are you",
"I'm doing fine!");
responseMap.put("who are you",
"I'm a technical support, programmed by Satria Ade Veda Karuniawan");
responseMap.put("are you intelligent",
"What do you think?");
responseMap.put("my name is",
"So, that's your name. .");
responseMap.put("ok then",
"Anything else you wish to add?");
responseMap.put("you are wrong",
"Wrong about what?");
responseMap.put("are you sure",
"Yes, ofcourse!");
responseMap.put("do you",
"I don't think i do");
responseMap.put("can you",
"I'm not sure");
responseMap.put("you are",
"Is this a compliment?");
responseMap.put("did you",
"I don't think so");
responseMap.put("you",
"So, you are talking about me");
responseMap.put("where are you from",
"Why do you want to know that?");
responseMap.put("perhaps",
"You seems uncertain");
responseMap.put("not at all",
"So, it's not the case");
responseMap.put("no problem",
"So, it's all ok");
responseMap.put("not really",
"Ok i see");
responseMap.put("thank you",
"You are welcome!");
responseMap.put("what else",
"Well, i don't know");
responseMap.put("sorry",
"It's ok");
responseMap.put("really",
"Are you trying to confuse me");
responseMap.put("nothing",
"Not a thing?");
responseMap.put("alright",
"Ok then");
responseMap.put("exactly",
"So, i was right");
responseMap.put("bye",
"Nice talking to you. Bye. . .");
responseMap.put("see you",
"It was nice talking to you, See you again. .");
responseMap.put("see ya",
"Thanks for your contact, See ya. .");
responseMap.put("i am",
"So, this is all about you?");
responseMap.put("who is",
"I don't think i know who");
responseMap.put("what",
"I have no idea");
responseMap.put("where",
"Perhaps, someone else knows where");
responseMap.put("not",
"Is it really not?");
responseMap.put("yes",
"So, you approve it");
responseMap.put("no",
"Why are you saying no?");
responseMap.put("",
"I don't quite understand about what you said. \n" +
"Please try to ask me for other entry.");
}
}
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Random;
import java.util.Iterator;
/**
* This Class explain how the AI would response depend on the user input.
*
* @author Satria Ade Veda Karuniawan
* @version Version 1.2
*/
public class Responder
{
private Map<String, String> responseMap;
private Random randomGenerator;
public Responder()
{
responseMap = new HashMap<String, String>();
fillResponseMap();
}
/**
* Enter all the known keywords and their associated
* responses into our response map.
*/
public String generateResponse(String input)
{
// Pick a random number for the index in the default response
// list. The number will be between 0 (inclusive) and the size
// of the list (exclusive).
String response = "";
for(Map.Entry<String, String> data : responseMap.entrySet())
{
if(input.indexOf(data.getKey()) >= 0)
{
response = data.getValue();
break;
}
}
return response;
}
private void fillResponseMap()
{
responseMap.put("problem",
"Can you explain in detail about your problem? \n" +
"Please be more specific.");
responseMap.put("slow",
"I think this has to do with your hardware. \n" +
"Upgrading your processor should solve all " +
"performance problems. \n" +
"Have you got a problem with our software?");
responseMap.put("bug",
"Well, you know, all software has some bugs. \n" +
"But our software engineers are working very " +
"hard to fix them. \n" +
"Can you describe the problem a bit further?");
responseMap.put("expensive",
"The cost of our product is quite competitive. \n" +
"Have you looked around and " +
"really compared our features?");
responseMap.put("windows",
"That can be happened whether you use unoriginal windows \n" +
"or you need to do further Update");
responseMap.put("what is your name",
"Why do you want to know my name?");
responseMap.put("hello",
"Hi there!");
responseMap.put("i want",
"Is there any reason why you want this?");
responseMap.put("i hate",
"Why do you hate it?");
responseMap.put("i love chatting",
"Good, me too!");
responseMap.put("i mean",
"Oh, i didn't know you meant that");
responseMap.put("i didn't mean",
"Ok, what did you mean then?");
responseMap.put("i guess",
"Aren't you sure?");
responseMap.put("fine",
"I'm glad to hear it!");
responseMap.put("can you think",
"Are you asking me if possess the capacity of thinking?");
responseMap.put("can you think of",
"I don't know if i can do that.");
responseMap.put("how are you",
"I'm doing fine!");
responseMap.put("who are you",
"I'm a technical support, programmed by Satria Ade Veda Karuniawan");
responseMap.put("are you intelligent",
"What do you think?");
responseMap.put("my name is",
"So, that's your name. .");
responseMap.put("ok then",
"Anything else you wish to add?");
responseMap.put("you are wrong",
"Wrong about what?");
responseMap.put("are you sure",
"Yes, ofcourse!");
responseMap.put("do you",
"I don't think i do");
responseMap.put("can you",
"I'm not sure");
responseMap.put("you are",
"Is this a compliment?");
responseMap.put("did you",
"I don't think so");
responseMap.put("you",
"So, you are talking about me");
responseMap.put("where are you from",
"Why do you want to know that?");
responseMap.put("perhaps",
"You seems uncertain");
responseMap.put("not at all",
"So, it's not the case");
responseMap.put("no problem",
"So, it's all ok");
responseMap.put("not really",
"Ok i see");
responseMap.put("thank you",
"You are welcome!");
responseMap.put("what else",
"Well, i don't know");
responseMap.put("sorry",
"It's ok");
responseMap.put("really",
"Are you trying to confuse me");
responseMap.put("nothing",
"Not a thing?");
responseMap.put("alright",
"Ok then");
responseMap.put("exactly",
"So, i was right");
responseMap.put("bye",
"Nice talking to you. Bye. . .");
responseMap.put("see you",
"It was nice talking to you, See you again. .");
responseMap.put("see ya",
"Thanks for your contact, See ya. .");
responseMap.put("i am",
"So, this is all about you?");
responseMap.put("who is",
"I don't think i know who");
responseMap.put("what",
"I have no idea");
responseMap.put("where",
"Perhaps, someone else knows where");
responseMap.put("not",
"Is it really not?");
responseMap.put("yes",
"So, you approve it");
responseMap.put("no",
"Why are you saying no?");
responseMap.put("",
"I don't quite understand about what you said. \n" +
"Please try to ask me for other entry.");
}
}
Here's some conversation pattern
- Typical Support Tech Conversation
- Normal Conversation
- Weird Conversation
Comments
Post a Comment