;
; test-anproto.scm - Test ANProto knowledge acquisition
;
; Feed self-knowledge + ANProto knowledge, then test:
; 1. Can it answer ANProto questions?
; 2. Does it discover ANProto structures?
; 3. What are its vagueness-driven learning priorities?
;
(use-modules (opencog))
(use-modules (ice-9 rdelim))
(use-modules (ice-9 format))
(primitive-load "atomspace-learner.scm")
;; ═══════════════════════════════════════════════════════════════════
;; FILE LOADER
;; ═══════════════════════════════════════════════════════════════════
(define (load-knowledge filename)
"Load and process knowledge file line by line"
(display (format #f "Loading ~a...\n" filename))
(let ((port (open-input-file filename))
(count 0))
(let loop ((line (read-line port)))
(if (eof-object? line)
(begin
(close-port port)
(display (format #f " Processed ~a lines\n" count)))
(begin
(let ((trimmed (string-trim-both line)))
(unless (or (string-null? trimmed)
(string-prefix? "#" trimmed))
(process-text! trimmed)
(set! count (+ count 1))))
(loop (read-line port)))))))
;; ═══════════════════════════════════════════════════════════════════
;; RUN TESTS
;; ═══════════════════════════════════════════════════════════════════
(define (section title)
(display (format #f "\n--- ~a ---\n\n" title)))
(define (run-anproto-tests)
(display "\n")
(display "════════════════════════════════════════════════════════════\n")
(display " ANProto Knowledge Test: Can the program learn ANProto?\n")
(display "════════════════════════════════════════════════════════════\n\n")
;; Load knowledge
(load-knowledge "data/self-knowledge.txt")
(load-knowledge "data/anproto-knowledge.txt")
;; Run structure discovery
(display "\nDiscovering structures from PMI...\n")
(discover-all-structures!)
;; Stats
(section "Stats")
(display (show-stats))
(display "\n")
;; ANProto questions
(section "ANProto Questions (Call/Response)")
(define anproto-questions
'("what is anproto"
"what is keypair"
"what is signature"
"what is signing"
"what is verification"
"how do you create keypair"
"how do you send message"
"what is public key"))
(for-each
(lambda (q)
(display (format #f "Q: ~a\n" q))
(display (format #f "A: ~a\n\n" (respond q))))
anproto-questions)
;; Key ANProto units
(section "ANProto Units (Full Knowledge State)")
(for-each
(lambda (word)
(when (> (get-unit-count word) 0)
(display (show-unit word))
(display "\n\n")))
'("anproto" "keypair" "signature" "signing" "message"
"verification" "hash" "content" "public" "secret"))
;; Learning priorities
(section "Learning Priorities (Vagueness-Driven)")
(display (show-learning-priorities 15))
(display "\n")
;; Grounding check
(section "Grounding Analysis")
(for-each
(lambda (word)
(let ((g (grounding-score word))
(s (structural-score word))
(v (unit-vagueness word)))
(when (> (get-unit-count word) 0)
(display (format #f " ~a: grounding=~,2f structure=~,2f vagueness=~,3f ~a\n"
word g s v
(cond
((and (> g 1.0) (> s 1.0)) "[GROUNDED]")
((> s 1.0) "[structural only]")
((> g 1.0) "[operational only]")
(else "[VAGUE]")))))))
'("anproto" "keypair" "signature" "signing" "message"
"verification" "hash" "content" "public" "secret"
"create" "send" "sign" "verify"))
(display "\n════════════════════════════════════════════════════════════\n")
(display " END OF TESTS\n")
(display "════════════════════════════════════════════════════════════\n"))
;; Run
(when (and (defined? 'command-line)
(> (length (command-line)) 1)
(string=? (cadr (command-line)) "test"))
(run-anproto-tests))