-
Notifications
You must be signed in to change notification settings - Fork 53
/
simple-query.rkt
90 lines (73 loc) · 2.81 KB
/
simple-query.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#lang racket
(provide
(all-from-out "../../medikanren/mk.rkt")
(all-from-out "../../medikanren/db.rkt")
(all-from-out "../../medikanren/mk-db.rkt")
(all-from-out "../../medikanren/common.rkt")
(all-from-out racket/date)
(all-defined-out))
(require
"../../medikanren/mk.rkt"
"../../medikanren/db.rkt"
"../../medikanren/mk-db.rkt"
"../../medikanren/common.rkt"
"../../attic/medikanren/create-all-hashtables.rkt"
racket/date
(except-in racket/match ==))
#|
concept format (subject or object), without dbname at front:
`(,cid ,cui ,name (,catid . ,cat) . ,props)
concept format (subject or object), with dbname at front (as used in fuzzy-concepto):
`(,dbname ,cid ,cui ,name (,catid . ,cat) . ,props)
edge format, without dbname at front:
`(,eid (,scid ,scui ,sname (,scatid . ,scat) . ,sprops)
(,ocid ,ocui ,oname (,ocatid . ,ocat) . ,oprops)
(,pid . ,pred) . ,eprops)
edge format, with dbname at front (as used in edgeo):
`(,dbname ,eid (,scid ,scui ,sname (,scatid . ,scat) . ,sprops)
(,ocid ,ocui ,oname (,ocatid . ,ocat) . ,oprops)
(,pid . ,pred) . ,eprops)
|#
(displayln "loading semmed knowledge graph")
(define semmed (make-db "../../medikanren/data/semmed"))
(printf "\n\nfull semmed edge:\n")
(run 1 (edge) (db:edgeo semmed edge))
(printf "\n\nTyped query 1:\n")
(run 1 (q)
(fresh (edge1
eid1 scid1 scui1 sname1 scatid1 scat1 sprops1
ocid1 ocui1 oname1 ocatid1 ocat1 oprops1
pid1 pred1 eprops1)
(== `(,eid1 (,scid1 ,scui1 ,sname1 (,scatid1 . ,scat1) . ,sprops1)
(,ocid1 ,ocui1 ,oname1 (,ocatid1 . ,ocat1) . ,oprops1)
(,pid1 . ,pred1) . ,eprops1)
edge1)
(== `(,sname1 ,pred1 ,oname1) q)
(db:edgeo semmed edge1)))
(printf "\n\nTyped query 2:\n")
(run 1 (q)
(fresh (edge1
eid1 scid1 scui1 sname1 scatid1 scat1 sprops1
ocid1 ocui1 oname1 ocatid1 ocat1 oprops1
pid1 pred1 eprops1)
(== `(,eid1 (,scid1 ,scui1 ,sname1 (,scatid1 . ,scat1) . ,sprops1)
(,ocid1 ,ocui1 ,oname1 (,ocatid1 . ,ocat1) . ,oprops1)
(,pid1 . ,pred1) . ,eprops1)
edge1)
(== '(5 . "chemical_substance") `(,scatid1 . ,scat1))
(== `(,sname1 ,pred1 ,oname1) q)
(db:edgeo semmed edge1)))
(printf "\n\nTyped query 3:\n")
(run 1 (q)
(fresh (edge1
eid1 scid1 scui1 sname1 scatid1 scat1 sprops1
ocid1 ocui1 oname1 ocatid1 ocat1 oprops1
pid1 pred1 eprops1)
(== `(,eid1 (,scid1 ,scui1 ,sname1 (,scatid1 . ,scat1) . ,sprops1)
(,ocid1 ,ocui1 ,oname1 (,ocatid1 . ,ocat1) . ,oprops1)
(,pid1 . ,pred1) . ,eprops1)
edge1)
(== '(5 . "chemical_substance") `(,scatid1 . ,scat1))
(== '(1 . "treats") `(,pid1 . ,pred1))
(== `(,sname1 ,pred1 ,oname1) q)
(db:edgeo semmed edge1)))