; test-atomspace-visibility.scm - Verify C++ can see AtomSpace contents
(use-modules (opencog) (opencog exec) (opencog lg))
(use-modules (opencog persist) (opencog persist-rocks))
(use-modules (opencog matrix) (opencog learn))
; Type aliases
(define (ParseNode name) (Anchor (string-append "parse:" name)))
(define (SentenceNode name) (Anchor (string-append "sentence:" name)))
(module-define! (resolve-module '(opencog lg)) 'ParseNode ParseNode)
(module-define! (resolve-module '(opencog lg)) 'SentenceNode SentenceNode)
(display "=== AtomSpace Visibility Test ===\n\n")
; Load data
(display "Loading data...\n")
(define rsn (RocksStorageNode "rocks://data/pairs.rdb"))
(cog-open rsn)
(define ala (make-any-link-api))
(define aca (add-count-api ala))
(define pair-stars (add-pair-stars aca))
(pair-stars 'fetch-pairs)
(format #t "Loaded ~a edges\n\n" (cog-count-atoms 'Edge))
; Check what AtomSpace we're using
(display "=== AtomSpace Info ===\n")
(define current-as (cog-atomspace))
(format #t "Current AtomSpace: ~a\n" current-as)
; (format #t "AtomSpace name: ~a\n" (cog-as-name current-as))
(format #t "Total atoms: ~a\n\n" (cog-count-atoms 'Atom))
; Test: Can we see the word "the" in the atomspace?
(display "=== Word Visibility Test ===\n")
(define the-word (cog-node 'WordNode "the"))
(format #t "Word 'the' exists: ~a\n" (if the-word #t #f))
(when the-word
(format #t "Word 'the' handle: ~a\n" (cog-handle the-word))
(format #t "Word 'the' incoming List count: ~a\n"
(length (cog-incoming-by-type the-word 'List))))
; Test: Can we see Bond "ANY"?
(display "\n=== Bond Visibility Test ===\n")
(define any-bond (cog-node 'BondNode "ANY"))
(format #t "Bond 'ANY' exists: ~a\n" (if any-bond #t #f))
(when any-bond
(format #t "Bond 'ANY' handle: ~a\n" (cog-handle any-bond))
(format #t "Bond 'ANY' incoming Edge count: ~a\n"
(length (cog-incoming-by-type any-bond 'Edge))))
; Test: LgDictEntry - this calls C++ code that should look up in AtomSpace
(display "\n=== LgDictEntry Test (C++ lookup) ===\n")
(display "This will test if C++ code can see our data...\n\n")
; First parse to establish dictionary
(display "Creating LgDict...\n")
(define dict (LgDict "dict-pair"))
(format #t "Dict: ~a\n" dict)
; Now try LgDictEntry - this does a direct C++ lookup
(display "\nLgDictEntry for 'the'...\n")
(catch #t
(lambda ()
(define entry (LgDictEntry (Word "the") dict))
(format #t "Entry: ~a\n" entry)
(define result (cog-execute! entry))
(format #t "Result: ~a\n" result))
(lambda (key . args)
(format #t "Error: ~a ~a\n" key args)))
; Try parsing directly to see verbose output
(display "\n=== Direct Parse Test ===\n")
; Use the lg-dict-entry function if available
(display "Checking LgDictEntry outgoing...\n")
(catch #t
(lambda ()
(define de (LgDictEntry (Word "the") dict (cog-atomspace) rsn))
(format #t "DictEntry: ~a\n" de)
(define res (cog-execute! de))
(format #t "DictEntry result: ~a\n" res))
(lambda (key . args)
(format #t "Error with 4-arg LgDictEntry: ~a ~a\n" key args)))
(cog-close rsn)
(display "\n=== Done ===\n")