''' DISKILLUTILS CLASS '''
class DISkillUtils:
# alg part based algorithm building methods
# var args param
def algBuilder(self, *itte: Mutatable) -> Algorithm:
# returns an algorithm built with the algPart varargs
algParts1: list[Mutatable] = []
for i in range(0, len(itte)):
algParts1.append(itte[i])
algorithm: Algorithm = Algorithm(algParts1)
return algorithm
# String based algorithm building methods
def simpleVerbatimAlgorithm(self, *sayThis) -> Algorithm:
# returns alg that says the word string (sayThis)
return self.algBuilder(APVerbatim(*sayThis))
# String part based algorithm building methods with cloudian (shallow ref object to inform on alg completion)
def simpleCloudiandVerbatimAlgorithm(self, cldBool: CldBool, *sayThis) -> Algorithm:
# returns alg that says the word string (sayThis)
return self.algBuilder(APCldVerbatim(cldBool, *sayThis))
def strContainsList(self, str1: str, items: list[str]) -> str:
# returns the 1st match between words in a string and values in a list.
for temp in items:
if (str1.count(temp) > 0):
return temp
return ""
''' DISKILLV2 CLASS '''
class DiSkillV2:
def __init__(self):
# The variables start with an underscore (_) because they are protected
self._kokoro = Kokoro(AbsDictionaryDB()) # consciousness, shallow ref class to enable interskill communications
self._diSkillUtils = DISkillUtils()
self._outAlg = None # skills output
self._outpAlgPriority: int = -1 # defcon 1->5
# skill triggers and algorithmic logic
def input(self, ear: str, skin: str, eye: str):
pass
# extraction of skill algorithm to run (if there is one)
def output(self, noiron: Neuron):
if self._outAlg is not None:
noiron.insertAlg(self._outpAlgPriority, self._outAlg)
self._outpAlgPriority = -1
self._outAlg = None
def setKokoro(self, kokoro: Kokoro):
# use this for telepathic communication between different chobits objects
self._kokoro = kokoro
# in skill algorithm building shortcut methods:
def setVerbatimAlg(self, priority: int, *sayThis: str):
# build a simple output algorithm to speak string by string per think cycle
# uses varargs param
temp:list[str] = []
for i in range(0,len(sayThis)):
temp.append(sayThis[i])
self._outAlg = self._diSkillUtils.simpleVerbatimAlgorithm(temp)
self._outpAlgPriority = priority # 1->5 1 is the highest algorithm priority
def setVebatimAlgFromList(self, priority: int, sayThis: list[str]):
# build a simple output algorithm to speak string by string per think cycle
# uses list param
self._outAlg = self._diSkillUtils.algBuilder(APVerbatim(sayThis))
self._outpAlgPriority = priority # 1->5 1 is the highest algorithm priority
def algPartsFusion(self, priority: int, *algParts: Mutatable):
# build a custom algorithm out of a chain of algorithm parts(actions)
self._outAlg = self._diSkillUtils.algBuilder(algParts)
self._outpAlgPriority = priority # 1->5 1 is the highest algorithm priority
class TODOListManager:
'''manages to do tasks.
q1 tasks are mentioned once, and forgotten
backup tasks are the memory of recently mentioned tasks'''
def __init__(self, todoLim: int):
self._q1: UniqueItemSizeLimitedPriorityQueue = UniqueItemSizeLimitedPriorityQueue(todoLim)
self._backup: UniqueItemSizeLimitedPriorityQueue = UniqueItemSizeLimitedPriorityQueue(todoLim)
def addTask(self, e1: str):
self._q1.insert(e1)
def getTask(self) -> str:
temp: str = self._q1.poll()
if not temp == "":
self._backup.insert(temp)
return temp
def getOldTask(self):
# task graveyard (tasks you've tackled already)
return self._backup.getRNDElement()
def clearAllTasks(self):
self._q1.clear()
self._backup.clear()
def clearTask(self, task: str):
self._q1.removeItem(task)
self._backup.removeItem(task)
def containsTask(self, task: str) -> bool:
return self._backup.contains(task)
package skills;
import AXJava.*;
import LivinGrimoire.APVerbatim;
import LivinGrimoire.DISkillUtils;
import LivinGrimoire.DiSkillV2;
import java.util.ArrayList;
public class DiHabit extends DiSkillV2 {
/*1 *habit*
set: i should x
get: random habit
engage : x completed
clear : clear habits
2 *bad habit*
set: i must not x
get: random bad habit
engage: x completed
clear: clear bad habits
3 *dailies*
set: i out to x
get: random daily
engage: x completed
clear: clear dailies
4 *preps or weekend tasks*
set: i have to x
get: random prep or random weekend
engage: x completed
clear: clear preps or clear weekends
5 *expirations*
set: i got to x
get: random expiration or random expirations
(will return all of then)
engage: none
clear: clear expirations
6 *to do*
set: i need to
get: random task (for new ToDos)
or random to do (for completed to dos)
engage: auto
clear: clear tasks or clear task or clear to do"*/
/*setter params*/
// habit params
private UniqueItemSizeLimitedPriorityQueue habitsPositive = new UniqueItemSizeLimitedPriorityQueue();
private AXCmdBreaker habitP = new AXCmdBreaker("i should");
private String temp = "";
// bad habits
private UniqueItemSizeLimitedPriorityQueue habitsNegative = new UniqueItemSizeLimitedPriorityQueue();
private AXCmdBreaker habitN = new AXCmdBreaker("i must not");
// dailies
private UniqueItemSizeLimitedPriorityQueue dailies = new UniqueItemSizeLimitedPriorityQueue();
private AXCmdBreaker dailyCmdBreaker = new AXCmdBreaker("i out to");
// weekends
private UniqueItemSizeLimitedPriorityQueue weekends = new UniqueItemSizeLimitedPriorityQueue();
private AXCmdBreaker weekendCmdBreaker = new AXCmdBreaker("i have to");
// expirations
private UniqueItemSizeLimitedPriorityQueue expirations = new UniqueItemSizeLimitedPriorityQueue();
private AXCmdBreaker expirationsCmdBreaker = new AXCmdBreaker("i got to");
// to-do list
private TODOListManager todo = new TODOListManager(5);
private AXCmdBreaker toDoCmdBreaker = new AXCmdBreaker("i need to");
private AXCmdBreaker clearCmdBreaker = new AXCmdBreaker("clear");
//getter param
private AXCmdBreaker getterCmdBreaker = new AXCmdBreaker("random");
private AXStrOrDefault strOrDefault = new AXStrOrDefault();
// gamification modules for shallow ref in other skills
private AXGamification gamification = new AXGamification();
private AXGamification punishments = new AXGamification();
public DiHabit() {
habitsPositive.setLimit(15);
habitsNegative.setLimit(5);
dailies.setLimit(3);
weekends.setLimit(3);
expirations.setLimit(3);
}
public AXGamification getGamification() {
return gamification;
}
public AXGamification getPunishments() {
return punishments;
}
@Override
public void input(String ear, String skin, String eye) {
if (ear.isEmpty()){return;}
// setters
if (ear.contains("i")){
temp = habitP.extractCmdParam(ear);
if (!temp.isEmpty()){
habitsPositive.add(temp);
temp = "";
setVerbatimAlg(4,"habit registered");
return;
}
temp = habitN.extractCmdParam(ear);
if (!temp.isEmpty()){
habitsNegative.add(temp);
temp = "";
setVerbatimAlg(4,"bad habit registered");
return;
}
temp = dailyCmdBreaker.extractCmdParam(ear);
if (!temp.isEmpty()){
dailies.add(temp);
temp = "";
setVerbatimAlg(4,"daily registered");
return;
}
temp = weekendCmdBreaker.extractCmdParam(ear);
if (!temp.isEmpty()){
weekends.add(temp);
temp = "";
setVerbatimAlg(4,"prep registered");
return;
}
temp = expirationsCmdBreaker.extractCmdParam(ear);
if (!temp.isEmpty()){
expirations.add(temp);
temp = "";
setVerbatimAlg(4,"expiration registered");
return;
}
temp = toDoCmdBreaker.extractCmdParam(ear);
if (!temp.isEmpty()){
todo.addTask(temp);
temp = "";
setVerbatimAlg(4,"task registered");
return;
}
}
// getters
temp = getterCmdBreaker.extractCmdParam(ear);
if (!temp.isEmpty()){
switch (temp){
case "habit":
setVerbatimAlg(4,strOrDefault.getOrDefault(habitsPositive.getRNDElement(),"no habits registered"));
return;
case "bad habit":
setVerbatimAlg(4,strOrDefault.getOrDefault(habitsNegative.getRNDElement(),"no bad habits registered"));
return;
case "daily":
setVerbatimAlg(4,strOrDefault.getOrDefault(dailies.getRNDElement(),"no dailies registered"));
return;
case "weekend": case "prep":
setVerbatimAlg(4,strOrDefault.getOrDefault(weekends.getRNDElement(),"no preps registered"));
return;
case "expirations":case "expiration":
if(expirations.getAsList().isEmpty()){
setVerbatimAlg(4,"no expirations registered");
return;
}
setVerbatimAlgFromList(4,expirations.getAsList());
return;
case "task":
setVerbatimAlg(4,strOrDefault.getOrDefault(todo.getTask(),"no tasks registered"));
return;
case "to do":
setVerbatimAlg(4,strOrDefault.getOrDefault(todo.getOldTask(),"no tasks registered"));
return;
}
}
// engagers
if(ear.contains("completed")){
if (!(diSkillUtils.strContainsList(ear,habitsPositive.getAsList()).isEmpty())){
gamification.increment();
setVerbatimAlg(4,"good boy");
return;
}
if (!(diSkillUtils.strContainsList(ear,habitsNegative.getAsList()).isEmpty())){
punishments.increment();
setVerbatimAlg(4,"bad boy");
return;
}
if (!(diSkillUtils.strContainsList(ear,dailies.getAsList()).isEmpty())){
gamification.increment();
setVerbatimAlg(4,"daily engaged");
return;
}
if (!(diSkillUtils.strContainsList(ear,weekends.getAsList()).isEmpty())){
setVerbatimAlg(4,"prep engaged");
return;
}
// expiration gamification redacted
}
// clear specific field
switch(ear) {
case "clear habits":
habitsPositive.clear();
setVerbatimAlg(4,"habits cleared");
break;
case "clear bad habits":
habitsNegative.clear();
setVerbatimAlg(4,"bad habits cleared");
break;
case "clear dailies":
dailies.clear();
setVerbatimAlg(4,"dailies cleared");
break;
case "clear preps": case "clear weekends":
weekends.clear();
setVerbatimAlg(4,"preps cleared");
break;
case "clear expirations":
expirations.clear();
setVerbatimAlg(4,"expirations cleared");
break;
case "clear tasks":case "clear task":case "clear to do":
todo.clearAllTasks();
setVerbatimAlg(4,"tasks cleared");
break;
case "clear all habits":
habitsPositive.clear();
habitsNegative.clear();
dailies.clear();
weekends.clear();
expirations.clear();
todo.clearAllTasks();
setVerbatimAlg(4,"all habits cleared");
break;
default:
if (ear.contains("clear")){
temp = clearCmdBreaker.extractCmdParam(ear);
if(todo.containsTask(temp)){
todo.clearTask(temp);
setVerbatimAlg(4,temp +" task cleared");
temp = "";
}
}
}
}
}