Bukan Alexa ataupun Siri, Program Sederhana dengan Ide Awal dari Eliza!

Hari ini saya belajar bagaimana Artificial Intelligent awalnya ditemukan. Bukan langsung melejit menjadi Siri ataupun Alexa, awal mulanya adalah sebuah technical support bernama Eliza. Input dan outputnya berupa text dimana jika kita mengetikkan sesuatu, secara otomatis akan dibalas dengan hal yang terkait dengan apa yang ditanyakan.
Program yang saya buat di kelas ini merupakan program sederhananya dimana ketika user mengetikkan sesuatu, akan dibalas dengan jawaban-jawaban acak yang sudah saya siapkan dalam program.

Tampilan

 Class Diagram

 
Start Interface 


 
Interaction - Random Response

Close Interface

Source Code

Responder

 import java.util.ArrayList;  
 import java.util.Random;  
 /**  
  * The responder class represents a response generator object. It is  
  * used to generate an automatic response.  
  * This is the second version of this class. This time, we generate   
  * some random behavior by randomly selecting a phrase from a predefined  
  * list of responses.  
  */  
 public class Responder  
 {  
   private Random randomGenerator;  
   private ArrayList<String> responses;  
   /**  
    * Construct a Responder  
    */  
   public Responder()  
   {  
     randomGenerator = new Random();  
     responses = new ArrayList<String>();  
     fillResponses();  
   }  
   /**  
    * Generate a response.  
    *   
    * @return A string that should be displayed as the response  
    */  
   public String generateResponse()  
   {  
     // 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).  
     int index = randomGenerator.nextInt(responses.size());  
     return responses.get(index);  
   }  
   /**  
    * Build up a list of default responses from which we can pick one  
    * if we don't know what else to say.  
    */  
   private void fillResponses()  
   {  
     responses.add("That sounds odd. Could you describe that problem in more detail?");  
     responses.add("No other customer has ever complained about this before. \n" +  
            "What is your system configuration?");  
     responses.add("That sounds interesting. Tell me more...");  
     responses.add("I need a bit more information on that.");  
     responses.add("Have you checked that you do not have a dll conflict?");  
     responses.add("That is explained in the manual. Have you read the manual?");  
     responses.add("Your description is a bit wishy-washy. Have you got an expert\n" +  
            "there with you who could describe this more precisely?");  
     responses.add("That's not a bug, it's a feature!");  
     responses.add("Could you elaborate on that?");  
   }  
 }  

InputReader

 import java.util.HashSet;  
 import java.util.Scanner;  
 /**  
  * InputReader reads typed text input from the standard text terminal.   
  * The text typed by a user is then chopped into words, and a set of words   
  * is provided.  
  */  
 public class InputReader  
 {  
   private Scanner reader;  
   /**  
    * Create a new InputReader that reads text from the text terminal.  
    */  
   public InputReader()  
   {  
     reader = new Scanner(System.in);  
   }  
   /**  
    * Read a line of text from standard input (the text terminal),  
    * and return it as a String.  
    *  
    * @return A String typed by the user.  
    */  
   public String getInput()  
   {  
     System.out.print("> ");  
     String inputLine = reader.nextLine();  
     return inputLine;  
   }  
 }  

SupportSystem

 /**  
  * This class implements a technical support system.  
  * It's the top-level class in this project.  
  * The support system communicates via text input/output in the text terminal.  
  * This class uses an object of class InputReader to read input from the user and  
  * an object of class Responder to generate responses.  
  * It contains a loop that repeatedly reads input and generates output until  
  * the user wants to leave.  
  */  
 public class SupportSystem  
 {  
   private InputReader reader;  
   private Responder responder;  
   //Creates a technical support system  
   public SupportSystem(){  
     reader = new InputReader();  
     responder = new Responder();  
   }  
   /**  
    * 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;  
     printWelcome();  
     while(!finished){  
       String input = reader.getInput();  
       if(input.startsWith("bye")){  
         finished = true;  
       }  
       else{  
       String response = responder.generateResponse();  
       System.out.println(response);  
       }  
     }  
     printGoodbye();  
   }  
   /**  
    * Print a welcome message to the screen  
    */  
   private void printWelcome(){  
     System.out.println("Welcome to the DodgySoft 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.");  
   }  
   /**  
    * Print a good-bye message to the screen.  
    */  
   private void printGoodbye(){  
     System.out.println("Nice talking to you. Bye ...");  
   }  
 }  

Komentar

Postingan populer dari blog ini

Halaman Berita? HTML & CSS!

Menggunakan CodeIgniter!!

Sistem Informasi Cinema 21 - APSI