; test-atomspace-identity.scm - Verify AtomSpace identity
(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 Identity Test ===\n\n")
; Get the current atomspace BEFORE loading anything
(define as-before (cog-atomspace))
(format #t "AtomSpace before load: ~a\n" as-before)
; Load data
(display "\nLoading 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)
; Get atomspace AFTER loading
(define as-after (cog-atomspace))
(format #t "AtomSpace after load: ~a\n" as-after)
(format #t "\nSame atomspace? ~a\n" (equal? as-before as-after))
(format #t "Edges in atomspace: ~a\n\n" (cog-count-atoms 'Edge))
; Check if the word "the" is in this atomspace
(display "=== Word Lookup Test ===\n")
(define the-word (cog-node 'WordNode "the"))
(format #t "Word 'the' found: ~a\n" (if the-word #t #f))
(when the-word
(format #t "Word handle: ~a\n" (cog-handle the-word))
(format #t "Incoming Lists: ~a\n" (length (cog-incoming-by-type the-word 'List))))
; Now construct the LgParseLink and check what atomspace it uses
(display "\n=== LgParseLink AtomSpace Check ===\n")
(define parse-link
(LgParseLink
(Phrase "the cat")
(LgDict "dict-pair")
(Number 3)
(cog-atomspace)
rsn))
; Check the outgoing set
(define outgoing (cog-outgoing-set parse-link))
(format #t "Outgoing set length: ~a\n" (length outgoing))
(format #t "Position 0 (Phrase): ~a\n" (list-ref outgoing 0))
(format #t "Position 1 (Dict): ~a\n" (list-ref outgoing 1))
(format #t "Position 2 (Number): ~a\n" (list-ref outgoing 2))
(format #t "Position 3 (AtomSpace): ~a\n" (list-ref outgoing 3))
(format #t "Position 4 (Storage): ~a\n" (list-ref outgoing 4))
; Verify the atomspace in position 3 is the same as our working atomspace
(define as-in-link (list-ref outgoing 3))
(format #t "\nAtomSpace in link: ~a\n" as-in-link)
(format #t "Same as working AS? ~a\n" (equal? as-in-link (cog-atomspace)))
; Execute and check result
(display "\n=== Execute ===\n")
(define result (cog-execute! parse-link))
(format #t "Result: ~a\n" result)
(cog-close rsn)
(display "\n=== Done ===\n")