battle programmers alliance
Would you like to react to this message? Create an account in a few clicks or log in to continue.


battle programming a forum for elite programmers with extreme will power to sharpen their skills
 
HomeGallerySearchRegisterLog in
 

 [auxiliary java class] InstaConvo a simple context sensitive chatbot

Go down 
AuthorMessage
kurosen
codding
codding
kurosen

Posts : 292
Join date : 2012-04-17

[auxiliary java class] InstaConvo a simple context sensitive chatbot Empty
PostSubject: [auxiliary java class] InstaConvo a simple context sensitive chatbot   [auxiliary java class] InstaConvo a simple context sensitive chatbot EmptyTue Dec 08, 2020 11:33 pm

Code:
package chobit;

import java.util.ArrayList;
import java.util.HashMap;

public class InstaConvo {
   private ZeroTimeGate timeGate = new ZeroTimeGate();
   private ArrayList<String> contexts = new ArrayList<String>();
   private String activeContext = "";
   private HashMap<String, String> pairs = new HashMap<>();

   public InstaConvo loadBullet(String context, String in1, String reply) {
      contexts.add(context);
      pairs.put(context + in1, reply);
      return this;
   }

   public InstaConvo loadBullet(String in1, String reply) {
      pairs.put(in1, reply);
      return this;
   }

   public String converse(String ear) {
      String temp = strContains(ear);
      if (!temp.isEmpty()) {
         activeContext = temp;
         timeGate.open(2);
         return pairs.getOrDefault(ear, "");
      }
      if (!timeGate.isOpen()) {
         activeContext = "";
      }
      return pairs.getOrDefault(activeContext + ear, "");
   }

   private String strContains(String ear) {
      for (String temp : contexts) {
         if (ear.contains(temp)) {
            return temp;
         }
      }
      return "";
   }

   private void clearMemory() {
      pairs.clear();
      contexts.clear();
   }
}

input example:

Code:
instaConvo.loadBullet("hi", "hello").loadBullet("bitch", "how are you", "non of your business")
            .loadBullet("how are you", "I am good");
      System.out.println(instaConvo.converse("how are you"));
      System.out.println(instaConvo.converse("cunt bitch"));
      System.out.println(instaConvo.converse("how are you"));

output :

I am good

non of your business
Back to top Go down
 
[auxiliary java class] InstaConvo a simple context sensitive chatbot
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
battle programmers alliance :: battle programming alliance :: the LivinGrimoire-
Jump to: