Created
April 24, 2020 12:00
-
-
Save Habush/2f103b4d71dbbba8e8e9ef2fd90d2587 to your computer and use it in GitHub Desktop.
A simple demonstration of using fibers for annotation scheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (atomese->graph in out) | |
(define (expr->graph thing) | |
(match (cog-type thing) | |
;; nodes | |
((or 'PredicateNode | |
'GeneNode | |
'MoleculeNode 'ConceptNode) (format #f "~s~%" (cog-name thing))) | |
;; links | |
((or 'ListLink 'SetLink 'AndLink OrLink 'MemberLink 'EvaluationLink 'InheritanceLink) | |
(format #f "~s~%|~%~/~{~s ~}~%" (cog-type thing) (map expr->graph (cog-outgoing-set thing)))) | |
;; This shouldn't happen | |
(unknown #f)) | |
) | |
(let loop () | |
(put-message out (expr->graph (get-message in))) | |
(loop) | |
) | |
) | |
(define (generate-result atoms out) | |
(for-each (lambda (atom) | |
(put-message out atom)) | |
atoms | |
) | |
) | |
(define (write-to-file in port) | |
(let loop () | |
(put-string port (get-message in)) | |
(loop) | |
) | |
) | |
(define (main) (run-fibers (lambda () | |
(let ( | |
[ch1 (make-channel)] | |
[ch2 (make-channel)] | |
[port (open-output-file "/opt/annotation-scheme/test.txt")] | |
) | |
(spawn-fiber (lambda () (atomese->graph ch1 ch2))) | |
(spawn-fiber (lambda () (write-to-file ch2 port))) | |
(generate-result sample-atoms ch1) | |
(close-port port) | |
) | |
))) | |
(define sample-atoms (list | |
(EvaluationLink | |
(PredicateNode "has_name") | |
(ListLink | |
(ConceptNode "GO:0015219") | |
(ConceptNode "protein-DNA complex transmembrane transporter activity"))) | |
(EvaluationLink | |
(PredicateNode "has_name") | |
(ListLink | |
(ConceptNode "GO:1902084") | |
(ConceptNode "fumagillin metabolic process")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment