; test-lgparse.scm - Test Link Grammar parsing with dict-pair
(use-modules (opencog) (opencog exec) (opencog lg))
(use-modules (opencog persist) (opencog persist-rocks))
(use-modules (opencog matrix) (opencog learn))
(display "Testing Link Grammar parsing with dict-pair...\n\n")
; First, we need to set up the type aliases that the learn module expects
(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)
; Open RocksDB and load pairs
(display "Opening RocksDB and loading pairs...\n")
(define rsn (RocksStorageNode "rocks://data/pairs.rdb"))
(cog-open rsn)
; Create matrix API and load pairs
(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 "Pairs loaded. Edges: ~a, Words: ~a\n"
(cog-count-atoms 'Edge)
(length (cog-get-atoms 'WordNode)))
; Test 0: Try demo-atomese first to verify atomese support works
(display "\nTest 0: LgParseLink with demo-atomese\n")
(catch #t
(lambda ()
(define test-result-0
(cog-execute!
(LgParseLink
(Phrase "The dog runs")
(LgDict "demo-atomese")
(Number 1)
(cog-atomspace))))
(format #t "Result 0: ~a\n" test-result-0))
(lambda (key . args)
(format #t "Error in Test 0: ~a ~a\n" key args)))
; Test 1: LgParseLink with dict-pair and AtomSpace
(display "\nTest 1: LgParseLink with dict-pair\n")
(catch #t
(lambda ()
(define test-result-1
(cog-execute!
(LgParseLink
(Phrase "The cat sat")
(LgDict "dict-pair")
(Number 1)
(cog-atomspace))))
(format #t "Result 1: ~a\n" test-result-1))
(lambda (key . args)
(format #t "Error in Test 1: ~a ~a\n" key args)))
; Test 2: Check if we have pairs for test words
(display "\nTest 2: Check word pairs in AtomSpace\n")
(format #t "Pairs for 'the': ~a\n"
(length (cog-incoming-by-type (Word "the") 'List)))
(format #t "Pairs for 'cat': ~a\n"
(length (cog-incoming-by-type (Word "cat") 'List)))
(format #t "Pairs for 'sat': ~a\n"
(length (cog-incoming-by-type (Word "sat") 'List)))
; Test 3: Check if the-cat pair exists
(display "\nTest 3: Check specific pair 'the'-'cat'\n")
(define the-cat-list (List (Word "the") (Word "cat")))
(define the-cat-edge (cog-link 'Edge (Bond "ANY") the-cat-list))
(if the-cat-edge
(format #t "Edge 'the'-'cat' exists: ~a\n" the-cat-edge)
(format #t "Edge 'the'-'cat' does NOT exist\n"))
; Close storage
(cog-close rsn)
(display "\nDone.\n")