}
}
}
}
// MARK: - CYCLE
private func cycle() {
guard var concept = memory.get() else {
return // no concepts in memory
}
let results = concept.cycle()
if let derived = results["Judgement"] {
for j in derived {
buffer.put(Task(sentence: .judgement(j)))
}
}
if let answers = results["Question"] {
if answers.first?.statement == .NULL {
// TODO: finish this !!!
for var chunk in answers.split(separator: .NULL-*) {
let source = chunk.removeFirst()
chunk.reversed().forEach { j in
let q1 = Sentence.question(Question(j.statement, source))
buffer.put(Task(sentence: q1))
}
}
} else {
for a in answers {
output(". 💡 \(a)")
}
}
}
if let answers = results["Goal"] {
// print("A\n", answers, "\n")
if let a = answers.first {
if case .statement(let sub, let cop, _) = a.statement {
if cop == .predictiveImp { // TODO: needs to be done properly
// subject is the subgoal
if case .statement(_, let c, let p) = sub {
// TODO: how to check preconditions?
if c == .predictiveImp { // TODO: `s` precondition need to be checked
if case .operation(let op, let ts) = p {
output(". 🤖 \(p)")
if let operation = operations[op] {
let result = operation(ts) // execute
output(result.description)
} else {
output("Unknown operation \(op)")
}
}
} else {
let gs = Goal(sub)
buffer.put(Task(sentence: .goal(gs)))
}
}
}
}
}
}
// decrease priority
concept.priority = max(concept.priority - 0.01, 0.01)
// storage
memory.put(concept)
}
}
https://api.github.com/maxeeem/NARS-Swift/blob/21e4bc99fdc21b3530cb9bbc57d91b1ec63305be/Code.playground/Sources/NARS/NARS.swift#L256