breakfast suggestor :
salad suggestor with database for save load :
DiSaladSuggestor (java) AGI skill fir the livingrimoir software design pattern :
:chii: :foid: :krebskulm:
Code:
package chobit;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
public class SaladSuggestor {
private HashSet<String> ingredientsSet = new HashSet();
public SaladSuggestor() {
ingredientsSet.add("tuna mayo and hot pepper");
ingredientsSet.add("omolet");
ingredientsSet.add("avocado and fried shrooms");
ingredientsSet.add("hummus with shrooms");
ingredientsSet.add("hummus with zhug");
ingredientsSet.add("egg salad with mayo and dill");
ingredientsSet.add("shakshuka");
ingredientsSet.add("tahini cookies with green tea");
ingredientsSet.add("pesto pasta");
}
public String suggestSalad() {
// anti glitch variety size
ArrayList<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < ingredientsSet.size(); i++) {
list.add(new Integer(i));
}
Collections.shuffle(list);
int x = list.get(0);
System.out.println(getIngredient(x));
return "";
}
private String getIngredient(int num) {
// antiglitch
String[] ingredients = new String[ingredientsSet.size()];
ingredientsSet.toArray(ingredients);
return ingredients[num];
}
}
salad suggestor with database for save load :
Code:
package chobit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
public class SaladSuggestorWDB {
private HashSet<String> ingredientsSet = new HashSet();
private HashSet<String> vegiSet = new HashSet();
public SaladSuggestorWDB(String ingredientsString, String vegiString) {
if (ingredientsString.isEmpty() || ingredientsString.equals("null")) {
defaultValues();
return;
}
// c'tor from strings of DB
String[] strParts = ingredientsString.split(",");
// convert array to the List using asList method
List<String> listParts = Arrays.asList(strParts);
// create HashSet from the List using constructor
ingredientsSet = new HashSet<String>(listParts);
// vegiList population :
String[] strParts2 = vegiString.split(",");
// convert array to the List using asList method
List<String> listParts2 = Arrays.asList(strParts2);
// create HashSet from the List using constructor
vegiSet = new HashSet<String>(listParts2);
}
public String defaultValues() {
ingredientsSet = new HashSet();
vegiSet = new HashSet();
ingredientsSet.add("tomatoe");
ingredientsSet.add("cucumber");
ingredientsSet.add("onion");
ingredientsSet.add("carrot");
vegiSet.add("tomatoe");
vegiSet.add("cucumber");
vegiSet.add("onion");
vegiSet.add("carrot");
return "null";
}
public String suggestSalad(int variety) {
// anti glitch variety size
if (variety > ingredientsSet.size() || variety < 1) {
variety = ingredientsSet.size();
}
// get unique random numbers :
ArrayList<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < ingredientsSet.size(); i++) {
list.add(new Integer(i));
}
Collections.shuffle(list);
String result = "";
// convert resulting unique numbers to salad ingredients
for (int i = 0; i < variety - 1; i++) {
int x = list.get(i);
result += getIngredient(x) + " ";
}
int x = list.get(variety - 1);
result += "and " + getIngredient(x);
return result;
}
private String getIngredient(int num) {
String[] ingredients = new String[ingredientsSet.size()];
ingredientsSet.toArray(ingredients);
return ingredients[num];
}
public String addVegi(String vegi) {
vegiSet.add(vegi);
return hashsetToString(vegiSet);
}
public String removeVegi(String vegi) {
vegiSet.remove(vegi);
return hashsetToString(vegiSet);
}
public String addIngredient(String vegi) {
if (!vegiSet.contains(vegi)) {
return "";
}
ingredientsSet.add(vegi);
return hashsetToString(ingredientsSet);
}
public String removeIngredient(String vegi) {
ingredientsSet.remove(vegi);
return hashsetToString(ingredientsSet);
}
private String hashsetToString(HashSet<String> hs) {
String result = "";
for (String string : hs) {
result += ",";
result += string;
}
result = result.replaceFirst(",", "");
return result;
}
}
DiSaladSuggestor (java) AGI skill fir the livingrimoir software design pattern :
Code:
package com.yotamarker.lgkotlin1;
public class DiSaladSuggestor extends DISkill {
private int variety = 3;
private DISkillUtils diSkillUtils = new DISkillUtils();
private RegexUtil regexUtil = new RegexUtil();
private SaladSuggestorWDB saladSuggestorWDB;
private SaladSuggestor saladSuggestor = new SaladSuggestor();
private String outStr = "";
public DiSaladSuggestor(Kokoro kokoro) {
super(kokoro);
String v1 = kokoro.grimoireMemento.simpleLoad("salad_db");
String v2 = kokoro.grimoireMemento.simpleLoad("veg_db");
saladSuggestorWDB = new SaladSuggestorWDB(v1, v2);
}
@Override
public void input(String ear, String skin, String eye) {
/*
* c'tor(Str: ingredients,Str: vegilist) default() suggestSalad(int variety)
* addVegi(String vegi) removeVegi(String vegi) addIngredient(String vegi)
* removeIngredient(String vegi)
*/
if (ear.isEmpty()) {
return;
}
if (ear.equals("suggest a breakfast")) {
outStr = saladSuggestor.suggestSalad();
return;
}
if (ear.contains("elements")) {
String numTemp = regexUtil.numberRegex(ear);
if (numTemp.isEmpty()) {
return;
}
variety = Integer.valueOf(numTemp);
outStr = "ok";
return;
}
if (ear.equals("suggest a salad")) {
outStr = saladSuggestorWDB.suggestSalad(variety);
return;
}
if (ear.equals("default salad")) {
variety = 3;
outStr = "yes you majesty";
saladSuggestorWDB.defaultValues();
kokoro.grimoireMemento.simpleSave("salad_db","");
kokoro.grimoireMemento.simpleSave("veg_db","");
return;
}
if (ear.contains("is a vegetable")) {
String veg1 = regexUtil.firstWord(ear);
kokoro.grimoireMemento.simpleSave("veg_db",saladSuggestorWDB.addVegi(veg1));
outStr = "yes";
return;
}
if (ear.contains("is not a vegetable")) {
String veg1 = regexUtil.firstWord(ear);
kokoro.grimoireMemento.simpleSave("veg_db",saladSuggestorWDB.removeVegi(veg1));
outStr = "bwahaha";
return;
}
if (ear.contains("does not taste good")) {
String veg1 = regexUtil.firstWord(ear);
kokoro.grimoireMemento.simpleSave("salad_db",saladSuggestorWDB.removeIngredient(veg1));
outStr = "chii";
return;
}
if (ear.contains("tastes good")||ear.contains("taste good")) {
String veg1 = regexUtil.firstWord(ear);
kokoro.grimoireMemento.simpleSave("salad_db",saladSuggestorWDB.addIngredient(veg1));
outStr = "ok";
return;
}
}
@Override
public void output(Neuron noiron) {
if (!outStr.isEmpty()) {
String temp = outStr;
outStr = "";
noiron.algParts.add(diSkillUtils.verbatimGorithm("salad", new APVerbatim(temp)));
}
}
}
:chii: :foid: :krebskulm: