class DiSkillUtils{
// alg part based algorithm building methods
// var args param
func algBuilder(algParts:Mutatable...)->Algorithm{
// returns an algorithm built with the algPart varargs
var algParts1: Array<Mutatable> = [Mutatable]()
for algPart in algParts{
algParts1.append(algPart)
}
let result:Algorithm = Algorithm(algParts: algParts1)
return result
}
// String based algorithm building methods
func simpleVerbatimAlgorithm(algMarker:String, sayThis:String...)->Algorithm{
// returns an algorithm that says the sayThis Strings verbatim per think cycle
return algBuilder(algParts: APVerbatim(sentences: sayThis))
}
// String part based algorithm building methods with cloudian (shallow ref object to inform on alg completion)
func simpleCloudianVerbatimAlgorithm(cldBool:CldBool, algMarker:String, sayThis:String...)->Algorithm{
/// returns an algorithm that says the sayThis Strings verbatim per think cycle
return algBuilder(algParts: APCldVerbatim(sentences: sayThis, cldBool: cldBool))
}
func stringContainsListElement(str1:String, items:Array<String>)->String{
// returns the 1st match between words in a string and values in a list.
for item in items{
if str1.contains(item){return item}
}
return ""
}
}
open class DiSkillV2{
private(set) var kokoro:Kokoro = Kokoro(absDictionaryDB: AbsDictionaryDB())
let diSkillUtills:DiSkillUtils = DiSkillUtils()
var outAlg:Algorithm? = nil
var outpAlgPriority:Int = -1 // defcon 1->5
init() {}
func input(ear:String, skin:String, eye:String){
}
func output(noiron:Neuron){
if let notNilAlg = self.outAlg{
noiron.insertAlg(priority: outpAlgPriority, alg: notNilAlg)
self.outpAlgPriority = -1
self.outAlg = nil
}
}
func setKokoro(kokoro:Kokoro){
// use this for telepathic communication between different chobits objects
self.kokoro = kokoro
}
// in skill algorithm building shortcut methods:
func setVerbatimAlgFromList(priority:Int, sayThis: Array<String>) {
// build a simple output algorithm to speak string by string per think cycle
// uses list param
self.outAlg = diSkillUtills.algBuilder(algParts: APVerbatim(sentences: sayThis))
self.outpAlgPriority = priority // 1->5 1 is the highest algorithm priority
}
func setVerbatimAlg(priority:Int, sayThis:String...) {
// build a simple output algorithm to speak string by string per think cycle
// uses varargs param
var temp: Array<String> = [String]()
for strTemp in sayThis{
temp.append(strTemp)
}
setVerbatimAlgFromList(priority: priority, sayThis: temp)
}
func algPartsFusion(priority:Int, algParts: Mutatable...) {
var algParts1: Array<Mutatable> = [Mutatable]()
for algPart in algParts{
algParts1.append(algPart)
}
let result:Algorithm = Algorithm(algParts: algParts1)
self.outAlg = result
self.outpAlgPriority = priority // 1->5 1 is the highest algorithm priority
}
}
class DiHelloWorld:DiSkillV2{
// hello world skill for testing purposes
override func input(ear: String, skin: String, eye: String) {
switch (ear) {
case "hello":
super.setVerbatimAlg(priority: 4, sayThis: "hello world")
case "incantation 0":
// cancel running algorithm entirely at any alg part point
super.setVerbatimAlg(priority: 4, sayThis: "fly","bless of magic caster","infinity wall", "magic ward holy","life essence")
default:
return
}
}
}
class TODOListManager{
/* manages to do tasks.
q1 tasks are mentioned once, and forgotten
backup tasks are the memory of recently mentioned tasks
* */
var q1:UniqueItemSizeLimitedPriorityQueue = UniqueItemSizeLimitedPriorityQueue()
var backup:UniqueItemSizeLimitedPriorityQueue = UniqueItemSizeLimitedPriorityQueue()
init(todoLim:Int) {
self.q1.setLimit(lim: todoLim)
self.backup.setLimit(lim: todoLim)
}
func addTask(e1:String){
q1.input(in1: e1)
}
func getTask()->String{
let temp:String = self.q1.poll()
if !temp.isEmpty {backup.input(in1: temp)}
return temp
}
func getOldAnTask()->String{
// task graveyard (tasks you've tackled already)
return backup.getRndItem()
}
func clearAllTasks(){
q1.clearData()
backup.clearData()
}
func containsTask(task:String) -> Bool {
return backup.contains(str: task)
}
}