Semantic net / learning chatbot for Uno / Zero and better


#1

So basically this is a learning chatbot that tries to make a semantic net of “whoo-hoo”-TEN elements. (Spectacularly more if you are not on an Arduino Uno / Zero.) I, the author, Nino Ivanov, herewith license it under the MIT-licence.

It works as follows: everything you say is with a “head” with a “tail”. Better limit yourself to three element, i.e. a “term” with “two attributes”, or you will swiftly run out of space on the Uno. The term of the head has the tail as properties. When you tell a sentence, 1. it is LEARNED and can be reused in the future, and 2. you receive as “inferences” all the terms in the properties, PROVIDED that properties actually have been learned about them. So when you say (A B C), and we know nothing of B, but we know that (C D E), then ((C D E)) will be your answer. Repeating terms will make old depictions of them inaccessible. When you run out of memory, you may just restart with (cyc).

(defvar xkx '((nil nil nil) (nil nil nil)
 (nil nil nil) (nil nil nil) (nil nil nil) (nil nil nil)
 (nil nil nil) (nil nil nil) (nil nil nil) (nil nil nil)))

(defvar xcx nil)

(defvar xrx nil)

(defun tck (sym kno)
  (if (null kno) nil
    (if (eq sym (caar kno)) (car kno)
        (tck sym (cdr kno)))))

(defun saa (ip)
  (if (null ip) nil
    (let ((ck (tck (car ip) xkx)))
      (if (null ck) (saa (cdr ip))
        (cons ck (saa (cdr ip)))))))

(defun cyc ()
  (loop
    (setq xcx (read))
    (if (null xcx) (return))
    (setq xkx (cons xcx (reverse (cdr (reverse xkx)))))
    (setq xrx (saa (cdr xcx)))
    (gc)
    (print xrx)))

; Sample run - the explanations behind ---- are added as
; commentary. They are not part of the execution.
; (CYC)
; ---- Launch it; each time after the first, there will be
; two statements - the first is the machine inference,
; the second is the human input (which the machine learns).
; An inference is done if a term is mentioned whose
; properties are known. Only the last term’s properties are
; remembered. Maximum ten terms are learned, FIFO based:
; if new terms are learned, old ones are forgotten. Similarly,
; new properties will make old properties inaccessible.
; (JON LOV CAK)Space: 28 bytes, Time: 1352 uS
; HUMAN: ---- John loves cake.
; nil (CAK SO NIC)Space: 46 bytes, Time: 1360 uS
; MACHINE: ---- No inference HUMAN: ---- Cake is so nice.
; nil (PPL LOV CAK)Space: 21 bytes, Time: 1356 uS
; MACHINE: ---- No inference HUMAN: ---- People love cake.
; ((cak so nic)) (JON IS PPL)Space: 25 bytes, Time: 1360 uS
; MACHINE: ---- Cake is so nice. HUMAN: ---- John is a person.
; ((ppl lov cak)) (ANA LOV JON)Space: 41 bytes, Time: 1372 uS
; MACHINE: ---- People love cake. HUMAN: ---- Anna loves John.
; ((jon is ppl)) (BEN LOV ANA)Space: 41 bytes, Time: 1368 uS
; MACHINE: ---- John is a person. HUMAN: ---- Ben loves Anna.
; ((ana lov jon)) (HAT BEN JON)Space: 34 bytes, Time: 1376 uS
; MACHINE: ---- Anna loves John. HUMAN: ---- Does Ben hate John?
; ((ben lov ana) (jon is ppl)) (WHY HAT JON)Space: 32 bytes, Time: 1380 uS
; MACHINE: ---- Ben loves Anna. John is a Person.
; [A bit of a non sequitur… Still, acceptable - this is not logic!]
; HUMAN: ---- Why does he hate John?
; ((hat ben jon) (jon is ppl)) (WHO HAT BEN)Space: 0 bytes, Time: 1372 uS
; MACHINE: ---- Why does Ben hate John? John is a person.
; [Ridiculous, I know. What is this anti-human sort of reasoning?!]
; HUMAN: ---- Who does Ben hate?
; ((hat ben jon) (ben lov ana)) (LOV JON ANA)Space: 23 bytes, Time: 1380 uS
; MACHINE: ---- Does Ben hate John? Ben loves Ana.
; ((jon is ppl) (ana lov jon)) (LOV JON CAK)Space: 23 bytes, Time: 1380 uS
; MACHINE: ---- John is a person. Anna loves John.
; HUMAN: ---- John loves cake.
; ((jon is ppl) (cak so nic)) (LOV PPL CAK)Space: 0 bytes, Time: 1376 uS
; MACHINE: ---- John is a person. Cake is so nice.
; HUMAN: ---- Do people love cake?
; ((ppl lov cak)) nil
; MACHINE: ---- People love cake. HUMAN: ---- Terminate.
; nil ---- End of talk


#2

Nice! It makes more sense if you run it on a platform that allows long symbol names, such as the Arduino Mega 2560, so you can then write:

(john loves cake)

and so on.


#3

Absolutely, you are of course totally right! And what’s more, you are there not limited to “10” symbols or “triplets”… you could write “(john loves tasty cake)” or whatever else!