;
; test-self-knowledge.scm - Test that the program can understand itself
;
; Feed the program knowledge about what it IS, then verify it can
; answer questions about its own nature.
;
(use-modules (opencog))
(use-modules (ice-9 rdelim))
(use-modules (ice-9 format))
(primitive-load "atomspace-learner.scm")
;; ═══════════════════════════════════════════════════════════════════
;; LOAD SELF-KNOWLEDGE
;; ═══════════════════════════════════════════════════════════════════
(define (load-self-knowledge filename)
"Load and process self-knowledge file"
(display "Loading self-knowledge...\n")
(let ((port (open-input-file filename)))
(let loop ((line (read-line port)) (count 0))
(if (eof-object? line)
(begin
(close-port port)
(display (format #f "Processed ~a lines\n" count)))
(begin
;; Skip comments and empty lines
(unless (or (string-null? (string-trim-both line))
(string-prefix? "#" (string-trim-both line)))
(process-text! line))
(loop (read-line port) (+ count 1)))))))
;; ═══════════════════════════════════════════════════════════════════
;; RUN TESTS
;; ═══════════════════════════════════════════════════════════════════
(define (run-self-knowledge-tests)
(display "\n")
(display "════════════════════════════════════════════════════════════\n")
(display " SELF-KNOWLEDGE TEST: Does the program understand itself?\n")
(display "════════════════════════════════════════════════════════════\n\n")
;; Load self-knowledge
(load-self-knowledge "data/self-knowledge.txt")
;; Run structure discovery
(display "\nDiscovering structures from PMI...\n")
(discover-all-structures!)
;; Show stats
(display "\n--- Stats ---\n")
(display (show-stats))
(display "\n")
;; Test questions about itself
(display "\n--- Self-Awareness Tests ---\n\n")
(define tests
'(("what is atomspace" "Should know AtomSpace is knowledge store")
("what is opencog" "Should know it's part of OpenCog")
("what is pmi" "Should know PMI measures associations")
("what do I contain" "Should know its own structure")
("what is vagueness" "Should know vagueness is uncertainty")
("what is counting" "Should know counting builds evidence")))
(for-each
(lambda (test)
(let ((question (car test))
(expected (cadr test)))
(display (format #f "Q: ~a\n" question))
(display (format #f "A: ~a\n" (respond question)))
(display (format #f " (~a)\n\n" expected))))
tests)
;; Show key units
(display "\n--- Key Self-Knowledge Units ---\n\n")
(for-each
(lambda (word)
(when (> (get-unit-count word) 0)
(display (show-unit word))
(display "\n\n")))
'("atomspace" "opencog" "pmi" "counting" "knowledge" "contains"))
;; Show learning priorities (vagueness-driven)
(display "\n--- Learning Priorities (Vagueness-Driven) ---\n\n")
(display (show-learning-priorities 10))
(display "\n")
(display "\n════════════════════════════════════════════════════════════\n")
(display " END OF TESTS\n")
(display "════════════════════════════════════════════════════════════\n"))
;; Run tests if executed directly
(when (and (defined? 'command-line)
(> (length (command-line)) 1)
(string=? (cadr (command-line)) "test"))
(run-self-knowledge-tests))