swift port 040224

fukurou

the supreme coder
ADMIN
Swift:
func isEmptied() -> Bool {
    return self.strings.count == 0
}
that's the drawRnd add on
 

fukurou

the supreme coder
ADMIN
Swift:
class RailChatBot {
    private var dic: [String: RefreshQ] = [:]
    private var context: String = "default"

    init() {
        self.dic[context] = RefreshQ()
    }

    func setContext(context: String) {
        if context.isEmpty { return }
        self.context = context
    }

    func respondMonolog(ear: String) -> String {
        if ear.isEmpty { return "" }
        if dic[ear] == nil {
            dic[ear] = RefreshQ()
        }
        let temp: String = dic[ear]?.getRNDElement() ?? ""
        if !temp.isEmpty { context = temp }
        return temp
    }

    func learn(ear: String) {
        if ear.isEmpty { return }
        if dic[ear] == nil {
            dic[ear] = RefreshQ()
            dic[context]?.add(element: ear)
            context = ear
            return
        }
        dic[context]?.add(element: ear)
        context = ear
    }

    func monolog() -> String {
        return respondMonolog(context: context)
    }

    func respondDialog(ear: String) -> String {
        if ear.isEmpty { return "" }
        if dic[ear] == nil {
            dic[ear] = RefreshQ()
        }
        let temp: String = dic[ear]?.getRNDElement() ?? ""
        return temp
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class RailChatBot {
    private var dic: [String: RefreshQ] = [:]
    private var context: String = "default"

    init() {
        self.dic[context] = RefreshQ()
    }

    func setContext(context: String) {
        if context.isEmpty { return }
        self.context = context
    }

    func respondMonolog(ear: String) -> String {
        if ear.isEmpty { return "" }
        if dic[ear] == nil {
            dic[ear] = RefreshQ()
        }
        let temp: String = dic[ear]?.getRndItem() ?? ""
        if !temp.isEmpty { context = temp }
        return temp
    }

    func learn(ear: String) {
        if ear.isEmpty { return }
        if dic[ear] == nil {
            dic[ear] = RefreshQ()
            dic[context]?.input(in1: ear)
            context = ear
            return
        }
        dic[context]?.input(in1: ear)
        context = ear
    }

    func monolog() -> String {
        return respondMonolog(ear: context)
    }

    func respondDialog(ear: String) -> String {
        if ear.isEmpty { return "" }
        if dic[ear] == nil {
            dic[ear] = RefreshQ()
        }
        let temp: String = dic[ear]?.getRndItem() ?? ""
        return temp
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class OnOffSwitch {
    private var mode: Bool = false
    private var timeGate: TimeGate = TimeGate(5)
    private var on: Responder = Responder(responses: ["on","talk to me"])
    private var off: Responder = Responder(responses: ["off","stop","shut up", "shut it","whatever","whateva"])

    func setPause(minutes: Int) {
        self.timeGate.setPause(minutes: minutes)
    }

    func setOn(on: Responder) {
        self.on = on
    }

    func setOff(off: Responder) {
        self.off = off
    }

    func getMode(ear: String) -> Bool {
        if on.responsesContainsStr(str: ear) {
            timeGate.openGate()
            mode = true
            return true
        } else if off.responsesContainsStr(str: ear) {
            timeGate.close()
            mode = false
        }
        if timeGate.isClosed() { mode = false }
        return mode
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class OnOffSwitch {
    private var mode: Bool = false
    private var timeGate: TimeGate = TimeGate(pause: 5)
    private var on: Responder = Responder("on","talk to me")
    private var off: Responder = Responder("off","stop","shut up", "shut it","whatever","whateva")

    func setPause(minutes: Int) {
        self.timeGate.setPause(pause: minutes)
    }

    func setOn(on: Responder) {
        self.on = on
    }

    func setOff(off: Responder) {
        self.off = off
    }

    func getMode(ear: String) -> Bool {
        if on.contains(str: ear) {
            timeGate.openGate()
            mode = true
            return true
        } else if off.contains(str: ear) {
            timeGate.closeGate()
            mode = false
        }
        if timeGate.isClosed() { mode = false }
        return mode
    }
}
 
Top