a dive into Neuro sama's code

fukurou

the supreme coder
ADMIN
this is an improved perchance chatbot code:

Code:
public class PerChance {/*
 * 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, UniqueItemSizeLimitedPriorityQueue> wordToList = new Hashtable<>();
    protected Random rand = new Random();
    private RegexUtil regexUtil = new RegexUtil();
    public PerChance() {
        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.extractAllRegexes("(\\w+)(?= #)", result);
        for (String strI : params) {
            UniqueItemSizeLimitedPriorityQueue temp = wordToList.get(strI);
            int n = temp.size();
            String s1 = temp.getRNDElement();
            result = result.replace(strI + " #", s1);
        }
        if (!result.contains("#")) {
            return result;
        } else {
            return clearRecursion(result);
        }
    }
    public void addParam(String category, String value){
        if(wordToList.containsKey(category)){
            wordToList.get(category).add(value);
        }
    }
}
in case you can't see it, it enables learning new parameters. the more parameters the more conversation option.
yes it needs to be put into context, to increase how human it feels. but I wanted to strip the code down to the bare minimum to explain how neuro sama speaks (what goes on under the hood).

so here is an example implementation:

Java:
public class PerChanceTest extends PerChance{
    public PerChanceTest() {
        super();
        sentences.add("I like to eat food # during time #. it's pretty good ");
        UniqueItemSizeLimitedPriorityQueue temp = new UniqueItemSizeLimitedPriorityQueue();
        temp.setLimit(3);
        wordToList.put("food", temp);
        // womenthing list
        temp.add("carrots");
        temp.add("hummus");
        temp.add("vegetables");
        temp.add("pasta");
        temp = new UniqueItemSizeLimitedPriorityQueue();
        temp.setLimit(3);
        wordToList.put("time", temp);
        // womenthing list
        temp.add("noon");
        temp.add("day time");
        temp.add("night time");
        temp.add("morning");
    }
}

main code:
Java:
PerChanceTest pct = new PerChanceTest();
        for (int i = 0; i < 10; i++) {
            System.out.println(pct.generateJoke());
        }

and output:
I like to eat vegetables during night time. it's pretty good
I like to eat pasta during morning. it's pretty good
I like to eat pasta during day time. it's pretty good
I like to eat pasta during day time. it's pretty good
I like to eat hummus during night time. it's pretty good
I like to eat hummus during night time. it's pretty good
I like to eat pasta during night time. it's pretty good
I like to eat pasta during night time. it's pretty good
I like to eat pasta during morning. it's pretty good
I like to eat hummus during morning. it's pretty good

Process finished with exit code 0
 
Top