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

battle programmers allianceLog in

the LivinGrimoire Artificial General Intelligence software design pattern forum

descriptionchat module with example use Emptychat module with example use

more_horiz

Code:

public class PerChance {/*
 * extend me and add sentences and lists for parameters in the sentences in the
 * sub classes c'tor.
  replicate speech paterns, generate movie scripts or books and enjoy
 */
    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);
            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);
        }
    }
    public void addParam(AXKeyValuePair kv){
        if(wordToList.containsKey(kv.getKey())){
            wordToList.get(kv.getKey()).add(kv.getValue());
        }
    }
}


Code:

public class PerChanceTest extends PerChance{
    public PerChanceTest() {
        super();
        sentences.add("here is a  salad vegi1 #, vegi2 # and herb #.");
        sentences.add("how about this salad vegi1 #, vegi2 # and herb #. it goes well with tuna fish");
        UniqueItemSizeLimitedPriorityQueue temp = new UniqueItemSizeLimitedPriorityQueue();
        temp.setLimit(3);
        wordToList.put("vegi1", temp);
        temp = new UniqueItemSizeLimitedPriorityQueue();
        temp.setLimit(3);
        wordToList.put("vegi2", temp);
        temp = new UniqueItemSizeLimitedPriorityQueue();
        temp.setLimit(3);
        wordToList.put("herb", temp);
    }
}


main

Code:

PerChanceTest pct = new PerChanceTest();
        pct.addParam("vegi1", "tomato");
        pct.addParam("vegi1", "cucmber");
        pct.addParam("vegi1", "lettuce");
        pct.addParam("vegi2", "onion");
        pct.addParam("vegi2", "pickle");
        pct.addParam("vegi2", "purple onion");
        pct.addParam("herb", "parcely");
        pct.addParam("herb", "cpriander");
        pct.addParam("herb", "irit");
        for (int i = 0; i < 10; i++) {
            System.out.println(pct.generateJoke());
        }


output:
here is a salad cucmber, purple onion and cpriander.
here is a salad tomato, purple onion and irit.
here is a salad lettuce, pickle and cpriander.
how about this salad tomato, purple onion and cpriander. it goes well with tuna fish
how about this salad lettuce, pickle and irit. it goes well with tuna fish
how about this salad lettuce, pickle and parcely. it goes well with tuna fish
how about this salad tomato, onion and cpriander. it goes well with tuna fish
how about this salad cucmber, pickle and parcely. it goes well with tuna fish
here is a salad cucmber, purple onion and parcely.
here is a salad cucmber, purple onion and irit.

Process finished with exit code 0

:s43: new params can be learned during run time (hence the input filter to make it even simpler)

descriptionchat module with example use EmptyRe: chat module with example use

more_horiz
if the amount of sentences is x, and each param list is marked as a1...an with y elements per list.
how many senstence options are there?

x*(y^n)
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply