Skip to content

Commit 7fd7f54

Browse files
committed
Improved processRequest function to handle different types of request: getGuidelines, getRecommendations and getInteractions.
getInteractions now returns a list of Interactions-Dictionary including the list of interacting recommendations and the type of interaction.
1 parent 79cb3fb commit 7fd7f54

1 file changed

Lines changed: 50 additions & 63 deletions

File tree

metis/metis.pl

Lines changed: 50 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,8 @@
3636

3737

3838

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
4741
init:-
4842
http_server(http_dispatch, [port(3030)]),
4943
load_data,
@@ -70,10 +64,43 @@
7064
).
7165

7266

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+
73101

74102

75103
/* *********************************** */
76-
% guideline(G)
77104
% ** check if a resource is a Guideline
78105
% ** retrieves all guidelines
79106
guideline(G) :-
@@ -82,20 +109,20 @@
82109

83110

84111
/* *********************************** */
85-
% recommendation(R, Guideline, Value, Belief)
86-
% ** check if ...
87112
% ** 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+
88119
% ** 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).
94123

95124

96125
/* *********************************** */
97-
% causationBelief(B, Value, Cause, Effect)
98-
% ** check if ...
99126
% ** given a belief retrieves its features
100127
% ** retrieves all belief and its features
101128
causationBelief(B, Value, Cause, Effect) :-
@@ -106,13 +133,11 @@
106133

107134

108135
/* *********************************** */
109-
% careActionT(A)
110136
% ** check if a resource is a Action Type
111137
% ** retrieves all Action Types
112138
careActionT(A) :-
113139
rdf(A, rdf:type, Type),
114140
rdf_reachable(Type, rdfs:subClassOf, tmr:'CareActionType').
115-
%, !. ???
116141

117142
subsumesActionT(ActionSuperT, ActionT) :-
118143
( subsumes(ActionSuperT, ActionT) -> true
@@ -133,16 +158,9 @@
133158
subsumes(ST, T) :-
134159
ST \= T,
135160
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-
% ).
142161

143162

144163
/* *********************************** */
145-
% transitionT(A)
146164
% ** check if a resource is a Transition Type
147165
% ** retrieves all Transition Types
148166
transitionT(T) :-
@@ -152,7 +170,6 @@
152170

153171

154172
/* *********************************** */
155-
% inverseTransition(T1, T2)
156173
% ** check if two resources are inverse transitions
157174
% ** given a transition, retrives the inverse ones
158175
% ** retrieves all pairs of inverse transitions
@@ -172,7 +189,6 @@
172189
).
173190

174191
/* *********************************** */
175-
% interaction(IntType, Rec1, Rec2, Interaction)
176192
% ** check if there is an interaction of a certain type for recommendations
177193
% ** given an Interaction Type, retrieves the interactions
178194
% ** retrieves all interactions and related pair of recommendations
@@ -185,29 +201,13 @@
185201

186202

187203
/* *********************************** */
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) :-
207206
rdf_reachable(IntTypeURI, rdfs:subClassOf, tmr4i:'InternalRecommendationInteraction'),
208207
rdf(Interaction, rdf:type, IntTypeURI),
209208
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}.
211211

212212
interactionRecommendation(Interaction, Recommendation, Guideline) :-
213213
(rdf_reachable(Interaction, owl:sameAs, I2)
@@ -220,7 +220,6 @@
220220

221221

222222
/* *********************************** */
223-
% existsInteraction(IntType, Rec1, Rec2)
224223
% ** Assert an interaction of a certain type between the two recommendations
225224
existsInteraction(IntType, Rec1, Rec2) :-
226225
( rdf_global_id(tmr4i:IntType, IntTypeURI),
@@ -245,7 +244,6 @@
245244

246245

247246
/* *********************************** */
248-
% inferInternalInteractions(G)
249247
% ** infer the internal interactions for all the recommendations in a guideline
250248
inferInternalInteractions :-
251249
% check Opposed Beliefs
@@ -394,30 +392,18 @@
394392

395393

396394
/* *********************************** */
397-
% inferExternalInteractions(G)
398395
% ** infer external interactions for all the recommendations in a guideline
399396
inferExternalInteractions(G) :-
400397
guideline(G),
401398
loadExternalBeliefs(G).
402399
%forall( )...
403400

404401
/* *********************************** */
405-
% loadExternalBeliefs(G)
406402
% ** Load external causation beliefs relevants to a guideline
407403
loadExternalBeliefs(G) :-
408404
guideline(G).
409405
%load relevant data from drugbank & sider
410406

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-
421407
/* *********************************** */
422408
% different(Resource1, Resource2) {CWA - Negation as failure}
423409
% check if two resources not the same
@@ -460,4 +446,5 @@
460446
* 9) How would I use it in python ?
461447
% https://github.com/SWI-Prolog/swish/blob/master/client/sin-table.html
462448
449+
463450
*/

0 commit comments

Comments
 (0)