Moti Barski super


Posts : 498 Join date : 2011-08-02
 | Subject: reverse engineered the perchance chatbot Thu Jan 02, 2020 9:30 pm | |
| it not A.I but it had an A.I vibe to it and maybe the brain also has something like it and it was a fun little puzzle to solve - Code:
-
import java.util.ArrayList; import java.util.Hashtable; import java.util.Random;
public class Joker { /* * extend me and add sentences and lists for parameters in the sentences in the * sub classes c'tor. see JokerIncel class for exammple see Joker Util class for * editing a large amount of data faster B4 adding it in the subclasses c'tor */ protected ArrayList<String> sentences = new ArrayList<String>(); protected Hashtable<String, ArrayList<String>> wordToList = new Hashtable<>(); protected Random rand = new Random(); private RegexUtil regexUtil = new RegexUtil(); public Joker() { super(); }
public String generateJoke() { int x = rand.nextInt(sentences.size()); String result = sentences.get(x); return clearRecursion(result); }
private String clearRecursion(String result) { int x; ArrayList<String> params = new ArrayList<String>(); params = regexUtil.regexChecker2("(\\w+)(?= #)", result); for (String strI : params) { ArrayList<String> temp = wordToList.get(strI); int n = temp.size(); x = rand.nextInt(n); String s1 = temp.get(x); result = result.replace(strI + " #", s1); } if (!result.contains("#")) { return result; } else { return clearRecursion(result); } // return ""; } } _________________ MB over and out  | |
|