OverviewFilesCommitsIssuesDocsReleasesPeers

hypercore-kb / opencog-kb / language-learning / chatbot / test-layer1.scm

70 lines · scm ref:
;
; test-layer1.scm - Test Layer 1 counting and PMI
;
; Run: guile -l test-layer1.scm
;

(add-to-load-path (dirname (current-filename)))
(use-modules (opencog))
(use-modules (opencog exec))
(load "layer1.scm")

(display "═══════════════════════════════════════════════════════════════════\n")
(display "   LAYER 1 TEST: Word Pair Counting & PMI                          \n")
(display "═══════════════════════════════════════════════════════════════════\n\n")

;; Test corpus
(define test-corpus '(
  "fish swim in water"
  "birds fly in sky"
  "fish have fins"
  "birds have feathers"
  "fish live in water"
  "cats chase mice"
  "dogs chase cats"
  "fish eat worms"
  "birds eat worms"
  "cats eat fish"
))

(display "Training on corpus:\n")
(for-each
  (lambda (s)
    (display (format #f "  ~a\n" s))
    (layer1-process s))
  test-corpus)

(display "\n─────────────────────────────────────────────────────────────────\n\n")
(display (format #f "Statistics:\n"))
(display (format #f "  Words: ~a\n" (layer1-word-count)))
(display (format #f "  Pairs: ~a\n" (layer1-pair-count)))
(display (format #f "  Observations: ~a\n" (layer1-total-observations)))

(display "\n─────────────────────────────────────────────────────────────────\n\n")
(display "Associations:\n\n")

(for-each
  (lambda (word)
    (display (show-associations word))
    (display "\n\n"))
  '("fish" "birds" "cats" "water"))

(display "─────────────────────────────────────────────────────────────────\n\n")
(display "PMI tests:\n\n")

(for-each
  (lambda (pair)
    (display (show-pmi (car pair) (cadr pair)))
    (newline))
  '(("fish" "swim")
    ("fish" "water")
    ("fish" "fly")
    ("birds" "fly")
    ("birds" "water")
    ("cats" "chase")
    ("cats" "swim")))

(display "\n═══════════════════════════════════════════════════════════════════\n")
(display "   TEST COMPLETE                                                    \n")
(display "═══════════════════════════════════════════════════════════════════\n")