|
36 | 36 |
|
37 | 37 |
|
38 | 38 |
|
39 | | -process_request(Request):- |
40 | | - memberchk(request_uri(Uri), Request), |
41 | | - uri_components(Uri, uri_components(_,_,_,QueryString,_)), |
42 | | - uri_query_components(QueryString, Query), |
43 | | - memberchk(guideline=Guideline, Query), |
44 | | - interactingRecommendationsList(List, Guideline), |
45 | | - reply_json_dict(json{recommendations: List}). |
46 | | - |
| 39 | +/* *********************************** */ |
| 40 | +% Initialization/Loading functions |
47 | 41 | init:- |
48 | 42 | http_server(http_dispatch, [port(3030)]), |
49 | 43 | load_data, |
|
70 | 64 | ). |
71 | 65 |
|
72 | 66 |
|
| 67 | +/* *********************************** */ |
| 68 | +% API functions |
| 69 | + |
| 70 | +process_request(Request) :- |
| 71 | + memberchk(request_uri(Uri), Request), |
| 72 | + uri_components(Uri, uri_components(_,_,_,QueryString,_)), |
| 73 | + uri_query_components(QueryString, Query), |
| 74 | + memberchk(type=Type, Query), |
| 75 | + ( |
| 76 | + Type = 'getGuidelines' |
| 77 | + -> |
| 78 | + setof(CIG, guideline(CIG), CIGsList), |
| 79 | + reply_json_dict(json{guidelines: CIGsList}) |
| 80 | + ; |
| 81 | + Type = 'getRecommendations' |
| 82 | + -> |
| 83 | + memberchk(guideline=Guideline, Query), |
| 84 | + setof(Rec, rec(Rec, Guideline), RecList), |
| 85 | + reply_json_dict(json{recommendations: RecList}) |
| 86 | + ; |
| 87 | + Type = 'getInteractions' |
| 88 | + -> |
| 89 | + %run the rules just for the requered guidelines? (instead of running on initialization?) |
| 90 | + memberchk(guideline=Guideline, Query), |
| 91 | + setof(InteractionDict, interactingRecommendations(InteractionDict, Guideline), IntRecList), |
| 92 | + reply_json_dict(json{interactions: IntRecList}) |
| 93 | + %; |
| 94 | + %Type = 'mergeGuidelines' |
| 95 | + %-> |
| 96 | + %memberchk(listCIGs=ListCIGs, Query), |
| 97 | + %mergeCGs(ListCIGs, newCIGURI), |
| 98 | + %reply_json_dict(json{mergedCIG: newCIGURI}) |
| 99 | + ). |
| 100 | + |
73 | 101 |
|
74 | 102 |
|
75 | 103 | /* *********************************** */ |
76 | | -% guideline(G) |
77 | 104 | % ** check if a resource is a Guideline |
78 | 105 | % ** retrieves all guidelines |
79 | 106 | guideline(G) :- |
|
82 | 109 |
|
83 | 110 |
|
84 | 111 | /* *********************************** */ |
85 | | -% recommendation(R, Guideline, Value, Belief) |
86 | | -% ** check if ... |
87 | 112 | % ** given a guideline, retrieves its recommendations and features |
| 113 | +recommendation(Rec, Guideline, Value, Belief) :- |
| 114 | + rdf(Rec, rdf:type, tmr:'Recommendation'), |
| 115 | + rdf(Rec, tmr:'partOf', Guideline), |
| 116 | + rdf(Rec, tmr:'hasValue', literal(type(xsd:string, Value))), |
| 117 | + rdf(Rec, tmr:'basedOn', Belief). |
| 118 | + |
88 | 119 | % ** retrieves guidelines and their recommendations |
89 | | -recommendation(R, Guideline, Value, Belief) :- |
90 | | - rdf(R, rdf:type, tmr:'Recommendation'), |
91 | | - rdf(R, tmr:'partOf', Guideline), |
92 | | - rdf(R, tmr:'hasValue', literal(type(xsd:string, Value))), |
93 | | - rdf(R, tmr:'basedOn', Belief). |
| 120 | +rec(Rec, Guideline) :- |
| 121 | + rdf(Rec, rdf:type, tmr:'Recommendation'), |
| 122 | + rdf(Rec, tmr:'partOf', Guideline). |
94 | 123 |
|
95 | 124 |
|
96 | 125 | /* *********************************** */ |
97 | | -% causationBelief(B, Value, Cause, Effect) |
98 | | -% ** check if ... |
99 | 126 | % ** given a belief retrieves its features |
100 | 127 | % ** retrieves all belief and its features |
101 | 128 | causationBelief(B, Value, Cause, Effect) :- |
|
106 | 133 |
|
107 | 134 |
|
108 | 135 | /* *********************************** */ |
109 | | -% careActionT(A) |
110 | 136 | % ** check if a resource is a Action Type |
111 | 137 | % ** retrieves all Action Types |
112 | 138 | careActionT(A) :- |
113 | 139 | rdf(A, rdf:type, Type), |
114 | 140 | rdf_reachable(Type, rdfs:subClassOf, tmr:'CareActionType'). |
115 | | - %, !. ??? |
116 | 141 |
|
117 | 142 | subsumesActionT(ActionSuperT, ActionT) :- |
118 | 143 | ( subsumes(ActionSuperT, ActionT) -> true |
|
133 | 158 | subsumes(ST, T) :- |
134 | 159 | ST \= T, |
135 | 160 | rdf_reachable(ST, tmr:'subsumes', T). |
136 | | -% ( |
137 | | -% rdf(ST, tmr:'subsumes', T) -> true |
138 | | -% ; |
139 | | -% rdf(ST, tmr:'subsumes', T1), |
140 | | -% subsumes(T1, T) |
141 | | -% ). |
142 | 161 |
|
143 | 162 |
|
144 | 163 | /* *********************************** */ |
145 | | -% transitionT(A) |
146 | 164 | % ** check if a resource is a Transition Type |
147 | 165 | % ** retrieves all Transition Types |
148 | 166 | transitionT(T) :- |
|
152 | 170 |
|
153 | 171 |
|
154 | 172 | /* *********************************** */ |
155 | | -% inverseTransition(T1, T2) |
156 | 173 | % ** check if two resources are inverse transitions |
157 | 174 | % ** given a transition, retrives the inverse ones |
158 | 175 | % ** retrieves all pairs of inverse transitions |
|
172 | 189 | ). |
173 | 190 |
|
174 | 191 | /* *********************************** */ |
175 | | -% interaction(IntType, Rec1, Rec2, Interaction) |
176 | 192 | % ** check if there is an interaction of a certain type for recommendations |
177 | 193 | % ** given an Interaction Type, retrieves the interactions |
178 | 194 | % ** retrieves all interactions and related pair of recommendations |
|
185 | 201 |
|
186 | 202 |
|
187 | 203 | /* *********************************** */ |
188 | | -interactionsList(IntList) :- |
189 | | - setof([IntType,List], sameInteractions(IntType, List), IntList). |
190 | | - |
191 | | -sameInteractions(IntType, ListSameInt) :- |
192 | | - rdf_reachable(IntTypeURI, rdfs:subClassOf, tmr4i:'InternalRecommendationInteraction'), |
193 | | - rdf(I1, rdf:type, IntTypeURI), |
194 | | - rdf_global_id(tmr4i:IntType, IntTypeURI), |
195 | | - setof(I2, (rdf_reachable(I1, owl:sameAs, I2); rdf_reachable(I2, owl:sameAs, I1)) |
196 | | - , ListSameInt). |
197 | | - |
198 | | -/* *********************************** */ |
199 | | -% interactingRecommendationsList(Interaction, IntType, List) |
200 | | -% 'Contradiction', [a,b] |
201 | | -% 'Contradiction', [a,c] |
202 | | -% 'Alternative', [a,d,e] |
203 | | -interactingRecommendationsList(IntRecList, Guideline) :- |
204 | | - setof([IntType,List], interactingRecommendations(IntType, List, Guideline), IntRecList). |
205 | | - |
206 | | -interactingRecommendations(IntType, List, Guideline) :- |
| 204 | +% retrieves a dictionary interacting recommendations and the type |
| 205 | +interactingRecommendations(InteractionDict, Guideline) :- |
207 | 206 | rdf_reachable(IntTypeURI, rdfs:subClassOf, tmr4i:'InternalRecommendationInteraction'), |
208 | 207 | rdf(Interaction, rdf:type, IntTypeURI), |
209 | 208 | rdf_global_id(tmr4i:IntType, IntTypeURI), |
210 | | - setof(Rec, interactionRecommendation(Interaction, Rec, Guideline), List). |
| 209 | + setof(Rec, interactionRecommendation(Interaction, Rec, Guideline), List), |
| 210 | + InteractionDict = interaction{type:IntType, recList:List}. |
211 | 211 |
|
212 | 212 | interactionRecommendation(Interaction, Recommendation, Guideline) :- |
213 | 213 | (rdf_reachable(Interaction, owl:sameAs, I2) |
|
220 | 220 |
|
221 | 221 |
|
222 | 222 | /* *********************************** */ |
223 | | -% existsInteraction(IntType, Rec1, Rec2) |
224 | 223 | % ** Assert an interaction of a certain type between the two recommendations |
225 | 224 | existsInteraction(IntType, Rec1, Rec2) :- |
226 | 225 | ( rdf_global_id(tmr4i:IntType, IntTypeURI), |
|
245 | 244 |
|
246 | 245 |
|
247 | 246 | /* *********************************** */ |
248 | | -% inferInternalInteractions(G) |
249 | 247 | % ** infer the internal interactions for all the recommendations in a guideline |
250 | 248 | inferInternalInteractions :- |
251 | 249 | % check Opposed Beliefs |
|
394 | 392 |
|
395 | 393 |
|
396 | 394 | /* *********************************** */ |
397 | | -% inferExternalInteractions(G) |
398 | 395 | % ** infer external interactions for all the recommendations in a guideline |
399 | 396 | inferExternalInteractions(G) :- |
400 | 397 | guideline(G), |
401 | 398 | loadExternalBeliefs(G). |
402 | 399 | %forall( )... |
403 | 400 |
|
404 | 401 | /* *********************************** */ |
405 | | -% loadExternalBeliefs(G) |
406 | 402 | % ** Load external causation beliefs relevants to a guideline |
407 | 403 | loadExternalBeliefs(G) :- |
408 | 404 | guideline(G). |
409 | 405 | %load relevant data from drugbank & sider |
410 | 406 |
|
411 | | - |
412 | | - |
413 | | -/* *********************************** */ |
414 | | - % >>>> Logical programing: given NameSpace and Resource |
415 | | - % it returns the NameRes |
416 | | - % atom_concat(NameSpace, NameRes, Resource) |
417 | | - % Non determinism: it can return multiple answers |
418 | | - % atom_concat(X, Y, abc). |
419 | | - |
420 | | - |
421 | 407 | /* *********************************** */ |
422 | 408 | % different(Resource1, Resource2) {CWA - Negation as failure} |
423 | 409 | % check if two resources not the same |
|
460 | 446 | * 9) How would I use it in python ? |
461 | 447 | % https://github.com/SWI-Prolog/swish/blob/master/client/sin-table.html |
462 | 448 |
|
| 449 | +
|
463 | 450 | */ |
0 commit comments