🐍 python Chii's python suit

python

fukurou

the supreme coder
ADMIN
AbsDictionaryDB

Python:
from abc import ABC, abstractmethod


class AbsDictionaryDB(ABC):
    @abstractmethod
    def save(key: str, value: str):
        '''save to DB'''
        pass

    @abstractmethod
    def load(key: str) -> str:
        '''set to return "null" as default if key not found !!!'''
        pass
 
Last edited:

fukurou

the supreme coder
ADMIN
AbsDictionaryDBShadow

Python:
from abc import ABC, abstractmethod

class AbsDictionaryDB(ABC):
    @abstractmethod
    def save(self, key: str, value: str):
        '''Returns action string'''
        pass

    @abstractmethod
    def load(self, key: str) -> str:
        '''TODO set to return null as default if key not found !!!'''
        pass

class AbsDictionaryDBShadow(AbsDictionaryDB):
    '''used as a fill in class if you want to test the chobit and havent built a DB class yet'''
    # Override
    def save(self, key: str, value: str):
        pass
  
    #Override
    def load(self, key: str) -> str:
        return "null"

if __name__ == "__main__":
    test = AbsDictionaryDBShadow()
    print(test.load("hello"))
 
Last edited:

fukurou

the supreme coder
ADMIN
Mutatable

Python:
from __future__ import annotations
from abc import ABC, abstractmethod
from enum import Enum

''' ENUMFAIL CLASS '''


class enumFail(Enum):
    fail = "fail"  # no input
    requip = "requip"  # item should be added
    dequip = "dequip"
    cloudian = "cloudian"  # algorithm goes to stand by in its Dclass
    ok = "ok"  # no fail


''' MUTATABLE CLASS '''


class Mutatable(ABC):
    @abstractmethod
    def action(self, ear: str, skin: str, eye: str) -> str:
        """Returns action string"""
        pass

    @abstractmethod
    def failure(self, input: str) -> enumFail:
        """Failure type only mutatable may use enumFail.fail"""
        pass

    @abstractmethod
    def completed(self) -> bool:
        """Has finished ?"""
        pass

    @abstractmethod
    def clone(self) -> Mutatable:
        pass

    def getMutationLimit(self) -> int:
        return 0

    def myName(self) -> str:
        """Returns the class name"""
        return self.__class__.__name__

    def mutation(self) -> Mutatable:
        self.clone()


'''!!! CHILD TEST CLASS TO REMOVE !!!'''


class T1(Mutatable):
    def mutation(self) -> Mutatable:
        print("t1 mutating into t2")
        return T2()

    def clone(self) -> Mutatable:
        print("t1 cloning another t1")
        return T1()

    # Override
    def action(self, ear: str, skin: str, eye: str) -> str:
        """Returns action string"""
        pass

    # Override
    def failure(self, input: str) -> enumFail:
        """Failure type only mutatable may use enumFail.fail"""
        pass

    # Override
    def completed(self) -> bool:
        """Has finished ?"""
        pass

    # Override
    def myName(self) -> str:
        """Returns the class name"""
        return self.__class__.__name__


'''!!! CHILD TEST CLASS TO REMOVE !!!'''


class T2(Mutatable):
    def mutation(self) -> Mutatable:
        print("t2 mutating into t1")
        return T1()

    def clone(self) -> Mutatable:
        print("t2 cloning another t2")
        return T2()

    # Override
    def action(self, ear: str, skin: str, eye: str) -> str:
        """Returns action string"""
        pass

    # Override
    def failure(self, input: str) -> enumFail:
        """Failure type only mutatable may use enumFail.fail"""
        pass

    # Override
    def completed(self) -> bool:
        """Has finished ?"""
        pass

    # Override
    def myName(self) -> str:
        """Returns the class name"""
        return self.__class__.__name__


if __name__ == "__main__":
    test = t1()
    print("This should return None: " + str(test.mutation().clone().getMutationLimit()))
 
Last edited:

fukurou

the supreme coder
ADMIN
APSay

Python:
from __future__ import annotations
from abc import ABC, abstractmethod
from enum import Enum

'''
Failure types:
- ok: no fail
- requip: item should be added
- cloudian: algorithm goes to stand by in its Dclass
- fail: no input
'''
class enumFail (Enum):
    fail = "fail"
    requip = "requip"
    dequip = "dequip"
    cloudian = "cloudian"
    ok = "ok"


class Mutatable:
    @abstractmethod
    def action(self, ear: str, skin: str, eye: str) -> str:
        """Returns action string"""
        ...

    @abstractmethod
    def failure(self, input: str) -> enumFail:
        """Failure type only mutatable may use enumFail.fail"""
        pass

    @abstractmethod
    def completed(self) -> bool:
        """Has finished ?"""
        pass

    @abstractmethod
    def clone(self) -> Mutatable:
        pass

    def getMutationLimit(self) -> int:
        return 0

    @abstractmethod
    def myName(self) -> str:
        """Returns the class name"""
        return self.__class__.__name__

    @abstractmethod
    def mutation(self) -> Mutatable:
        self.clone()


'''
it speaks something x times
a most basic skill.
also fun to make the chobit say what you want
'''
class APSay(Mutatable):
    def __init__(self, at: int, param: str) -> None:
        super().__init__()
        if (at > 10):
            at = 10
        self.at = at
        self.param = param

    def action(self, ear: str, skin: str, eye: str) -> str:
        '''TODO Auto-generated method stub'''
        axnStr = ""
        if (self.at > 0):
            if (ear.lower() != self.param.lower()):
                axnStr = self.param
                self.at -= 1
        return axnStr

    def failure(self, input: str) -> enumFail:
        '''TODO Auto-generated method stub'''
        return enumFail.ok

    def completed(self) -> bool:
        '''TODO Auto-generated method stub'''
        return self.at < 1

    def clone(self) -> AbsAlgPart:
        '''TODO Auto-generated method stub'''
        return APSay(self.at, self.param)


if __name__ == "__main__":
    apsay = APSay(7, "seven")
    print("The output of the action() method is: " + apsay.action("six","",""))
    print("The output of the failure() method is: " + apsay.failure("input").name)
    print("The output of the completed() method is: " + str(apsay.completed()))
    for x in range(8):
        print(apsay.action("six","",""))
    clone = apsay.clone()
    print("\napsay has been cloned, let's see its details:")
    print("The output of the action() method is: " + clone.action("six","",""))
    print("The output of the failure() method is: " + clone.failure("input").name)
    print("The output of the completed() method is: " + str(clone.completed()))
 

fukurou

the supreme coder
ADMIN
APVerbatim

Python:
from __future__ import annotations
from abc import ABC, abstractmethod
from enum import Enum

'''
Failure types:
- ok: no fail
- requip: item should be added
- cloudian: algorithm goes to stand by in its Dclass
- fail: no input
'''


class enumFail(Enum):
    fail = "fail"
    requip = "requip"
    dequip = "dequip"
    cloudian = "cloudian"
    ok = "ok"


class Mutatable:
    @abstractmethod
    def action(self, ear: str, skin: str, eye: str) -> str:
        """Returns action string"""
        ...

    @abstractmethod
    def failure(self, input: str) -> enumFail:
        """Failure type only mutatable may use enumFail.fail"""
        pass

    @abstractmethod
    def completed(self) -> bool:
        """Has finished ?"""
        pass

    @abstractmethod
    def clone(self) -> Mutatable:
        pass

    def getMutationLimit(self) -> int:
        return 0

    @abstractmethod
    def myName(self) -> str:
        """Returns the class name"""
        return self.__class__.__name__

    @abstractmethod
    def mutation(self) -> Mutatable:
        self.clone()


class APVerbatim(Mutatable):
    '''this algorithm part says each past param verbatim'''

    def __init__(self, *args) -> None:
        super().__init__()
        self.sentences = []
        self.at = 0

        try:
            if (isinstance(args[0], list)):
                self.sentences = args[0]
                if (0 == len(self.sentences)):
                    self.at = 30
            else:
                for i in range(len(args)):
                    self.sentences.append(args[i])
        except:
            self.at = 30

    # Override
    def action(self, ear: str, skin: str, eye: str) -> str:
        '''TODO Auto-generated method stub'''
        axnStr = ""
        if (self.at < len(self.sentences)):
            axnStr = self.sentences[self.at]
            self.at += 1
        return axnStr

    # Override
    def failure(self, input: str) -> enumFail:
        '''TODO Auto-generated method stub'''
        return enumFail.ok

    # Override
    def completed(self) -> bool:
        '''TODO Auto-generated method stub'''
        return self.at >= len(self.sentences)

    # Override
    def clone(self) -> AbsAlgPart:
        '''TODO Auto-generated method stub'''
        return APVerbatim(self.sentences)


if __name__ == "__main__":
    testOne = APVerbatim(["hello", "how", "are", "you"])
    print("TestOne.action() should return 'hello': " + testOne.action("ear", "skin", "eye"))
    print(testOne.action("", "", ""))
    print("TestOne.completed should be false: " + str(testOne.completed()))
    testTwo = APVerbatim("hi", "I", "am", "good")
    print("TestTwo.action() should return 'hi': " + testTwo.action("ear", "skin", "eye"))
    print("TestTwo.completed should be false: " + str(testTwo.completed()))
    testThree = APVerbatim([])
    print("TestThree.action() should return an empty string: " + testThree.action("ear", "skin", "eye"))
    print("TestThree.completed should be true: " + str(testThree.completed()))
    testFour = APVerbatim()
    print("TestFour.action() should return an empty string: " + testFour.action("ear", "skin", "eye"))
    print("TestFour.completed should be true: " + str(testFour.completed()))

    # Clone testing
    testTwoClone = testTwo.clone()
    print("\nA clone of testTwo has been made, let's test it:")
    print("TestTwoClone.action() should return 'hi': " + testTwoClone.action("ear", "skin", "eye"))
    print("TestTwoClone.completed should be false: " + str(testTwoClone.completed()))
 

fukurou

the supreme coder
ADMIN
Person

Python:
class Person():
    def __init__(self):
        self.name = ""
        self.active = False
        self.phone = ""
        self.skill = ""
        self.profession = ""
        self.jutsu = "hadouken"
        # location
        self.email = ""
        self.id = ""

    @property
    def getName(self) -> str:
        '''Returns the name'''
        return self.name
    @getName.setter
    def setName(self, name: str):
        '''Sets the name'''
        self.name = name

    @property
    def getActive(self) -> bool:
        '''Returns active'''
        return self.active

    @getActive.setter
    def setActive(self, active: bool):
        '''Sets active'''
        self.active = active

    @property
    def getPhone(self) -> str:
        '''Returns the phone'''
        return self.phone

    @getPhone.setter
    def setPhone(self, phone: str):
        '''Sets the phone'''
        self.phone = phone

    @property
    def getSkill(self) -> str:
        '''Returns the skill'''
        return self.skill

    @getSkill.setter
    def setSkill(self, skill: str):
        '''Sets the skill'''
        self.skill = skill

    @property
    def getProfession(self) -> str:
        '''Returns the profession'''
        return self.profession

    @getProfession.setter
    def setProfession(self, profession: str):
        '''Sets the profession'''
        self.profession = profession

    @property
    def getJutsu(self) -> str:
        '''Returns the jutsu'''
        return self.jutsu
    @getJutsu.setter
    def setJutsu(self, jutsu: str):
        '''Sets the justsu'''
        self.jutsu = jutsu

    @property
    def getEmail(self) -> str:
        '''Returns the email'''
        return self.email
    @getEmail.setter
    def setEmail(self, email: str):
        '''Sets the email'''
        self.email = email

    @property
    def getId(self) -> str:
        '''Returns the id'''
        return self.id
    @getId.setter
    def setId(self, id: str):
        '''Sets the id'''
        self.id = id

    def deleteFriend(self):
        '''It resets all the properties of the object'''
        self.name = ""
        self.active = False
        self.phone = ""
        self.skill = ""
        self.profession = ""
        self.jutsu = "hadouken"
        # location
        self.email = ""
        self.id = ""


if __name__ == "__main__":
    # Person definition
    person = Person()
    person.name = "John"
    person.active = True
    person.phone = "0789451489"
    person.skill = "painter"
    person.profession = "chef"
    person.jutsu = "bukijutsu"
    person.email = "[email protected]"
    person.id = "1982763"

    # Person's details printing
    print("Name: " + person.name + "\n" +
          "active: " + str(person.active) + "\n" +
          "phone: " + person.phone + "\n" +
          "skill: " + person.skill + "\n" +
          "profession: " + person.profession + "\n" +
          "jutsu: " + person.jutsu + "\n" +
          "email: " + person.email + "\n" +
          "id: " + person.id + "\n")

    # Person is deleted
    person.deleteFriend()
    print("\nPerson has been deleted:\n")

    # Person's details printing again
    print("Name: " + person.name + "\n" +
          "active: " + str(person.active) + "\n" +
          "phone: " + person.phone + "\n" +
          "skill: " + person.skill + "\n" +
          "profession: " + person.profession + "\n" +
          "jutsu: " + person.jutsu + "\n" +
          "email: " + person.email + "\n" +
          "id: " + person.id)
 

fukurou

the supreme coder
ADMIN
PlayGround (not core class but high use in skills)
this class helps with time related methods

Python:
import datetime
from datetime import timedelta
import calendar

from enum import Enum, auto


class enumTimes(Enum):
    DATE = auto()
    DAY = auto()
    YEAR = auto()
    HOUR = auto()
    MINUTES = auto()
    SECONDS = auto()


class PlayGround:
    def __init__(self):
        self.week_days = {1: 'sunday',
                          2: 'monday',
                          3: 'tuesday',
                          4: 'wednesday',
                          5: 'thursday',
                          6: 'friday',
                          7: 'saturday',
                          }
        self.dayOfMonth = {1:"first_of", 2:"second_of", 3: "third_of", 4: "fourth_of", 5: "fifth_of", 6: "sixth_of", 7: "seventh_of",
                            8: "eighth_of", 9: "nineth_of", 10 : "tenth_of", 11: "eleventh_of", 12: "twelveth_of", 13: "thirteenth_of",
                            14 : "fourteenth_of", 15: "fifteenth_of", 16: "sixteenth_of", 17: "seventeenth_of", 18: "eighteenth_of",
                           19: "nineteenth_of", 20: "twentyth_of", 21: "twentyfirst_of", 22: "twentysecond_of", 23: "twentythird_of",
                            24: "twentyfourth_of", 25: "twentyfifth_of", 26: "twentysixth_of", 27: "twentyseventh_of", 28: "twentyeighth_of",
                            29: "twentynineth_of", 30: "thirtyth_of", 31: "thirtyfirst_of"}

    def getCurrentTimeStamp(self) -> str:
        '''This method returns the current time (hh:mm)'''
        right_now = datetime.datetime.now()
        return str(right_now.hour) + ":" + str(right_now.minute)

    def getMonthAsInt(self) -> int:
        '''This method returns the current month (MM)'''
        right_now = datetime.datetime.now()
        return right_now.month

    def getDayOfTheMonthAsInt(self) -> int:
        '''This method returns the current day (dd)'''
        right_now = datetime.datetime.now()
        return right_now.day

    def getYearAsInt(self) -> int:
        '''This method returns the current year (yyyy)'''
        right_now = datetime.datetime.now()
        return right_now.year

    def getDayAsInt(self) -> int:
        '''This method returns the current day of the week (1, 2, ... 7)'''
        right_now = datetime.datetime.now()
        return right_now.isoweekday()

    def getMinutes(self) -> str:
        '''This method returns the current minutes (mm)'''
        right_now = datetime.datetime.now()
        return str(right_now.minute)

    def getSeconds(self) -> str:
        '''This method returns the current seconds (ss)'''
        right_now = datetime.datetime.now()
        return str(right_now.second)

    def getDayOfDWeek(self) -> str:
        '''This method returns the current day of the week as a word (monday, ...)'''
        right_now = datetime.datetime.now()
        return calendar.day_name[right_now.weekday()]

    def translateMonthDay(self, day: int) -> str:
        '''This method returns the current day of the month as a word (first_of, ...)'''
        return self.dayOfMonth.get(day, "")

    def getSpecificTime(self, time_variable: enumTimes) -> str:
        '''This method returns the current specific date in words (eleventh_of June 2021, ...)'''
        enum_temp = time_variable.name
        if enum_temp == "DATE":
            right_now = datetime.datetime.now()
            output = self.translateMonthDay(right_now.day) + " " + calendar.month_name[right_now.month] + " " + str(
                right_now.year)
        elif enum_temp == "HOUR":
            output = str(datetime.datetime.now().hour)
        elif enum_temp == "SECONDS":
            output = str(datetime.datetime.now().second)
        elif enum_temp == "MINUTES":
            output = str(datetime.datetime.now().minute)
        elif enum_temp == "YEAR":
            output = str(datetime.datetime.now().year)
        else:
            output = ""
        return output

    def getSecondsAsInt(self) -> int:
        '''This method returns the current seconds'''
        right_now = datetime.datetime.now()
        return right_now.second

    def getMinutesAsInt(self) -> int:
        '''This method returns the current minutes'''
        right_now = datetime.datetime.now()
        return right_now.minute

    def getHoursAsInt(self) -> int:
        '''This method returns the current hour'''
        right_now = datetime.datetime.now()
        return right_now.hour

    def getFutureInXMin(self, extra_minutes: int) -> str:
        '''This method returns the date in x minutes'''
        right_now = datetime.datetime.now()
        final_time = right_now + datetime.timedelta(minutes=extra_minutes)
        return str(final_time)

    def getPastInXMin(self, less_minutes: int) -> str:
        '''This method returns the date x minutes before'''
        right_now = datetime.datetime.now()
        final_time = right_now - datetime.timedelta(minutes=less_minutes)
        return str(final_time)

    def getFutureHour(self, startHour: int, addedHours: int) -> int:
        '''This method returns the hour in x hours from the starting hour'''
        return (startHour + addedHours) % 24

    def getFutureFromXInYMin(self, to_add: int, start: str) -> str:
        '''This method returns the time (hh:mm) in x minutes the starting time (hh:mm)'''
        values = start.split(":")
        times_to_add = (int(values[1]) + to_add) // 60
        new_minutes = (int(values[1]) + to_add) % 60
        new_time = str((int(values[0]) + times_to_add) % 24) + ":" + str(new_minutes)
        return new_time

    def timeInXMinutes(self, x: int) -> str:
        '''This method returns the time (hh:mm) in x minutes'''
        right_now = datetime.datetime.now()
        final_time = right_now + datetime.timedelta(minutes=x)
        return str(final_time.hour) + ":" + str(final_time.minute)

    def isDayTime(self) -> bool:
        '''This method returns true if it's daytime (6-18)'''
        return 5 < datetime.datetime.now().hour < 19

    def smallToBig(self, *a) -> bool:
        for i in range(len(a) - 1):
            if a[i] > a[i + 1]:
                return False
        return True

    def partOfDay(self) -> str:
        '''This method returns which part of the day it is (morning, ...)'''
        hour: int = self.getHoursAsInt()
        if self.smallToBig(5, hour, 12):
            return "morning"
        elif self.smallToBig(11, hour, 17):
            return "afternoon"
        elif self.smallToBig(16, hour, 21):
            return "evening"
        return "night"

    def convertToDay(self, number: int) -> str:
        '''This method converts the week number to the weekday name'''
        return self.week_days.get(number, "")

    def isNight(self) -> bool:
        '''This method returns true if it's night (21-5)'''
        hour: int = self.getHoursAsInt()
        return hour > 20 or hour < 6

    def getTomorrow(self) -> str:
        '''This method returns tomorrow'''
        right_now = datetime.datetime.now()
        if (right_now.weekday == 6):
            return "Monday"
        return calendar.day_name[right_now.weekday() + 1]

    def getYesterday(self) -> str:
        '''This method returns yesterday'''
        right_now = datetime.datetime.now()
        if right_now.weekday == 0:
            return "Sunday"
        return calendar.day_name[right_now.weekday() - 1]

    def getGMT(self) -> int:
        '''This method returns the local GMT'''
        right_now = datetime.datetime.now()
        timezone = int(str(right_now.astimezone())[-6:-3])
        return timezone

    def getLocal(self) -> str:
        '''This method returns the local time zone'''
        return datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo


if __name__ == "__main__":
    playground = PlayGround()
    print("The current time is: " + playground.getCurrentTimeStamp())
    print("The current month is: " + str(playground.getMonthAsInt()))
    print("The current day is: " + str(playground.getDayOfTheMonthAsInt()))
    print("The current year is: " + str(playground.getYearAsInt()))
    print("The current day of the week (number) is: " + str(playground.getDayAsInt()))
    print("The current minutes are: " + playground.getMinutes())
    print("The current seconds are: " + playground.getSeconds())
    print("The current day of the week (word) is: " + playground.getDayOfDWeek())
    print("here")
    print("The current date in words is: " + playground.getSpecificTime(enumTimes.DATE))
    print("The current seconds are: " + str(playground.getSecondsAsInt()))
    print("The current minutes are: " + str(playground.getMinutesAsInt()))
    print("The current hours are: " + str(playground.getHoursAsInt()))
    print("The current date in words is: " + playground.getFutureInXMin(30))
    print("The current date in words is: " + playground.getPastInXMin(30))
    print("The hour x in y hours will be: " + str(playground.getFutureHour(5, 24)))
    print("The time (hh:mm) in x minutes will be: " + playground.getFutureFromXInYMin(150, "23:10"))
    print("The current time (hh:mm) in x minutes will be: " + playground.timeInXMinutes(90))
    print("Right now is daytime: " + str(playground.isDayTime()))
    print("Right now is: " + playground.partOfDay())
    print("Right now is night: " + str(playground.isNight()))
    print("Tomorrow will be a: " + playground.getTomorrow())
    print("Yesterday was: " + playground.getYesterday())
    print("The GTM is: " + str(playground.getGMT()))
    print("The local time zone is: " + str(playground.getLocal()))
    print("The weekday corresponding to number 2 is: " + playground.convertToDay(7))
    print(playground.convertToDay(1))
 
  • Like
Reactions: neo

fukurou

the supreme coder
ADMIN
GrimoireMemento

Python:
from __future__ import annotations
from abc import ABC, abstractmethod
from enum import Enum
import re

'''
Failure types:
- ok: no fail
- requip: item should be added
- cloudian: algorithm goes to stand by in its Dclass
- fail: no input
'''


class enumFail(Enum):
    fail = "fail"
    requip = "requip"
    dequip = "dequip"
    cloudian = "cloudian"
    ok = "ok"


class Mutatable(ABC):
    @abstractmethod
    def action(self, ear: str, skin: str, eye: str) -> str:
        """Returns action string"""
        ...

    @abstractmethod
    def failure(self, input: str) -> enumFail:
        """Failure type only mutatable may use enumFail.fail"""
        pass

    @abstractmethod
    def completed(self) -> bool:
        """Has finished ?"""
        pass

    @abstractmethod
    def clone(self) -> Mutatable:
        pass

    def getMutationLimit(self) -> int:
        return 0

    @abstractmethod
    def myName(self) -> str:
        """Returns the class name"""
        return self.__class__.__name__

    @abstractmethod
    def mutation(self) -> Mutatable:
        self.clone()


class AbsDictionaryDB(ABC):
    @abstractmethod
    def save(self, key: str, value: str):
        '''Returns action string'''
        pass

    @abstractmethod
    def load(self, key: str) -> str:
        '''TODO set to return null as default if key not found !!!'''
        pass


'''!!! CHILD TEST CLASS TO REMOVE !!!'''


class AbsDictionaryDBShadow(AbsDictionaryDB):
    '''used as a fill in class if you want to test the chobit and havent built a DB class yet'''

    # Override
    def save(self, key: str, value: str):
        pass

    # Override
    def load(self, key: str) -> str:
        return "null"


if __name__ == "__main__":
    test = AbsDictionaryDBShadow()
    print(test.load("hello"))

'''!!! CHILD TEST CLASS TO REMOVE !!!'''


class T1(Mutatable):
    def mutation(self) -> Mutatable:
        print("t1 mutating into t2")
        return T2()

    def clone(self) -> Mutatable:
        print("t1 cloning another t1")
        return T1()

    # Override
    def action(self, ear: str, skin: str, eye: str) -> str:
        """Returns action string"""
        ...

    # Override
    def failure(self, input: str) -> enumFail:
        """Failure type only mutatable may use enumFail.fail"""
        pass

    # Override
    def completed(self) -> bool:
        """Has finished ?"""
        pass

    # Override
    def myName(self) -> str:
        """Returns the class name"""
        return self.__class__.__name__


'''!!! CHILD TEST CLASS TO REMOVE !!!'''


class T2(Mutatable):
    def mutation(self) -> Mutatable:
        print("t2 mutating into t1")
        return T1()

    def clone(self) -> Mutatable:
        print("t2 cloning another t2")
        return T2()

    # Override
    def action(self, ear: str, skin: str, eye: str) -> str:
        """Returns action string"""
        ...

    # Override
    def failure(self, input: str) -> enumFail:
        """Failure type only mutatable may use enumFail.fail"""
        pass

    # Override
    def completed(self) -> bool:
        """Has finished ?"""
        pass

    # Override
    def myName(self) -> str:
        """Returns the class name"""
        return self.__class__.__name__


class GrimoireMemento:
    def __init__(self, absDictionaryDB: AbsDictionaryDB) -> None:
        super().__init__()
        self.rootToAPNumDic = {}  # string, string
        self.APNumToObjDic = {}  # string, Mutatable
        self.absDictionaryDB = absDictionaryDB

    def load(self, obj: Mutatable) -> Mutatable:
        '''load final mutation from memory of obj'''
        objName = obj.__class__.__name__
        objRoot = re.sub(r'\d+', '', objName)
        # if not in active DB try adding from external DB
        if not self.rootToAPNumDic.keys().__contains__(objRoot):
            temp = self.absDictionaryDB.load(objRoot)
            if temp != "null":
                self.rootToAPNumDic[objRoot] = temp

        if (not self.rootToAPNumDic.keys().__contains__(objRoot)):
            self.rootToAPNumDic[objRoot] = objName
            return obj

        if (self.rootToAPNumDic[objRoot] == objName):
            # the mutatable does not have mutations
            return obj
        else:
            APNum = self.rootToAPNumDic[objRoot]
            if (self.APNumToObjDic.keys().__contains__(APNum)):
                return self.APNumToObjDic[APNum].clone()
            else:
                self.loadMutations(obj, objName, objRoot)
                return self.APNumToObjDic[APNum].clone()

    def reqquipMutation(self, mutationAPName: str):
        '''save mutation'''
        self.rootToAPNumDic[re.sub(r'\d+', '', mutationAPName)] = mutationAPName
        self.absDictionaryDB.save(re.sub(r'\d+', '', mutationAPName), mutationAPName)

    def loadMutations(self, obj: Mutatable, objName: str, objRoot: str):
        '''
        make sure all the AP mutation sets of obj are present
        self assumes the last mutation mutates into the prime mutation
        '''
        mutant = obj
        end = objName
        while (True):
            self.APNumToObjDic[obj.__class__.__name__] = obj.clone()
            mutant = obj
            obj = mutant.mutation()
            if (end == obj.__class__.__name__):
                break

    def simpleLoad(self, key: str) -> str:
        return self.absDictionaryDB.load(key)

    def simpleSave(self, key: str, value: str):
        if (key.startswith("AP") or key == "" or value == ""):
            return
        self.absDictionaryDB.save(key, value)


if __name__ == "__main__":
    # Classes creation
    tempClassOne = AbsDictionaryDBShadow()
    tempClassTwo = T1()

    # Testing
    mainTest = GrimoireMemento(tempClassOne)
    mainTest.load(tempClassTwo)
    mainTest.loadMutations(tempClassTwo, "T1", "T")
    print(re.sub(r'\d+', '', '123hello 456world'))
 
  • Like
Reactions: neo

fukurou

the supreme coder
ADMIN
Algorithm

Python:
from __future__ import annotations
from abc import ABC, abstractmethod
from enum import Enum
import re

'''
Failure types:
- ok: no fail
- requip: item should be added
- cloudian: algorithm goes to stand by in its Dclass
- fail: no input
'''

class enumFail(Enum):
    fail = "fail"
    requip = "requip"
    dequip = "dequip"
    cloudian = "cloudian"
    ok = "ok"


class Mutatable(ABC):
    @abstractmethod
    def action(self, ear: str, skin: str, eye: str) -> str:
        """Returns action string"""
        ...

    @abstractmethod
    def failure(self, input: str) -> enumFail:
        """Failure type only mutatable may use enumFail.fail"""
        pass

    @abstractmethod
    def completed(self) -> bool:
        """Has finished ?"""
        pass

    @abstractmethod
    def clone(self) -> Mutatable:
        pass

    def getMutationLimit(self) -> int:
        return 0

    def myName(self) -> str:
        """Returns the class name"""
        return self.__class__.__name__

    def mutation(self) -> Mutatable:
        self.clone()


'''!!! CHILD TEST CLASS TO REMOVE !!!'''

class T1(Mutatable):
    def mutation(self) -> Mutatable:
        print("t1 mutating into t2")
        return T2()

    def clone(self) -> Mutatable:
        print("t1 cloning another t1")
        return T1()

    # Override
    def action(self, ear: str, skin: str, eye: str) -> str:
        """Returns action string"""
        ...

    # Override
    def failure(self, input: str) -> enumFail:
        """Failure type only mutatable may use enumFail.fail"""
        pass

    # Override
    def completed(self) -> bool:
        """Has finished ?"""
        pass

    # Override
    def myName(self) -> str:
        """Returns the class name"""
        return self.__class__.__name__


'''!!! CHILD TEST CLASS TO REMOVE !!!'''

class T2(Mutatable):
    def mutation(self) -> Mutatable:
        print("t2 mutating into t1")
        return T1()

    def clone(self) -> Mutatable:
        print("t2 cloning another t2")
        return T2()

    # Override
    def action(self, ear: str, skin: str, eye: str) -> str:
        """Returns action string"""
        ...

    # Override
    def failure(self, input: str) -> enumFail:
        """Failure type only mutatable may use enumFail.fail"""
        pass

    # Override
    def completed(self) -> bool:
        """Has finished ?"""
        pass

    # Override
    def myName(self) -> str:
        """Returns the class name"""
        return self.__class__.__name__


class AbsDictionaryDB(ABC):
    @abstractmethod
    def save(self, key: str, value: str):
        '''Returns action string'''
        pass

    @abstractmethod
    def load(self, key: str) -> str:
        '''TODO set to return null as default if key not found !!!'''
        pass


class AbsDictionaryDBShadow(AbsDictionaryDB):
    '''used as a fill in class if you want to test the chobit and havent built a DB class yet'''

    # Override
    def save(self, key: str, value: str):
        pass

    # Override
    def load(self, key: str) -> str:
        return "null"


class GrimoireMemento:
    def __init__(self, absDictionaryDB: AbsDictionaryDB) -> None:
        super().__init__()
        self.rootToAPNumDic = {}  # string, string
        self.APNumToObjDic = {}  # string, Mutatable
        self.absDictionaryDB = absDictionaryDB

    def load(self, obj: Mutatable) -> Mutatable:
        '''load final mutation from memory of obj'''
        objName = obj.__class__.__name__
        objRoot = re.sub(r'\d+', '', objName)
        # if not in active DB try adding from external DB
        if not self.rootToAPNumDic.keys().__contains__(objRoot):
            temp = self.absDictionaryDB.load(objRoot)
            if temp != "null":
                self.rootToAPNumDic[objRoot] = temp

        if (not self.rootToAPNumDic.keys().__contains__(objRoot)):
            self.rootToAPNumDic[objRoot] = objName
            return obj

        if (self.rootToAPNumDic[objRoot] == objName):
            # the mutatable does not have mutations
            return obj
        else:
            APNum = self.rootToAPNumDic[objRoot]
            if (self.APNumToObjDic.keys().__contains__(APNum)):
                return self.APNumToObjDic[APNum].clone()
            else:
                self.loadMutations(obj, objName, objRoot)
                return self.APNumToObjDic[APNum].clone()

    def reqquipMutation(self, mutationAPName: str):
        '''save mutation'''
        self.rootToAPNumDic[re.sub(r'\d+', '', mutationAPName)] = mutationAPName
        self.absDictionaryDB.save(re.sub(r'\d+', '', mutationAPName), mutationAPName)

    def loadMutations(self, obj: Mutatable, objName: str, objRoot: str):
        '''
        make sure all the AP mutation sets of obj are present
        self assumes the last mutation mutates into the prime mutation
        '''
        mutant = obj
        end = objName
        while (True):
            self.APNumToObjDic[obj.__class__.__name__] = obj.clone()
            mutant = obj
            obj = mutant.mutation()
            if (end == obj.__class__.__name__):
                break

    def simpleLoad(self, key: str) -> str:
        return self.absDictionaryDB.load(key)

    def simpleSave(self, key: str, value: str):
        if (key.startswith("AP") or key == "" or value == ""):
            return
        self.absDictionaryDB.save(key, value)


'''
ALGORITHM SECTION
'''

class APVerbatim(Mutatable):
    '''this algorithm part says each past param verbatim'''

    def __init__(self, *args) -> None:
        super().__init__()
        self.sentences = []
        self.at = 0

        try:
            if (isinstance(args[0], list)):
                self.sentences = args[0]
                if (0 == len(self.sentences)):
                    self.at = 30
            else:
                for i in range(len(args)):
                    self.sentences.append(args[i])
        except:
            self.at = 30

    # Override
    def action(self, ear: str, skin: str, eye: str) -> str:
        '''TODO Auto-generated method stub'''
        axnStr = ""
        if (self.at < len(self.sentences)):
            axnStr = self.sentences[self.at]
            self.at += 1
        return axnStr

    # Override
    def failure(self, input: str) -> enumFail:
        '''TODO Auto-generated method stub'''
        return enumFail.ok

    # Override
    def completed(self) -> bool:
        '''TODO Auto-generated method stub'''
        return self.at >= len(self.sentences)

    # Override
    def clone(self) -> AbsAlgPart:
        '''TODO Auto-generated method stub'''
        return APVerbatim(self.sentences)


# A step by step plan to achieve a goal
class Algorithm:

    def __init__(self, goal: str, representation: str, algParts: list[Mutatable]):    # list of Mutatable
        super().__init__()
        self.goal = goal
        self.representation = representation
        self.algParts = algParts

    # *constract with string and goal
    @property
    def getGoal(self) -> str:
        return self.goal

    @property
    def getRepresentation(self) -> str:
        return self.representation

    @property
    def getAlgParts(self) -> list[Mutatable]:
        return self.algParts

    def getSize(self) -> int:
        return len(self.algParts)

    def clone(self) -> Algorithm:
        parts = []    # list of Mutatable
        for mutatable in self.algParts:
            parts.append(mutatable.clone())
        return Algorithm(self.goal, self.getRepresentation, parts)


if __name__ == "__main__":
    testOne = APVerbatim("hello")
    testTwo = T1()
    testThree = T2()
    testList = [testOne, testTwo, testThree]
    algorithm = Algorithm("goal", "representation", testList)

    # Printing
    print(algorithm.getAlgParts[0].action("","",""))
    print("This should return 'goal': " + algorithm.getGoal)
    print("This should return 'representation': " + algorithm.getRepresentation)
    print("This should return a list containing 3 objects: " + str(algorithm.getAlgParts))
    print("This should return 3: " + str(algorithm.getSize()))
    algorithmTwo = algorithm.clone()

    # Clone printing
    print("\nThis should return 'goal': " + algorithmTwo.getGoal)
    print("This should return 'representation': " + algorithmTwo.getRepresentation)
    print("This should return a list containing 3 objects: " + str(algorithmTwo.getAlgParts))
    print("This should return 3: " + str(algorithmTwo.getSize()))
 

fukurou

the supreme coder
ADMIN
APCldVerbatim and CldBool

Python:
from __future__ import annotations
from abc import ABC, abstractmethod
from enum import Enum

'''
Failure types:
- ok: no fail
- requip: item should be added
- cloudian: algorithm goes to stand by in its Dclass
- fail: no input
'''


class enumFail(Enum):
    fail = "fail"
    requip = "requip"
    dequip = "dequip"
    cloudian = "cloudian"
    ok = "ok"


class Mutatable(ABC):
    @abstractmethod
    def action(self, ear: str, skin: str, eye: str) -> str:
        """Returns action string"""
        ...

    @abstractmethod
    def failure(self, input: str) -> enumFail:
        """Failure type only mutatable may use enumFail.fail"""
        pass

    @abstractmethod
    def completed(self) -> bool:
        """Has finished ?"""
        pass

    @abstractmethod
    def clone(self) -> Mutatable:
        pass

    def getMutationLimit(self) -> int:
        return 0

    def myName(self) -> str:
        """Returns the class name"""
        return self.__class__.__name__

    def mutation(self) -> Mutatable:
        self.clone()


class t1(Mutatable, ABC):
    def mutation(self) -> Mutatable:
        print("t1 mutating into t2")
        return t2()

    def clone(self) -> Mutatable:
        print("t1 cloning another t1")
        return t1()


class t2(Mutatable, ABC):
    def mutation(self) -> Mutatable:
        print("t2 mutating into t1")
        return t1()

    def clone(self) -> Mutatable:
        print("t2 cloning another t2")
        return t2()


class CldBool:
    # cloudian : this class is used to provide shadow reference to a boolean variable
    def __init__(self):
        self.modeActive = False
    @property
    def getModeActive(self) -> bool:
        return self.modeActive

    def setModeActive(self, modeActive: bool):
        self.modeActive = modeActive


class APCldVerbatim(Mutatable):
    '''this algorithm part says each string param verbatim'''

    def __init__(self, cldBool: CldBool, *words):
        super().__init__()
        self.sentences = []
        self.at = 0
        self.cldBool = cldBool

        try:
            if (isinstance(words[0], list)):
                self.sentences = words[0]
                self.cldBool.setModeActive(True)
            else:
                for i in range(len(words)):
                    self.sentences.append(words[i])
                self.cldBool.setModeActive(True)
        except:
            self.at = 30

    # Override
    def action(self, ear: str, skin: str, eye: str) -> str:
        # TODO Auto-generated method stub
        axnStr = ""
        if (self.at < len(self.sentences)):
            axnStr = self.sentences[self.at]
            self.at += 1

        self.cldBool.setModeActive(not (self.at >= len(self.sentences)))
        return axnStr

    # Override
    def failure(self, input: str) -> enumFail:
        # TODO Auto-generated method stub
        return enumFail.ok

    # Override
    def completed(self) -> bool:
        return self.at >= len(self.sentences)

    # Override
    def clone(self) -> Mutatable:
        # TODO Auto-generated method stub
        return APCldVerbatim(self.cldBool, self.sentences)


if __name__ == "__main__":
    # CldBool testing
    cldBool = CldBool()

    # APCldVerbatim test one
    print("\nTesting the first APCldVerbatim")
    apcOne = APCldVerbatim(cldBool, "hi", "how", "are", "you")
    print(cldBool.modeActive)
    for x in range(6):
        print(apcOne.action("","",""))
    print(cldBool.modeActive)
 

fukurou

the supreme coder
ADMIN
Kokoro and Chi

Python:
from __future__ import annotations
from abc import ABC, abstractmethod
from enum import Enum
import re


'''
Failure types:
- ok: no fail
- requip: item should be added
- cloudian: algorithm goes to stand by in its Dclass
- fail: no input
'''
class enumFail(Enum):
    fail = "fail"
    requip = "requip"
    dequip = "dequip"
    cloudian = "cloudian"
    ok = "ok"


class Mutatable(ABC):
    @abstractmethod
    def action(self, ear: str, skin: str, eye: str) -> str:
        """Returns action string"""
        ...

    @abstractmethod
    def failure(self, input: str) -> enumFail:
        """Failure type only mutatable may use enumFail.fail"""
        pass

    @abstractmethod
    def completed(self) -> bool:
        """Has finished ?"""
        pass

    @abstractmethod
    def clone(self) -> Mutatable:
        pass

    def getMutationLimit(self) -> int:
        return 0

    def myName(self) -> str:
        """Returns the class name"""
        return self.__class__.__name__

    def mutation(self) -> Mutatable:
        self.clone()


'''!!! CHILD TEST CLASS TO REMOVE !!!'''
class T1(Mutatable):
    def mutation(self) -> Mutatable:
        print("t1 mutating into t2")
        return T2()

    def clone(self) -> Mutatable:
        print("t1 cloning another t1")
        return T1()

    # Override
    def action(self, ear: str, skin: str, eye: str) -> str:
        """Returns action string"""
        ...

    # Override
    def failure(self, input: str) -> enumFail:
        """Failure type only mutatable may use enumFail.fail"""
        pass

    # Override
    def completed(self) -> bool:
        """Has finished ?"""
        pass

    # Override
    def myName(self) -> str:
        """Returns the class name"""
        return self.__class__.__name__


'''!!! CHILD TEST CLASS TO REMOVE !!!'''
class T2(Mutatable):
    def mutation(self) -> Mutatable:
        print("t2 mutating into t1")
        return T1()

    def clone(self) -> Mutatable:
        print("t2 cloning another t2")
        return T2()

    # Override
    def action(self, ear: str, skin: str, eye: str) -> str:
        """Returns action string"""
        ...

    # Override
    def failure(self, input: str) -> enumFail:
        """Failure type only mutatable may use enumFail.fail"""
        pass

    # Override
    def completed(self) -> bool:
        """Has finished ?"""
        pass

    # Override
    def myName(self) -> str:
        """Returns the class name"""
        return self.__class__.__name__


class AbsDictionaryDB(ABC):
    @abstractmethod
    def save(self, key: str, value: str):
        '''Returns action string'''
        pass

    @abstractmethod
    def load(self, key: str) -> str:
        '''TODO set to return null as default if key not found !!!'''
        pass


class AbsDictionaryDBShadow(AbsDictionaryDB):
    '''used as a fill in class if you want to test the chobit and havent built a DB class yet'''

    # Override
    def save(self, key: str, value: str):
        pass

    # Override
    def load(self, key: str) -> str:
        return "null"


class GrimoireMemento:
    def __init__(self, absDictionaryDB: AbsDictionaryDB) -> None:
        super().__init__()
        self.rootToAPNumDic:dict[str, str] = {}
        self.APNumToObjDic:dict[str, Mutatable] = {}
        self.absDictionaryDB = absDictionaryDB

    def load(self, obj: Mutatable) -> Mutatable:
        '''load final mutation from memory of obj'''
        objName = obj.__class__.__name__
        objRoot = re.sub(r'\d+', '', objName)
        # if not in active DB try adding from external DB
        if not self.rootToAPNumDic.keys().__contains__(objRoot):
            temp = self.absDictionaryDB.load(objRoot)
            if temp != "null":
                self.rootToAPNumDic[objRoot] = temp

        if (not self.rootToAPNumDic.keys().__contains__(objRoot)):
            self.rootToAPNumDic[objRoot] = objName
            return obj

        if (self.rootToAPNumDic[objRoot] == objName):
            # the mutatable does not have mutations
            return obj
        else:
            APNum = self.rootToAPNumDic[objRoot]
            if (self.APNumToObjDic.keys().__contains__(APNum)):
                return self.APNumToObjDic[APNum].clone()
            else:
                self.loadMutations(obj, objName, objRoot)
                return self.APNumToObjDic[APNum].clone()

    def reqquipMutation(self, mutationAPName: str):
        '''save mutation'''
        self.rootToAPNumDic[re.sub(r'\d+', '', mutationAPName)] = mutationAPName
        self.absDictionaryDB.save(re.sub(r'\d+', '', mutationAPName), mutationAPName)

    def loadMutations(self, obj: Mutatable, objName: str, objRoot: str):
        '''
        make sure all the AP mutation sets of obj are present
        self assumes the last mutation mutates into the prime mutation
        '''
        mutant = obj
        end = objName
        while (True):
            self.APNumToObjDic[obj.__class__.__name__] = obj.clone()
            mutant = obj
            obj = mutant.mutation()
            if (end == obj.__class__.__name__):
                break

    def simpleLoad(self, key: str) -> str:
        return self.absDictionaryDB.load(key)

    def simpleSave(self, key: str, value: str):
        if (key.startswith("AP") or key == "" or value == ""):
            return
        self.absDictionaryDB.save(key, value)


'''
all action data goes through here
 * detects negatives such as : repetition, pain on various levels and failures
 * serves as a database for memories, convos and alg generations
 * can trigger revenge algs
 * checks for % of difference in input for exploration type algs
'''
class Kokoro:
    def __init__(self, absDictionaryDB: AbsDictionaryDB):
        self.emot = ""
        self.pain:dict[str, int] = {}
        self.grimoireMemento = GrimoireMemento(absDictionaryDB)
        self.toHeart:dict[str, str] = {}
        self.fromHeart:dict[str, str] = {}
        self.standBy = False

    def getEmot(self) -> str:
        return self.emot

    def setEmot(self, emot: str):
        self.emot = emot

    def getPain(self, BijuuName: str) -> int:
        try:
            value = self.pain[BijuuName]
        except:
            value = 0
        return value

    def inside(self, chi: Chi):
        pass

    def outside(self, isCompleted: bool, failure: enumFail):
        pass

class Chi(Mutatable):
    '''
    an adaptor pattern to the alg part, it also has the kokoro consiousness
    object to be aware throughout the program of what is happening all action
    data goes through this soul.
    '''
    def __init__(self, kokoro: Kokoro, ofSkill: str, aPart: Mutatable):
        super().__init__()
        self.kokoro = kokoro
        self.ofSkill = ofSkill
        self.aPart = kokoro.grimoireMemento.load(aPart)

    def actualAction(self, ear: str, skin: str, eye: str) -> str:
        return self.aPart.action(ear, skin, eye)

    # Override
    def action(self, ear: str, skin: str, eye: str) -> str:
        self.kokoro.inside(self)
        result = self.actualAction(ear, skin, eye)
        self.kokoro.outside(self.completed(), self.failure(""))
        return result

    # Override
    def failure(self, input: str) -> enumFail:
        # TODO Auto-generated method stub
        return self.aPart.failure(input)

    # Override
    def completed(self) -> bool:
        # TODO Auto-generated method stub
        return self.aPart.completed()

    # Override
    def clone(self) -> Mutatable:
        # TODO Auto-generated method stub
        return Chi(self.kokoro, self.ofSkill, self.aPart.clone())

    # Override
    def getMutationLimit(self) -> int:
        # TODO Auto-generated method stub
        return self.aPart.getMutationLimit()

    # Override
    def mutation(self) -> Mutatable:
        mutant = self.aPart
        tempAP = mutant.mutation()
        self.kokoro.grimoireMemento.reqquipMutation(tempAP.__class__.__name__)
        return Chi(self.kokoro, self.ofSkill, tempAP)

    # Override
    def myName(self) -> str:
        return self.aPart.myName()


if __name__ == "__main__":
    # Kokoro and Chi creation
    mutatable = T1()
    absDB = AbsDictionaryDBShadow()
    kokoro = Kokoro(absDB)
    chi = Chi(kokoro, "skill", mutatable)

    # Kokoro test
    print("\n---- KOKORO TESTING ----")
    print("This should return nothing: " + kokoro.getEmot())
    kokoro.setEmot("smiley")
    print("This should return 'smiley': " + kokoro.getEmot())
    print("This should return 0: " + str(kokoro.getPain("painful")))

    # Chi test
    print("\n---- CHI TESTING ----")
    print("This should return None: " + str(chi.actualAction("ear", "skin", "eye")))
    print("This should return None: " + str(chi.action("ear", "skin", "eye")))
    print("This should return None: " + str(chi.failure("")))
    print("This should return None: " + str(chi.completed()))
    print("This should return 0: " + str(chi.getMutationLimit()))
    print("This should return T1: " + chi.myName())

    # Chi clone testing
    print("\n---- CHI CLONE TESTING ----")
    chiClone = chi.clone()
    print("This should return None: " + str(chiClone.actualAction("ear", "skin", "eye")))
    print("This should return None: " + str(chiClone.action("ear", "skin", "eye")))
    print("This should return None: " + str(chiClone.failure("")))
    print("This should return None: " + str(chiClone.completed()))
    print("This should return 0: " + str(chiClone.getMutationLimit()))
    print("This should return T1: " + chiClone.myName())

    # Chi mutation testing
    print("\n---- CHI MUTATION TESTING ----")
    chiMuta = chi.mutation()
    print("This should return 0: " + str(chiMuta.getMutationLimit()))
    print("This should return T2: " + chiMuta.myName())
    mutatable2 = T2() # dif result from t1 => works
    chi = Chi(kokoro, "skill", mutatable2)
 

fukurou

the supreme coder
ADMIN
DISkillUtils and Neuron

Python:
''' NEURON CLASS '''
# used to transport algorithms to other classes
class Neuron:
    def __init__(self) -> None:
        self.algParts: list[Algorithm] = []
        self.negativeAlgParts: list[Algorithm] = []

    def empty(self):
        self.algParts.clear()
        self.negativeAlgParts.clear()


''' DISKILLUTILS CLASS '''
class DISkillUtils:
    def verbatimGorithmOne(self, itte: Mutatable) -> Algorithm:
        # returns a simple algorithm containing 1 alg part
        representation = "util"
        algParts1: list[Mutatable] = []
        algParts1.append(itte)
        algorithm = Algorithm("util", representation, algParts1)
        return algorithm

    def verbatimGorithmTwo(self, algMarker: str, itte: Mutatable) -> Algorithm:
        # returns a simple algorithm for saying sent parameter
        representation = "util"
        algParts1: list[Mutatable] = []
        algParts1.append(itte)
        algorithm = Algorithm("util", representation, algParts1)
        return algorithm

    def customizedVerbatimGorithm(self, algMarker: str, itte: Mutatable) -> Algorithm:
        # the most stable and advanced algorithm builder
        # returns a simple algorithm containing 1 alg part
        representation = "r_" + algMarker
        algParts1: list[Mutatable] = []
        algParts1.append(itte)
        algorithm = Algorithm(algMarker, representation, algParts1)
        return algorithm

    def customizedVerbatimGorithm(self, algMarker: str, *itte: Mutatable) -> Algorithm:
        # the most stable and advanced algorithm builder
        # returns a simple algorithm containing 1 alg part
        representation = "r_" + algMarker
        algParts1: list[Mutatable] = []
        for i in range (len(itte)):
            algParts1.append(itte[i])
        algorithm = Algorithm(algMarker, representation, algParts1)
        return algorithm

    def simpleVerbatimAlgorithm(self, algMarker: str, *sayThis) -> Algorithm:
        # returns alg that says the word string (sayThis)
        return self.customizedVerbatimGorithm(algMarker, APVerbatim(*sayThis))

    def simpleCloudiandVerbatimAlgorithm(self, cldBool: CldBool, algMarker: str, *sayThis) -> Algorithm:
        # returns alg that says the word string (sayThis)
        return self.customizedVerbatimGorithm(algMarker, 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 ""



if __name__ == "__main__":
    neuron = Neuron()
    diskillUtils = DISkillUtils()
    t1 = T1()
    t2 = T2()
    cldBool = CldBool()
    print("The verbatimGorithm method works if a number is returned: " + str(
        diskillUtils.verbatimGorithmOne(t1).getSize()))
    print("The verbatimGorithm method works if a number is returned: " + str(
        diskillUtils.verbatimGorithmTwo("win", t1).getSize()))
    print("The customizedVerbatimGorithm method works if a number is returned: " + str(
        diskillUtils.customizedVerbatimGorithm("win", t1).getSize()))
    print("The customizedVerbatimGorithm method works if a number is returned: " + str(
        diskillUtils.customizedVerbatimGorithm("win", t1, t2).getSize()))
    print("The simpleVerbatimAlgorithm method works if a number is returned: " + str(
        diskillUtils.simpleVerbatimAlgorithm("win", "hi", "how", "is", "life").getSize()))
    print("The simpleCloudiandVerbatimAlgorithm method works if a number is returned: " + str(
        diskillUtils.simpleCloudiandVerbatimAlgorithm(cldBool, "win", "hello", "I", "am", "here").getSize()))
    alg: Algorithm = diskillUtils.simpleVerbatimAlgorithm("win", "hi", "how", "is", "life")
    x = alg.algParts[0]
    print(x.action("", "", ""))
    print(alg.algParts[0].action("", "", ""))
    print(alg.algParts[0].action("", "", ""))
    print(alg.algParts[0].action("", "", ""))
    print("The strContainsList method returns: " + diskillUtils.strContainsList("my name is Vavuz",
                                                                                ["your", "name", "was", "Rossi"]))
    l: list[str] = ["hey", "you"]
    print(l[1])

see attached the full code with dependencies
 

Attachments

  • DISkillUtils and Neuron.txt
    13.7 KB · Views: 0

fukurou

the supreme coder
ADMIN
DiSkillV2

Python:
''' DISKILLV2 CLASS '''


class DiSkillV2:
    def __init__(self, kokoro: Kokoro):
        # The variables start with an underscore (_) because they are protected
        self._kokoro = kokoro  # consciousness, shallow ref class to enable interskill communications
        self._diSkillUtils = DISkillUtils()
        self._outAlg = None  # skills output

    def input(self, ear: str, skin: str, eye: str):
        pass

    def output(self, noiron: Neuron):
        if (self._outAlg != None):
            noiron.algParts.append(self._outAlg)
            self._outAlg = None

    def auto(self) -> bool:
        """ does this skill also engage by time triggers ? is it also a level > 1 type of
        # skill ? if yes
        # override me and return true """
        return False


if __name__ == "__main__":
    # DiSkillV2 creation
    absDB = AbsDictionaryDBShadow()
    kokoro = Kokoro(absDB)
    diskillv2 = DiSkillV2(kokoro)

    # DiSkillV2 creation
    print("\n---- DISKILLV2 TESTING ----")
    print("This should return False: " + str(diskillv2.auto()))
    print(diskillv2.output(Neuron()))
 

Attachments

  • DiSkillV2.txt
    16 KB · Views: 0

fukurou

the supreme coder
ADMIN
RegexUtil and ZeroTimeGate

Python:
''' ----------------- REGEXUTIL ---------------- '''
import re
from typing import Match, Pattern
from collections import Counter
from math import sqrt


class Point:
    def __init__(self, x_init, y_init):
        self.x = x_init
        self.y = y_init

    def shift(self, x, y):
        self.x += x
        self.y += y

    def __repr__(self):
        return "".join(["Point(", str(self.x), ",", str(self.y), ")"])


def distance(a, b):
    return sqrt((a.x - b.x) ** 2 + (a.y - b.y) ** 2)


''' REGEXUTIL CLASS'''


# returns expression of type theRegex from the string str2Check
class RegexUtil:

    def regexChecker(self, theRegex: str, str2Check: str) -> str:
        regexMatcher = re.search(theRegex, str2Check)
        if (regexMatcher != None):
            return regexMatcher.group(0).strip()
        return ""

    def numberRegex(self, str2Check: str) -> str:
        theRegex = r"[-+]?[0-9]*[.,][0-9]*"
        list1: list[str] = []
        regexMatcher = re.search(theRegex, str2Check)
        if (regexMatcher != None):
            return regexMatcher.group(0).strip()
        return ""

    def timeStampRegex(self, str2Check: str) -> str:
        theRegex = r"(([0-9]|[0-1][0-9]|[2][0-3]):([0-5][0-9])$)|(^([0-9]|[1][0-9]|[2][0-3])$)"
        list1: list[str] = []
        regexMatcher = re.search(theRegex, str2Check)
        if (regexMatcher != None):
            return regexMatcher.group(0).strip()
        return ""

    def intRegex(self, str2Check: str) -> str:
        theRegex = r"[-+]?[0-9]{1,13}"
        list1: list[str] = []
        regexMatcher = re.search(theRegex, str2Check)
        if (regexMatcher != None):
            return regexMatcher.group(0).strip()
        return ""

    def pointRegex(self, str2Check: str) -> Point:
        # "[-+]?[0-9]{1,13}(\\.[0-9]*)?" for double numbers
        theRegex: str = "[-+]?[0-9]{1,13}"
        result: Point = Point(0, 0)
        list1: list[str] = []
        regexMatcher = re.search(theRegex, str2Check)
        if (regexMatcher != None):
            result.y = int(regexMatcher.group(0).strip())
        str2Check = str2Check[str2Check.index(f'{result.y}') + 1:len(str2Check)]
        phase2 = str2Check
        phase2 = self.intRegex(phase2)
        if (phase2 == ""):
            return Point(result.y, 0)

        result.x = int(phase2)
        return Point(result.y, result.x)

    def regexChecker2(self, theRegex: str, str2Check: str) -> list[str]:
        # return a list of all matches

        mylist : list[str] = str2Check.split()
        r = re.compile(theRegex)
        l_final = list(filter(r.match, mylist))
        return l_final

    def contactRegex(self, str2Check: str) -> str:
        # return a list of all matches
        theRegex = r"(?<=contact)(.*)"
        list1: list[str] = []
        regexMatcher = re.search(theRegex, str2Check)
        if (regexMatcher != None):
            return regexMatcher.group(0).strip()
        return ""

    def emailRegex(self, str2Check: str) -> str:
        # return a list of all matches
        theRegex = '([A-Za-z0-9]+[.-_])*[A-Za-z0-9]+@[A-Za-z0-9-]+(\.[A-Z|a-z]{2,})+'
        list1: list[str] = []
        regexMatcher = re.search(theRegex, str2Check)
        if (regexMatcher != None):
            return regexMatcher.group(0).strip()
        return ""

    def duplicateRegex(self, input: str) -> str:
        # first split given string separated by space
        # into words
        words = input.split(' ')

        # now convert list of words into dictionary
        dict = Counter(words)

        # traverse list of words and check which first word
        # has frequency > 1
        for key in words:
            if dict[key] > 1:
                return key
        return ""

    def uniqueWord(self, str1: str) -> str:
        list1: list[str] = []  # of strings
        s = str1.split(" ")
        p = s[0]
        list1.append(p)
        # i
        for i in range(1, len(s)):
            if (not (p == s[i])):
                list1.append(s[i])
            p = s[i]
        return list1[0]

    def afterWord(self, word: str, str2Check: str) -> str:
        # return a list of all matches
        theRegex = r"(?<=" + word + r")(.*)"
        list1: list[str] = []
        regexMatcher = re.search(theRegex, str2Check)
        if (regexMatcher != None):
            return regexMatcher.group(0).strip()
        return ""

    def phoneRegex1(self, str2Check: str) -> str:
        return self.regexChecker(r"[0]\d{2}\d{4}\d{3}$", str2Check)

    def firstWord(self, str2Check: str) -> str:
        arr: list[str] = str2Check.split(" ", 2)
        firstWord = arr[0]  # the
        return firstWord

    def stripAwayNumbers(self, str1: str) -> str:
        return re.sub(r'\d+', '', str1)


''' --------------- ZEROTIMEGATE --------------- '''
import time
import datetime

''' --------------- ZEROTIMEGATE --------------- '''
import time
import datetime
from datetime import timedelta

''' ZEROTIMEGATE CLASS '''


class ZeroTimeGate:
    # a gate that only opens x minutes after it has been set

    def __init__(self, minutes) -> None:
        self.pause: int = 1
        self.openedGate: datetime.date = datetime.datetime.now()
        self.checkPoint: datetime.date = datetime.datetime.now()

        try:
            self.pause = minutes
            try:
                time.sleep(0.1)
            except Exception as e:
                # TODO Auto-generated catch block
                # e.printStackTrace()
                pass
        except:
            pass

    def isClosed(self) -> bool:
        return (self.openedGate < datetime.datetime.now())

    def isOpen(self) -> bool:
        return (not (self.openedGate < datetime.datetime.now()))

    def open(self, minutes: int):
        now: datetime.date = datetime.datetime.now()
        self.openedGate = now + timedelta(minutes=minutes)

    def setPause(self, pause: int):
        if 60 > pause > 0:
            self.pause = pause

    def resetCheckPoint(self):
        self.checkPoint = datetime.datetime.now()

    def getRunTimeTimeDifInSecondes(self) -> int:
        # used to measure code snippets run time
        now: datetime.date = datetime.datetime.now()
        diff: datetime.timedelta = self.checkPoint - now
        return diff.total_seconds()


if __name__ == "__main__":
    # Point testing
    print(" TESTING POINT CLASS")
    point = Point(3, 4)
    print("This should return 3: " + str(point.x))

    # RegexUtil testing
    print("\n TESTING REGEXUTIL CLASS")
    regex = RegexUtil()
    print("The regexChecker method should return the word 'String': " + regex.regexChecker(r"(G*s)", r"Gotta Go Gym"))
    print("The numberRegex method should return ?: " + regex.numberRegex(
        "hello-789.998world"))
    print("The timeStampRegex method should return ?: " + regex.timeStampRegex('the time is 4:35'))
    print("The intRegex method should return ?: " + regex.intRegex('area51 is in nevada'))
    print(regex.pointRegex('coordinate 6.6008').y)
    print("The regexChecker2 method should return ?: ",
          regex.regexChecker2(r"[-+]?[0-9]{1,13}", "1d2d3 23 apple banana 799"))  # err : should return entire list of matches
    # see https://stackoverflow.com/questions/3640359/regular-expressions-search-in-list
    print("The contactRegex method should return ?: " + regex.contactRegex('contact some person'))
    print("The emailRegex method should return ?: " + regex.emailRegex('this is some [email protected] test'))
    print("The duplicateRegex method should return ?: " + regex.duplicateRegex('test hadoken hadoken'))
    print(regex.uniqueWord('one two three three one'))
    print("The afterWord method should return ?: " + regex.afterWord(r"sentence", r"A sentence with String"))
    print("The phoneRegex1 method should return ?: " + regex.phoneRegex1('phone num 0556667766'))
    print("The firstWord method should return ?: " + regex.firstWord(r"A sentence with String"))
    print("strip numbers :")
    print(regex.stripAwayNumbers("h3ll0"))

    # ZeroTimeGate testing
    print("\n TESTING ZEROTIMEGATE CLASS")
    gate = ZeroTimeGate(1)
    print("The isClosed method should return true: ", gate.isClosed())
    print("The isOpen method should return false: ", gate.isOpen())
    print(gate.openedGate)
    gate.open(3)  # gate will stay opened for 3 minutes than close
    print(gate.openedGate)
    print("The isOpen method should return false: ", gate.isOpen())
    print("ret true ", gate.isOpen())  # err
    gate.checkPoint
    print(gate.checkPoint)
    print("time dif ?: ", gate.getRunTimeTimeDifInSecondes())
 
Last edited:

fukurou

the supreme coder
ADMIN
Cerabellum and DExplorer

Python:
''' CERABELLUM CLASS '''


class Cerabellum:
    # runs an algorithm
    def __init__(self) -> None:
        self.fin: int = None
        self.at: int = None
        self.failType: enumFail = None
        self.incrementAt: bool = False
        self.alg: Algorithm = None
        self.isActive: bool = False
        self.emot: str = ""

    def advanceInAlg(self):
        if (self.incrementAt):
            self.incrementAt = False
            self.at += 1
            if (self.at == self.fin):
                self.isActive = False

    def getAt(self) -> int:
        return self.at

    def getEmot(self) -> str:
        return self.emot

    def setAlgorithm(self, algorithm: Algorithm) -> bool:
        if (not (self.isActive) and (algorithm.getAlgParts != None)):
            self.alg = algorithm
            self.at = 0
            self.fin = algorithm.getSize()
            self.isActive = True
            self.emot = self.alg.getAlgParts[self.at].myName()  # updated line
            return False
        return True

    def isActiveMethod(self) -> bool:
        return self.isActive

    def setActiveOne(self, b1: bool) -> bool:
        return self.isActive == b1

    def setActiveTwo(self, isActive_temp: bool):
        self.isActive = isActive_temp

    def act(self, ear: str, skin: str, eye: str) -> str:
        axnStr: str = ""
        if (not self.isActive):
            return axnStr
        if (self.at < self.fin):
            axnStr = self.alg.getAlgParts[self.at].action(ear, skin, eye)
            self.emot = self.alg.getAlgParts[self.at].myName()
            if (self.alg.getAlgParts[self.at].completed()):
                self.incrementAt = True
        return axnStr

    def getMutationLimitOfActiveAlgPart(self) -> int:
        return self.alg.getAlgParts[self.at].getMutationLimit()

    def getFailType(self) -> enumFail:
        return self.alg.getAlgParts[self.at].failure("")


''' DEXPLORER CLASS '''


class DExplorer(DiSkillV2):
    '''
    D class responsible for mutations of algParts (Mutatable)
    '''

    def __init__(self):
        self.failureCounter: int = 0
        self.prevAP: str = ""

    # Override
    def output(self, noiron: Neuron):
        # TODO Auto-generated method stub
        pass

    # Override
    def input(self, ear: str, skin: str, eye: str):
        # TODO Auto-generated method stub
        pass

    def mutate(self, cera: Cerabellum, failure: enumFail):
        AP: str = cera.getEmot()
        '''
        group relies on a naming convention each class in a mutation series must have
        the same class name concated with a number : APMoan1, APMoan2, APMaon3 ...
        '''
        AP = re.sub(r'\d+', '', AP)  # remove numbers from alg part name to account for overall mutations
        # give up ? :
        if ((self.prevAP.count(AP) != 0) and not (failure.name == enumFail.ok.name)):
            self.failureCounter += 1
            if (self.failureCounter > cera.getMutationLimitOfActiveAlgPart()):
                cera.setActiveTwo(False)
                # this.failureCounter = 0;
        else:
            if (not (self.prevAP.count(AP) != 0)):
                self.failureCounter = 0
        self.prevAP = AP
        if (failure.name == "fail"):
            mutant: Mutatable = cera.alg.getAlgParts().get(cera.getAt())
            cera.alg.getAlgParts().set(cera.getAt(), mutant.mutation())
        elif (failure.name == "cloudian"):
            cera.setActiveTwo(False)
 

Attachments

  • Cerabellum and DExplorer.txt
    20.3 KB · Views: 0

fukurou

the supreme coder
ADMIN
Fusion FusionCera and PriorityQueue

Python:
''' PRIORITYQUEUE CLASS '''
# A simple implementation of Priority Queue
# using Queue.
class PriorityQueue(object):
    def __init__(self):
        self.queue = []

    def __str__(self):
        return ' '.join([str(i) for i in self.queue])

    # for checking if the queue is empty
    def isEmpty(self):
        return len(self.queue) == 0

    # for inserting an element in the queue
    def insert(self, data):
        self.queue.append(data)

    # for popping an element based on Priority
    def poll(self) -> object:
        if not len(self.queue) == 0:
            result0 = self.queue[0]
            del self.queue[0]
            return result0
        return None


''' FUSION CLASS '''
class Fusion:
    '''
     * fuses algorithms and sends needed algorithm to a designated cerabellum
     * object for activation
    '''
    def __init__(self, algDurations: dict[str, int]):
        self.AlgDurations: dict[str, int] = None
        self.AlgDurations2: dict[str, int] = {}
        self.emot: str = ""
        self.algQueue: PriorityQueue = PriorityQueue()   # PriorityQueue[Algorithm]
        self.dangerAlgQueue: PriorityQueue = PriorityQueue()   # PriorityQueue[Algorithm]
        self.reqOverload: bool = False # too many requests
        self.repReq: bool = False # chobit has already accepted this request
        self.represantations: list[str] = []
        self.dExplorer: DExplorer = DExplorer()
        self.goalsToTrack: list[str] = ["", ""] # dangerCera, mainCera
        # cerabellums :
        self.dangerCera: Cerabellum = Cerabellum()
        # requip cera
        # fusionCera = (Cerabellum) (new FusionCera(algQueue));
        self.fusionCera: FusionCera = FusionCera(self.algQueue)
        self.mainCera: Cerabellum = Cerabellum()
        # home cera
        # cera = { dangerCera, fusionCera, mainCera };
        self.cera: list[Cerabellum] = [self.dangerCera, self.fusionCera, self.mainCera]
        # end cerabellums
        self.AlgDurations: dict[str, int] = algDurations

    def setAlgQueue(self, shinkei: Neuron):
        # populate cerabellums with algorithms from queues
        for algorithm in shinkei.negativeAlgParts:
            if (len(self.dangerAlgQueue.queue) < 1):
                self.dangerAlgQueue.insert(algorithm.clone())
            else:
                break

        self.repReq = False
        for algorithm in shinkei.algParts:
            self.updateRepresentations()
            if (self.represantations.count(algorithm.getRepresentation) > 0):
                self.repReq = True
                # System.out.println("again with this poo ?");
                continue
            if (len(self.algQueue.queue) < 5):
                self.algQueue.insert(algorithm.clone())
            else:
                break

        self.reqOverload = len(self.algQueue.queue) > 4 and len(shinkei.algParts) > 0
        # empty Neuron
        shinkei.empty()
        if (not(self.dangerCera.isActiveMethod()) and (not(len(self.dangerAlgQueue.queue) == 0))):
            self.dangerCera.setAlgorithm(self.dangerAlgQueue.poll())
            self.goalsToTrack[0] = self.dangerCera.alg.getGoal
            self.goalTrack(self.goalsToTrack[0])
        if (not self.mainCera.isActiveMethod() and not (len(self.algQueue.queue) == 0)):
            self.mainCera.setAlgorithm(self.algQueue.poll())
            self.goalsToTrack[1] = self.mainCera.alg.getGoal
            self.goalTrack(self.goalsToTrack[1])
        self.fuze()

    def getRepReq(self) -> bool:
        # were the same algorithms repeatedly requested ? were the AI negged ?
        return self.repReq

    def getReqOverload(self) -> bool:
        # too many algorithms requested for the time being, queue overlaod (>5 algs)
        return self.reqOverload

    def act(self, ear: str, skin: str, eye: str) -> str:
        result: str = ""
        for i in range(len(self.cera)):
            if (self.cera[i].isActiveMethod()):
                result = self.cera[i].act(ear, skin, eye)
                self.dExplorer.mutate(self.cera[i], self.cera[i].getFailType())
                self.cera[i].advanceInAlg()
                self.emot = self.cera[i].getEmot()
                if (i > 1):
                    n1: int = self.AlgDurations2[self.cera[i].alg.getGoal]
                    self.AlgDurations2[self.cera[i].alg.getGoal] = n1 + 1
                break
            # else(cera notactive) try go home
        return result

    def getEmot(self) -> str:
        return self.emot

    def updateRepresentations(self):
        for algorithm in self.algQueue.queue:
            self.represantations.append(algorithm.getRepresentation)

    def goalTrack(self, goal: str):
        if (not goal in self.AlgDurations2):
            # try to load, if failed :
            self.AlgDurations[goal] = 0
            self.AlgDurations2[goal] = 0
        else:
            self.AlgDurations[goal] = self.AlgDurations2[goal]

    def goalTrackReset(self, goal: str) -> str:
        if (not goal == ""):
            self.AlgDurations2[goal] = 0
        return ""

    def fuze(self):
        if (self.mainCera.isActiveMethod() and not self.fusionCera.isActiveMethod()):
            algRunTime: int = self.AlgDurations[self.mainCera.alg.getGoal]
            algRunTime = algRunTime / 2
            alg1: Algorithm = None
            g1: str = ""
            time1: int = 0
            iterator: Iterable[Algorithm] = iter(self.algQueue.queue)    # Iterator<Algorithm>
            for element in iterator:
                alg1 = element
                g1 = alg1.getGoal
                self.goalTrack(g1)
                time1 = self.AlgDurations[g1]
                if (time1 < algRunTime):
                    self.fusionCera.setAlgorithm(alg1)
                    self.algQueue.queue.remove(alg1)
                    self.fusionCera.setAbort(time1)
                    self.goalTrackReset(g1)
                    break

        self.goalsToTrack[0] = self.goalTrackReset(self.goalsToTrack[0])
        self.goalsToTrack[1] = self.goalTrackReset(self.goalsToTrack[1])


''' FUSIONCERA CLASS '''
class FusionCera(Cerabellum):

    def __init__(self, algQueue: PriorityQueue):
        super().__init__()
        self.abort: int = 0
        self.algQueue: PriorityQueue = algQueue  # PriorityQueue<Algorithm>

    def setAbort(self, abort: int):
        self.abort = abort + 1

    # Override
    def act(self, ear: str, skin: str, eye: str) -> str:
        # TODO Auto-generated method stub
        result: str = super().act(ear, skin, eye)
        self.abort -= 1
        if (self.abort < 1):
            self.setActiveTwo(False)
        else:
            if (not self.isActiveMethod()):
                try:
                    self.algQueue.queue.remove(self.alg)
                except:
                    pass
        return result
 

Attachments

  • Fusion FusionCera and PriorityQueue.txt
    27.5 KB · Views: 0

fukurou

the supreme coder
ADMIN
Permission DPermitter and Personality

Python:
''' PERMISSION CLASS '''


class Permission:
    '''
     * uses two names as lv1,2 permission levels
     * requires password to change password or said names
    '''

    singleton: Permission = None

    def __init__(self, password: str, lv1Name: str, lv2Name: str):
        if Permission.singleton != None:
            raise Exception("singleton cannot be instantiated more than once")
        else:
            self.password: str = password
            self.lv1Name: str = lv1Name
            self.lv2Name: str = lv2Name
            self.permissionLevel: int = None
            Permission.singleton = self

    @staticmethod
    def newInstance(password: str, lv1Name: str, lv2Name: str) -> Permission:
        if (Permission.singleton == None):
            Permission(password, lv1Name, lv2Name)
        return Permission.singleton

    def getPermissionLevel(self) -> int:
        result: int = self.permissionLevel
        self.permissionLevel = 0
        return result

    def setPermissionLevel(self, input: str):
        if (input.count(self.lv2Name) > 0):
            self.permissionLevel = 2
        elif (input.count(self.lv1Name) > 0):
            self.permissionLevel = 1
        if (input.count(self.lv2Name + " reset") > 0):
            self.permissionLevel = 0

    def setPassword(self, oldPassword: str, newPassword: str) -> bool:
        if (self.password == oldPassword):
            self.password = newPassword
            return True
        return False

    def setLv2Name(self, password: str, newName2: str) -> bool:
        if (self.password == password):
            self.lv2Name = newName2
            return True
        return False

    def getLv1Name(self) -> str:
        return self.lv1Name

    def getLv2Command(self, command: str) -> str:
        # returns cmd without lv2 name
        result: str = command
        result = result.replace(self.lv2Name, "")
        return result.strip()

    def setLv1Name(self, password: str, newName: str) -> bool:
        if (self.password == password):
            self.lv1Name = newName
            return True
        return False

    def clsmsg(self) -> str:
        return "chaos ritual\r\n" + "\r\n" + "create two names\r\n" \
               + "one soul will be called to the light\r\n" + "and one will be led by the darkness\r\n" \
               + "and those souls of light and darkness will combine to create\r\n" \
               + "the light of chaos\r\n" + "...\r\n" + "A.G.I descended!"


''' DPERMITTER CLASS'''
'''
   handles permissions using 2 names for the chobit :
 * name one : permission lv1 (engages with friend)
 * name 2 : permission level2 (for doing things with the owner only)
'''


class DPermitter(DiSkillV2):
    '''
     * conjuratis : change pass : oldPass new password newPassword change lv1 name :
     * pass your name is newName change lv2 name : pass you are newName
    '''

    def __init__(self, permission: Permission):
        super()
        self.permission: Permission = permission
        self.permissionLevel: int = 2
        self.regexer: RegexUtil = RegexUtil()

    # Override
    def input(self, ear: str, skin: str, eye: str):
        self.permission.setPermissionLevel(ear)
        self.permissionLevel = self.permission.getPermissionLevel()
        if (ear.count("what is your name") > 0):
            self.outAlg = self.requipSayAlg(self.permission.getLv1Name())
            return

        password: str = self.regexer.regexChecker("(\\w+)(?= you are)", ear)
        newName: str = self.regexer.regexChecker("(?<=you are)(.*)", ear)
        if (self.permission.setLv2Name(password, newName)):
            self.outAlg = self.requipSayAlg("got it")
            return

        password = self.regexer.regexChecker("(\\w+)(?= your name is)", ear)
        newName = self.regexer.regexChecker("(?<=your name is)(.*)", ear)
        if (self.permission.setLv1Name(password, newName)):
            self.outAlg = self.requipSayAlg("new nickname has been established")
            return

        oldPass: str = self.regexer.regexChecker("(\\w+)(?= new password)", ear)
        newPass: str = self.regexer.regexChecker("(?<=new password)(.*)", ear)
        if (self.permission.setPassword(oldPass, newPass)):
            self.outAlg = self.requipSayAlg("new password accepted")
            return

    def getPermissionLevel(self) -> int:
        return self.permissionLevel

    def requipSayAlg(self, replay: str) -> Algorithm:
        itte: Mutatable = APSay(1, replay)
        algParts1: list[Mutatable] = []
        algParts1.append(itte)
        represantation: str = "say " + replay
        return Algorithm("say", represantation, algParts1)


''' PERSONALITY CLASS '''


class Personality:
    '''
    this class is used in the ChobitV2 c'tor.
    it enables loading a complete skill set (a sub class of the personality class)
    using 1 line of code. of course you can also select specific skills to add from
    the subclasses c'tor. see also Personality1 for example.
    '''
    '''
    flight or fight skills may need access to the above fusion class booleans
    on the output methode of a skill this skills will load algorithms to the highest priority of the noiron
    which carries algorithms :
    noiron.negativeAlgParts.add(Algorithm)
    '''

    def __init__(self, *absDictionaryDB: AbsDictionaryDB):
        self._dClassesLv1: list[DiSkillV2] = []  # can engage with anyone
        self._dClassesLv2: list[DiSkillV2] = []  # can engage with friends and work related
        self._dClassesLv3: list[DiSkillV2] = []  # can engage only by user
        self._permission: Permission = Permission.newInstance("password", "sweetie", "honey")
        self._dPermitter: DPermitter = DPermitter(self._permission)  # TODO
        self._AlgDurations: dict[str, int] = {}
        self._fusion: Fusion = Fusion(self._AlgDurations)
        # fusion.getReqOverload() # an overload of requests on the brain
        # fusion.getRepReq() // someone is negging and asking the same thing over and over again
        try:
            if (len(absDictionaryDB) == 1):
                self._kokoro = Kokoro(absDictionaryDB[0])
            else:
                self._kokoro = Kokoro(AbsDictionaryDBShadow())
        except:
            self._kokoro = Kokoro(AbsDictionaryDBShadow())

    def getdClassesLv1(self) -> list[DiSkillV2]:
        return self._dClassesLv1

    def getdClassesLv2(self) -> list[DiSkillV2]:
        return self._dClassesLv2

    def getdClassesLv3(self) -> list[DiSkillV2]:
        return self._dClassesLv3

    def getKokoro(self) -> Kokoro:
        return self._kokoro

    def getPermission(self) -> Permission:
        return self._permission

    def getdPermitter(self) -> DPermitter:
        return self._dPermitter

    def getAlgDurations(self) -> dict[str, int]:
        return self._AlgDurations

    def getFusion(self) -> Fusion:
        return self._fusion


if __name__ == "__main__":
    # Permission testing
    print("Permission testing ---")
    permission: Permission = Permission.newInstance("1234", "Mark", "Luke")
    permission.setPermissionLevel("Luke")
    print("Permission level should be 2: " + str(permission.getPermissionLevel()))
    print("Permission level should be 0: " + str(permission.getPermissionLevel()))
    print("setLv1Name should return True: " + str(permission.setLv1Name("1234", "Gregg")))
    print("Lv1Name should be Gregg: " + permission.getLv1Name())

    # DPermitter testing
    print("\nDPermitter testing ---")
    abs: AbsDictionaryDB = AbsDictionaryDBShadow()
    dpermitter: DPermitter = DPermitter(permission)
    dpermitter.input("what is your name my friend?", "", "")
    print("outAlg representation should be 'say Gregg': " + dpermitter.outAlg.representation)
    algo: Algorithm = dpermitter.requipSayAlg("replay")
    print("Representation should be 'say replay': " + algo.getRepresentation)
    print("cases check")
    dpermitter.input("1234 you are chi", "", "")
    AP = dpermitter.outAlg.getAlgParts[0]
    result = AP.action("","","")
    print(result)

    # Personality testing
    print("\nPersonality testing ---")
    personality: Personality = Personality(abs)
    personality._kokoro.setEmot("screaming")
    print("Kokoro emot: " + personality._kokoro.emot)
    personality: Personality = Personality()
    personality._kokoro.setEmot("laughing")
    print("Kokoro emot: " + personality._kokoro.emot)
 

Attachments

  • Permission DPermitter and Personality.txt
    40.9 KB · Views: 0

fukurou

the supreme coder
ADMIN
Thinkable

Python:
''' Thinkable CLASS '''
class Thinkable :
    def think(self, ear: str, skin: str, eye: str) -> str:
        """override me"""
        return ""
 

fukurou

the supreme coder
ADMIN
Actionable

Python:
''' Actionable CLASS '''


class Actionable:
    def act(self, input: str):
        # override me
        pass
 

fukurou

the supreme coder
ADMIN
Brain

Python:
''' Brain CLASS '''


class Brain:
    def __init__(self, chobit: Thinkable, mvc: Actionable):
        super().__init__()
        self.chi: Thinkable = chobit
        self.mvc: Actionable = mvc

    def doIt(self, ear: str, skin: str, eye: str):
        temp_str: str = self.chi.think(ear, skin, eye)
        self.mvc.act(temp_str)
 
Top