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

descriptionnew auxiliary modules for command engagement Emptynew auxiliary modules for command engagement

more_horiz

Code:

package AXJava;

public class ContextCmd {
    // engage on commands
    // when commands are engaged, context commans can also engage
    public UniqueItemSizeLimitedPriorityQueue commands = new UniqueItemSizeLimitedPriorityQueue();
    public UniqueItemSizeLimitedPriorityQueue contextCommands = new UniqueItemSizeLimitedPriorityQueue();
    public TrgTolerance trgTolerance  = new TrgTolerance(3);
    public Boolean engageCommand(String s1){
        if (commands.contains(s1)){
            trgTolerance.reset();
            return true;
        }
        if (!trgTolerance.trigger()){
            return false;
        }
        return contextCommands.contains(s1);
    }
}

main example

Code:

        ContextCmd a = new ContextCmd();
        a.commands.add("what did i need to do");
        a.contextCommands.add("what else");
        a.contextCommands.add("and");
        a.contextCommands.add("next");
        System.out.println(a.engageCommand("hello"));
        System.out.println(a.engageCommand("what else"));
        System.out.println(a.engageCommand("what did i need to do"));
        System.out.println(a.engageCommand("what else"));
        System.out.println(a.engageCommand("what did i need to do"));
        for (int i = 0; i < 4; i++) {
            System.out.println(a.engageCommand("what else"));
//            System.out.println(n.wait(""));
        }

descriptionnew auxiliary modules for command engagement EmptyRe: new auxiliary modules for command engagement

more_horiz

Code:

package AXJava;

import java.util.Hashtable;

public class AXMachineCode {
    // common code lines used in machine code to declutter machine code
    public Hashtable<String,Integer> dic = new Hashtable<>();
    public AXMachineCode addKeyValuePair(String key, int value){
        dic.put(key,value);
        return this;
    }
    public int getMachineCodeFor(String key){
        return dic.getOrDefault(key,-1);
    }
}

descriptionnew auxiliary modules for command engagement EmptyRe: new auxiliary modules for command engagement

more_horiz

Code:

package AXJava;

public class AXInputWaiter {
    // wait for any input
    private TrgTolerance trgTolerance;

    public AXInputWaiter(int tolerance) {
        this.trgTolerance = new TrgTolerance(tolerance);
        trgTolerance.reset();
    }
    public void reset(){
        trgTolerance.reset();
    }
    public Boolean wait(String s1){
        // return true till any input detected or till x times of no input detection
        if (!s1.isEmpty()){
            return false;
        }
        return trgTolerance.trigger();
    }
    public void setWait(int timesToWait){
        trgTolerance.setMaxrepeats(timesToWait);
    }
}

descriptionnew auxiliary modules for command engagement EmptyRe: new auxiliary modules for command engagement

more_horiz

Code:

package AXJava;

public class AXCmdBreaker {
    // separate command parameter from the command
    public String conjuration;

    public AXCmdBreaker(String conjuration) {
        this.conjuration = conjuration;
    }
    public String extractCmdParam(String s1){
        if (s1.contains(conjuration)){
            return s1.replace(conjuration,"").trim();
        }
        return "";
    }
}

descriptionnew auxiliary modules for command engagement EmptyRe: new auxiliary modules for command engagement

more_horiz

Code:

class AXMachineCode:
    # common code lines used in machine code to declutter machine code
    # also simplified extensions for common dictionary actions
    def __init__(self):
        self.dic: dict[str, int] = {}

    def addKeyValuePair(self, key: str, value: int) -> AXMachineCode:
        self.dic[key] = value
        return self

    def getMachineCodeFor(self, key: str) -> int:
        # dictionary get or default
        if not key in self.dic:
            return -1
        return self.dic[key]


class AXInputWaiter:
    # wait for any input
    def __init__(self, tolerance: int):
        self._trgTolerance: TrgTolerance = TrgTolerance(tolerance)
        self._trgTolerance.reset()

    def reset(self):
        self._trgTolerance.reset()

    def wait(self, s1: str) -> False:
        # return true till any input detected or till x times of no input detection
        if not s1 == "":
            return False
        return self._trgTolerance.trigger()

    def setWait(self, timesToWait: int):
        self._trgTolerance.setMaxRepeats(timesToWait)


class AXCmdBreaker:
    def __init__(self, conjuration: str):
        self.conjuration: str = conjuration

    def extractCmdParam(self, s1: str) -> str:
        if self.conjuration in s1:
            return s1.replace(self.conjuration, "").strip()
        return ""


class AXContextCmd:
    # engage on commands
    # when commands are engaged, context commans can also engage
    def __init__(self):
        self.commands: UniqueItemSizeLimitedPriorityQueue = UniqueItemSizeLimitedPriorityQueue(5)
        self.contextCommands: UniqueItemSizeLimitedPriorityQueue = UniqueItemSizeLimitedPriorityQueue(5)
        self.trgTolerance: TrgTolerance = TrgTolerance(3)

    def engageCommand(self, s1: str) -> bool:
        if self.commands.contains(s1):
            self.trgTolerance.reset()
        if not self.trgTolerance.trigger():
            return False
        return self.contextCommands.contains(s1)

descriptionnew auxiliary modules for command engagement EmptyRe: new auxiliary modules for command engagement

more_horiz


Code:

package AXJava;

import LivinGrimoire.DiSkillV2;

public class DiTasker extends DiSkillV2 {
    private TODOListManager todoListManager = new TODOListManager(5);
    private AXMachineCode axMachineCode = new AXMachineCode();
    private AXCmdBreaker axCmdBreaker = new AXCmdBreaker("i need to");
    private AXContextCmd axContextCmd = new AXContextCmd();
    public DiTasker() {
        axMachineCode.addKeyValuePair("give me a task",1);
        axMachineCode.addKeyValuePair("task me",1);
        axContextCmd.commands.add("what did i want to do");
        axContextCmd.contextCommands.add("what else");
        axMachineCode.addKeyValuePair("clear tasks",3);
    }

    @Override
    public void input(String ear, String skin, String eye) {
        String temp = axCmdBreaker.extractCmdParam(ear);
        if (!temp.isEmpty()){
            todoListManager.addTask(temp);
            this.outAlg = this.diSkillUtils.simpleVerbatimAlgorithm("tasker1","task added");
            return;
        }
        int n1 = axMachineCode.getMachineCodeFor(ear);
        if (axContextCmd.engageCommand(ear)){n1 = 2;}
        switch (n1){
            case 1:
                temp = todoListManager.getTask();
                if (temp.isEmpty()){
                    this.outAlg = this.diSkillUtils.simpleVerbatimAlgorithm("tasker2","non available");
                }
                else{
                    this.outAlg = this.diSkillUtils.simpleVerbatimAlgorithm("tasker2",temp);
                }
                break;
            case 2:
                temp = todoListManager.getOldTask();
                if(temp.isEmpty()){
                    this.outAlg = this.diSkillUtils.simpleVerbatimAlgorithm("tasker3","hmm");
                    break;
                }
                this.outAlg = this.diSkillUtils.simpleVerbatimAlgorithm("tasker3",temp);
                break;
            case 3:
                todoListManager.clearAllTasks();
                this.outAlg = this.diSkillUtils.simpleVerbatimAlgorithm("tasker3","tasks cleared");
                break;
        }
    }
}
like
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply