forked from webyrd/mediKanren
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrapi-tests.rkt
160 lines (144 loc) · 3.74 KB
/
trapi-tests.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#lang racket/base
(provide trapi-response)
(require
"../../medikanren2/trapi.rkt"
"../../medikanren2/lw-reasoning.rkt"
racket/file racket/function racket/list racket/hash
(except-in racket/match ==)
racket/port
racket/pretty
racket/runtime-path
racket/string
json
)
;; Simple tests for TRAPI interpreter
(define q (string->jsexpr #<<EOS
{
"message": {
"query_graph": {
"edges": {
"e00": {
"subject": "n00",
"object": "n01",
"predicates": ["biolink:gene_associated_with_condition"]
}
},
"nodes": {
"n00": {
"ids" : ["UniProtKB:P51587"],
"categories": ["biolink:biological_entity"]
},
"n01": {
"categories": ["biolink:Disease"],
"is_set" : true
}
}
}
}
}
EOS
))
;; Using knowledge_graph
(define q2 (string->jsexpr #<<EOS
{
"message": {
"query_graph": {
"edges": {
"e00": {
"subject": "n00",
"object": "n01",
"predicates" : ["biolink:treats"]
}
},
"nodes": {
"n00": {
"ids" : ["CHEBI:6801XXX"]
},
"n01": {
"categories": ["biolink:Disease"]
}
}
},
"knowledge_graph" : {
"nodes": {
"MONDO:0005148": {"name": "type-2 diabetes", "category":"biolink:Disease"},
"CHEBI:6801XXX": {"name": "metformin", "category": "drug"}
},
"edges": {
"df87ff82": {"subject": "CHEBI:6801XXX", "predicate": "biolink:treats", "object": "MONDO:0005148"}
}
}
}
}
EOS
))
(define q3 (string->jsexpr #<<EOS
{
"message": {
"query_graph": {
"edges": {
"e01": {
"object": "n0",
"subject": "n1",
"predicates":["biolink:has_phenotype"]
}
},
"nodes": {
"n0": {
"ids": ["MONDO:0007114"],
"categories":["biolink:Disease"]
},
"n1": {
"categories": ["biolink:PhenotypicFeature"]
}
}
}
}
}
EOS
))
(define q4 (string->jsexpr #<<EOS
{
"message": {
"query_graph": {
"edges": {
"e00": {
"subject": "n00",
"object": "n01",
"predicates": ["biolink:regulates"],
"use_reasoning" : true
}
},
"nodes": {
"n00": {
"ids" : ["GO:0002862"],
"use_reasoning" : true
},
"n01": {
"categories": ["biolink:BiologicalProcess"]
}
}
}
}
}
EOS
))
(define m4 (hash-ref q4 'message))
(let ((results (time (trapi-response m4))))
(display (jsexpr->string results))
(printf "\nSize:~s\n" (length (hash-ref results 'results '()))))
;; (lw-reasoning? #t)
;; (define m1 (hash-ref q 'message))
;; (define m2 (hash-ref q2 'message))
;; (define m3 (hash-ref q3 'message))
;; (define r (time (trapi-response m1)))
;; (display (jsexpr->string r))
;; (printf "\nSize:~s\n" (length (hash-ref r 'results '())))
;; (printf "\n=====\n")
;; (define r2 (time (trapi-response m2)))
;; (display (jsexpr->string r2))
;; (printf "\nSize:~s\n" (length (hash-ref r2 'results '())))
;; (printf "\n=====\n")
;; (define r3 (time (trapi-response m3)))
;; (display (jsexpr->string r3))
;; (printf "\nSize:~s\n" (length (hash-ref r3 'results '())))