public class Magic8Ball {
private Responder questions = new Responder();
private Responder answers = new Responder();
public void setQuestions(Responder questions) {
this.questions = questions;
}
public void setAnswers(Responder answers) {
this.answers = answers;
}
public Responder getQuestions() {
return questions;
}
public Responder getAnswers() {
return answers;
}
public Magic8Ball() {
// answers :
// Affirmative Answers
answers.addResponse("It is certain");
answers.addResponse("It is decidedly so");
answers.addResponse("Without a doubt");
answers.addResponse("Yes definitely");
answers.addResponse("You may rely on it");
answers.addResponse("As I see it, yes");
answers.addResponse("Most likely");
answers.addResponse("Outlook good");
answers.addResponse("Yes");
answers.addResponse("Signs point to yes");
// Non – Committal Answers
answers.addResponse("Reply hazy, try again");
answers.addResponse("Ask again later");
answers.addResponse("Better not tell you now");
answers.addResponse("Cannot predict now");
answers.addResponse("Concentrate and ask again");
// Negative Answers
answers.addResponse("Don’t count on it");
answers.addResponse("My reply is no");
answers.addResponse("My sources say no");
answers.addResponse("Outlook not so good");
answers.addResponse("Very doubtful");
// questions :
questions = new Responder("will i", "can i expect", "should i", "may i","is it a good idea","will it be a good idea for me to","is it possible","future hold","will there be");
}
public Boolean engage(String ear){
if (ear.isEmpty()){return false;}
if (questions.strContainsResponse(ear)){return true;}
// String temp = new RegexUtil().firstWord(ear);
// if (temp.equals("does")||temp.equals("is")){return true;}
return false;
}
public String reply(){return answers.getAResponse();}
}
class Magic8Ball {
private var questions = Responder()
private var answers = Responder()
func setQuestions(_ questions: Responder) {
self.questions = questions
}
func setAnswers(_ answers: Responder) {
self.answers = answers
}
func getQuestions() -> Responder {
return questions
}
func getAnswers() -> Responder {
return answers
}
init() {
answers.addResponse("It is certain")
answers.addResponse("It is decidedly so")
answers.addResponse("Without a doubt")
answers.addResponse("Yes definitely")
answers.addResponse("You may rely on it")
answers.addResponse("As I see it, yes")
answers.addResponse("Most likely")
answers.addResponse("Outlook good")
answers.addResponse("Yes")
answers.addResponse("Signs point to yes")
answers.addResponse("Reply hazy, try again")
answers.addResponse("Ask again later")
answers.addResponse("Better not tell you now")
answers.addResponse("Cannot predict now")
answers.addResponse("Concentrate and ask again")
answers.addResponse("Don’t count on it")
answers.addResponse("My reply is no")
answers.addResponse("My sources say no")
answers.addResponse("Outlook not so good")
answers.addResponse("Very doubtful")
questions = Responder(responses: ["will i", "can i expect", "should i", "may i","is it a good idea","will it be a good idea for me to","is it possible","future hold","will there be"])
}
func engage(_ ear: String) -> Bool {
if ear.isEmpty() {
return false
}
if questions.strContainsResponse(ear) {
return true
}
return false
}
func reply() -> String {
return answers.getAResponse()
}
}
import Foundation
class AXShoutOut {
private var isActive: Bool = false
let handshake = Responder()
func activate() {
isActive = true
}
func engage(ear: String) -> Bool {
if ear.isEmpty {
return false
}
if isActive {
if handshake.strContainsResponse(ear) {
isActive = false
return true
}
}
isActive = false
return false
}
}
class AXHandshake {
private var trgTime = TrgTime()
private var trgTolerance = TrgTolerance(10)
private var shoutOut = AXShoutOut()
private var user_name = "user"
private var dripper = PercentDripper()
init() {
shoutOut.handshake = Responder("what", "yes", "i am here")
}
func setTimeStamp(_ time_stamp: String) -> AXHandshake {
trgTime.setTime(time_stamp)
return self
}
func setShoutOutLim(_ lim: Int) -> AXHandshake {
trgTolerance.setMaxrepeats(lim)
return self
}
func setHandShake(_ responder: Responder) -> AXHandshake {
shoutOut.handshake = responder
return self
}
func setDripperPercent(_ n: Int) -> AXHandshake {
dripper.setLimis(n)
return self
}
func setUser_name(_ user_name: String) {
self.user_name = user_name
}
func getUser_name() -> String {
return user_name
}
func engage(_ ear: String) -> Bool {
if trgTime.alarm() {
trgTolerance.reset()
}
if shoutOut.engage(ear) {
trgTolerance.disable()
return true
}
return false
}
func trigger() -> Bool {
if trgTolerance.trigger() {
if dripper.drip() {
shoutOut.activate()
return true
}
}
return false
}
}
class Magic8Ball {
private var questions:Responder = Responder()
private var answers:Responder = Responder()
func setQuestions(_ questions: Responder) {
self.questions = questions
}
func setAnswers(_ answers: Responder) {
self.answers = answers
}
func getQuestions() -> Responder {
return questions
}
func getAnswers() -> Responder {
return answers
}
init() {
answers.addResponse(s1: "It is certain")
answers.addResponse(s1: "It is decidedly so")
answers.addResponse(s1: "Without a doubt")
answers.addResponse(s1: "Yes definitely")
answers.addResponse(s1: "You may rely on it")
answers.addResponse(s1: "As I see it, yes")
answers.addResponse(s1: "Most likely")
answers.addResponse(s1: "Outlook good")
answers.addResponse(s1: "Yes")
answers.addResponse(s1: "Signs point to yes")
answers.addResponse(s1: "Reply hazy, try again")
answers.addResponse(s1: "Ask again later")
answers.addResponse(s1: "Better not tell you now")
answers.addResponse(s1: "Cannot predict now")
answers.addResponse(s1: "Concentrate and ask again")
answers.addResponse(s1: "Don’t count on it")
answers.addResponse(s1: "My reply is no")
answers.addResponse(s1: "My sources say no")
answers.addResponse(s1: "Outlook not so good")
answers.addResponse(s1: "Very doubtful")
questions = Responder("will i", "can i expect", "should i", "may i","is it a good idea","will it be a good idea for me to","is it possible","future hold","will there be")
}
func engage(_ ear: String) -> Bool {
if ear.isEmpty {
return false
}
if questions.strContainsResponse(ear: ear) {
return true
}
return false
}
func reply() -> String {
return answers.getAResponse()
}
}
class AXShoutOut {
private var isActive: Bool = false
let handshake:Responder = Responder()
func activate() {
// make engage-able
isActive = true
}
func engage(ear: String) -> Bool {
if ear.isEmpty {
return false
}
if isActive {
if handshake.strContainsResponse(ear: ear) {
isActive = false
return true // shout out was replied!
}
}
// unrelated reply to shout out, shout out context is outdated
isActive = false
return false
}
}
class AXHandshake {
private var trgTime:TrgTime = TrgTime()
private var trgTolerance:TrgTolerance = TrgTolerance(maxRepeats: 10)
private var shoutOut:AXShoutOut = AXShoutOut()
private var user_name:String = "user"
private var dripper:PercentDripper = PercentDripper()
init() {
// default handshakes (valid reply to shout out)
shoutOut.handshake = Responder("what", "yes", "i am here")
}
// setters
func setTimeStamp(_ time_stamp: String) -> AXHandshake {
// when will the shout-out happen?
// example time stamp: 9:15
trgTime.setTime(v1: time_stamp)
return self
}
func setShoutOutLim(_ lim: Int) -> AXHandshake {
// how many times should user be called for, per shout out?
trgTolerance.setMaxRepeats(maxRepeats: lim)
return self
}
func setHandShake(_ responder: Responder) -> AXHandshake {
// which responses would acknowledge the shout-out?
// such as *see default handshakes for examples suggestions
shoutOut.handshake = responder
return self
}
func setDripperPercent(_ n: Int) -> AXHandshake {
// when shout out to user how frequent will it be?
dripper.setLimis(n)
return self
}
func setUser_name(_ user_name: String) {
self.user_name = user_name
}
// getters
func getUser_name() -> String {
return user_name
}
func engage(_ ear: String) -> Bool {
if trgTime.trigger() {
trgTolerance.reset()
}
// stop shout out
if shoutOut.engage(ear: ear) {
trgTolerance.disable()
return true
}
return false
}
func trigger() -> Bool {
if trgTolerance.trigger() {
if dripper.drip() {
shoutOut.activate()
return true
}
}
return false
}
}
protected void setSimpleAlg(String... sayThis){
// based on the setVerbatimAlg method
// build a simple output algorithm to speak string by string per think cycle
// uses varargs param
this.outAlg = this.diSkillUtils.simpleVerbatimAlgorithm(sayThis);
this.outpAlgPriority = 4; // 1->5 1 is the highest algorithm priority
}
func getCurrentMonthName() -> String {
switch (getMonthAsInt()){
case 1:
return "january"
case 2:
return "february"
case 3:
return "march"
case 4:
return "april"
case 5:
return "may"
case 6:
return "june"
case 7:
return "july"
case 8:
return "august"
case 9:
return "november"
case 10:
return "october"
case 11:
return "november"
case 12:
return "december"
default:
return ""
}
}
public class DiTime extends DiSkillV2 {
private PlayGround pl = new PlayGround();
@Override
public void input(String ear, String skin, String eye) {
switch(ear) {
case "what is the time":
setVerbatimAlg(4, pl.getCurrentTimeStamp());
return;
case "which day is it":
setVerbatimAlg(4, pl.getDayOfDWeek());
return;
case "good morning": case "good night": case "good afternoon": case "good evening":
setVerbatimAlg(4, "good " + pl.partOfDay());
return;
case "which month is it":
setSimpleAlg(pl.translateMonth(pl.getMonthAsInt()));
return;
case "which year is it":
setVerbatimAlg(4, pl.getYearAsInt()+"");
return;
case "what is your time zone":
setVerbatimAlg(4, pl.getLocal());
return;
case "when is the first":
setVerbatimAlg(4, pl.nxtDayOnDate(1));
return;
case "when is the second":
setVerbatimAlg(4, pl.nxtDayOnDate(2));
return;
case "when is the third":
setVerbatimAlg(4, pl.nxtDayOnDate(3));
return;
case "when is the fourth":
setVerbatimAlg(4, pl.nxtDayOnDate(4));
return;
case "when is the fifth":
setVerbatimAlg(4, pl.nxtDayOnDate(5));
return;
case "when is the sixth":
setVerbatimAlg(4, pl.nxtDayOnDate(6));
return;
case "when is the seventh":
setVerbatimAlg(4, pl.nxtDayOnDate(7));
return;
case "when is the eighth":
setVerbatimAlg(4, pl.nxtDayOnDate(8));
return;
case "when is the ninth":
setVerbatimAlg(4, pl.nxtDayOnDate(9));
return;
case "when is the tenth":
setVerbatimAlg(4, pl.nxtDayOnDate(10));
return;
case "when is the eleventh":
setVerbatimAlg(4, pl.nxtDayOnDate(11));
return;
case "when is the twelfth":
setVerbatimAlg(4, pl.nxtDayOnDate(12));
return;
case "when is the thirteenth":
setVerbatimAlg(4, pl.nxtDayOnDate(13));
return;
case "when is the fourteenth":
setVerbatimAlg(4, pl.nxtDayOnDate(14));
return;
case "when is the fifteenth":
setVerbatimAlg(4, pl.nxtDayOnDate(15));
return;
case "when is the sixteenth":
setVerbatimAlg(4, pl.nxtDayOnDate(16));
return;
case "when is the seventeenth":
setVerbatimAlg(4, pl.nxtDayOnDate(17));
return;
case "when is the eighteenth":
setVerbatimAlg(4, pl.nxtDayOnDate(18));
return;
case "when is the nineteenth":
setVerbatimAlg(4, pl.nxtDayOnDate(19));
return;
case "when is the twentieth":
setVerbatimAlg(4, pl.nxtDayOnDate(21));
return;
case "when is the twenty first":
setVerbatimAlg(4, pl.nxtDayOnDate(21));
return;
case "when is the twenty second":
setVerbatimAlg(4, pl.nxtDayOnDate(22));
return;
case "when is the twenty third":
setVerbatimAlg(4, pl.nxtDayOnDate(23));
return;
case "when is the twenty fourth":
setVerbatimAlg(4, pl.nxtDayOnDate(24));
return;
case "when is the twenty fifth":
setVerbatimAlg(4, pl.nxtDayOnDate(25));
return;
case "when is the twenty sixth":
setVerbatimAlg(4, pl.nxtDayOnDate(26));
return;
case "when is the twenty seventh":
setVerbatimAlg(4, pl.nxtDayOnDate(27));
return;
case "when is the twenty eighth":
setVerbatimAlg(4, pl.nxtDayOnDate(28));
return;
case "when is the twenty ninth":
setVerbatimAlg(4, pl.nxtDayOnDate(29) == "" ? "never":pl.nxtDayOnDate(29));
return;
case "when is the thirtieth":
setVerbatimAlg(4, pl.nxtDayOnDate(30) == "" ? "never":pl.nxtDayOnDate(30));
return;
case "when is the thirty first":
setVerbatimAlg(4, pl.nxtDayOnDate(31) == "" ? "never":pl.nxtDayOnDate(31));
return;
default:
// code block
}
}
}
class DiTime:DiSkillV2{
private let pl:PlayGround = PlayGround()
// hello world skill for testing purposes
override func input(ear: String, skin: String, eye: String) {
switch (ear) {
case "what is the time":
setSimpleAlg(sayThis: pl.getCurrentTimeStamp())
break
case "which day is it":
setSimpleAlg(sayThis: pl.getDayOfDWeek())
break
case "good morning","good afternoon","good evening","good night":
setSimpleAlg(sayThis: pl.partOfDay())
break
case "which month is it":
setSimpleAlg(sayThis: pl.getCurrentMonthName())
break
case "which year is it":
setSimpleAlg(sayThis: "\(pl.getYearAsInt())")
break
case "what is your time zone":
setSimpleAlg(sayThis: pl.getLocal())
break
case "when is the first":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 1))
break
case "when is the second":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 2))
break
case "when is the third":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 3))
break
case "when is the fourth":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 4))
break
case "when is the fifth":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 5))
break
case "when is the sixth":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 6))
break
case "when is the seventh":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 7))
break
case "when is the eighth":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 8))
break
case "when is the ninth":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 9))
break
case "when is the tenth":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 10))
break
case "when is the eleventh":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 11))
break
case "when is the twelfth":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 12))
break
case "when is the thirteenth":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 13))
break
case "when is the fourteenth":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 14))
break
case "when is the fifteenth":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 15))
break
case "when is the sixteenth":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 16))
break
case "when is the seventeenth":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 17))
break
case "when is the eighteenth":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 18))
break
case "when is the nineteenth":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 19))
break
case "when is the twentieth":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 20))
break
case "when is the twenty first":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 21))
break
case "when is the twenty second":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 22))
break
case "when is the twenty third":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 23))
break
case "when is the twenty fourth":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 24))
break
case "when is the twenty fifth":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 25))
break
case "when is the twenty sixth":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 26))
break
case "when is the twenty seventh":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 27))
break
case "when is the twenty eighth":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 28))
break
case "when is the twenty ninth":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 29) == "" ? "never":pl.nxtDayOnDate(dayOfMonth: 29))
break
case "when is the thirtieth":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 30) == "" ? "never":pl.nxtDayOnDate(dayOfMonth: 30))
break
case "when is the thirty first":
setSimpleAlg(sayThis: pl.nxtDayOnDate(dayOfMonth: 31) == "" ? "never":pl.nxtDayOnDate(dayOfMonth: 31))
break
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")
break
default:
return
}
}
}
public class DiMagic8Ball extends DiSkillV2 {
public Magic8Ball magic8Ball = new Magic8Ball();
// skill toggle params:
public AXContextCmd skillToggler = new AXContextCmd();
private Boolean isActive = true;
public DiMagic8Ball() {
skillToggler.contextCommands.add("toggle eliza");
skillToggler.contextCommands.add("toggle magic 8 ball");
skillToggler.contextCommands.add("toggle magic eight ball");
skillToggler.commands.add("again");skillToggler.commands.add("repeat");
}
@Override
public void input(String ear, String skin, String eye) {
// toggle the skill off/on
if(skillToggler.engageCommand(ear)){isActive = !isActive;setVerbatimAlg(4, isActive? "skill activated":"skill inactivated");return;}
if (!isActive){return;}
// skill logic:
if (magic8Ball.engage(ear)){
setVerbatimAlg(4, magic8Ball.reply());
}
}
}
class DiMagic8Ball: DiSkillV2 {
public var magic8Ball = Magic8Ball()
// skill toggle params:
public var skillToggler = AXContextCmd()
private var isActive = true
override init() {
skillToggler.contextCommands.input(in1: "toggle eliza")
skillToggler.contextCommands.input(in1: "toggle magic 8 ball")
skillToggler.contextCommands.input(in1: "toggle magic eight ball")
skillToggler.commands.input(in1: "again")
skillToggler.commands.input(in1: "repeat")
}
override func input(ear: String, skin: String, eye: String) {
// toggle the skill off/on
if skillToggler.engageCommand(ear: ear) {
isActive = !isActive
setSimpleAlg(sayThis: isActive ? "skill activated" : "skill inactivated")
return
}
if !isActive {
return
}
// skill logic:
if magic8Ball.engage(ear) {
setSimpleAlg(sayThis: magic8Ball.reply())
}
}
}
public class DiCron extends DiSkillV2 {
private String sound = "snore";
private Cron cron = new Cron("12:05",40,2);//Cron(String startTime, int minutes, int limit)
// setters
public DiCron setSound(String sound) {
this.sound = sound;
return this;
}
public DiCron setCron(Cron cron) {
this.cron = cron;
return this;
}
@Override
public void input(String ear, String skin, String eye) {
if (cron.trigger()){
setVerbatimAlg(4,sound);
}
}
}
class DiCron:DiSkillV2{
private var sound:String = "snore"
private var cron:Cron = Cron(startTime: "12:05", minutes: 40, limit: 2)
// setters
func setSound(sound:String) -> DiCron {
self.sound = sound
return self
}
func setCron(cron:Cron) -> DiCron {
self.cron = cron
return self
}
override func input(ear: String, skin: String, eye: String) {
if cron.trigger(){
setSimpleAlg(sayThis: sound)
}
}
}
public class DiTreater extends DiSkillV2 {
private AXHandshake handshake = new AXHandshake();
public Responder replies = new Responder("stop arguing", "just do it", "behave","be a big boy and do it","bad boy no more fussing","i know best");
public TrgArgue contextCmd = new TrgArgue();
public DiTreater setTime(String time_stamp){
// set time in which the event eventifies
handshake.setTimeStamp(time_stamp);
return this;
}
public DiTreater setDripper(int percentage){
handshake.setDripperPercent(percentage);
return this;
}
public DiTreater() {
handshake.setTimeStamp("19:30");
contextCmd.contextCommands.add("do i have to wear a diaper");
contextCmd.commands.add("but");
contextCmd.commands.add("do not want to");
contextCmd.commands.add("why");
contextCmd.commands.add("no");
}
@Override
public void input(String ear, String skin, String eye) {
if (handshake.engage(ear)){
contextCmd.engageCommand("do i have to wear a diaper");
setVerbatimAlg(4,"put on your diaper sweet heart");return;
}
if (handshake.trigger()){setVerbatimAlg(4,handshake.getUser_name());return;}
switch (contextCmd.engageCommand(ear)){
case 1:
setVerbatimAlg(4,"you know you do");
break;
case 2:
setVerbatimAlg(4, replies.getAResponse());
break;
}
}
public DiTreater setUser_nickname(String nickname){
handshake.setUser_name(nickname);
return this;
}
}