OverviewFilesCommitsIssuesDocsReleasesPeers

hypercore-kb / opencog-kb / language-learning / mvp / test-grammar-phase.scm

47 lines · scm ref:
;;
;; test-grammar-phase.scm — Test the grammar phase functions
;;
;; Load this in CogServer after corpus-learning.scm:
;;   (load "test-grammar-phase.scm")
;;

(format #t "~%═══ TESTING GRAMMAR PHASE ═══~%~%")

;; Step 1: Build class-MI cache
(format #t "Step 1: Building class-MI cache...~%")
(cl-build-class-mi-cache!)

;; Step 2: Export grammar dictionary
(format #t "~%Step 2: Exporting grammar dictionary...~%")
(cl-export-grammar!)

;; Step 3: Test grammar parse
(format #t "~%Step 3: Testing grammar parse...~%")
(let ((test-sentences '(("the" "cat" "sat" "on" "the" "mat")
                        ("she" "had" "not" "been" "there")
                        ("every" "quasar" "oscillated" "rapidly"))))
  (for-each
    (lambda (words)
      (let* ((word-edges (cpu-pmfg-parse words))
             (gram-edges (cl-grammar-parse words))
             (gs (cl-grammar-surprise words)))
        (format #t "  ~a~%" words)
        (format #t "    word-parse edges: ~a~%" (length word-edges))
        (format #t "    gram-parse edges: ~a~%" (length gram-edges))
        (format #t "    grammar-surprise: ~,3f~%~%" gs)))
    test-sentences))

;; Step 4: Show grammar status
(grammar-status)

;; Step 5: Show crawl status
(crawl-status)

;; Step 6: Test crawler on existing corpus
(format #t "~%Step 6: Testing crawler on corpus/incoming/ ...~%")
(let ((incoming-dir (string-append *mvp-dir* "/corpus/incoming/")))
  (format #t "  Directory: ~a~%" incoming-dir)
  (format #t "  (Would need .txt files to process)~%"))

(format #t "~%═══ GRAMMAR PHASE TEST COMPLETE ═══~%~%")