%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % The Rule-based Service for the % W3C Health Care and Life Science Database % % It uses the mirror hosted as DERI % % http://hcls.deri.ie/hcls_demo.html % % It allows to query the HCLS SPARQL endpoint and retrieve the % data in the selected output format %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % import of additional ContractLog libraries (modules) :-eval(consult('ContractLog/utils.prova')). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Meta-data facts about services % TODO outsource this data to a Semantic Web description %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% service(hcls,"http://hcls.deri.ie/sparql/",xml). service(hcls,"http://hcls.deri.ie/sparql/",html). service(hcls,"http://hcls.deri.ie/sparql/",json). service(hcls,"http://hcls.deri.ie/sparql/",javascript). % public function interfaces of this rule service % describes the function signatures and types (untyped variables are also supported) % and the mode declarations and gives a narrative description for human % consumption interface(performative(Performative), performative("?"), "pragmatic performatives of this agent/service"). interface(service(ServiceName,ServiceURL,ServiceOutputFormat),service("?","?","?"), "service description including the supported output formats"). interface(interface(Signature,ModeDeclaration,Description),service("?","?","?"), "interface description of the public rule functions of this rule service"). interface(retrieveData(Result, Service, Format, Query), retrieveDate("-","+","+","+"), "submits a Query to the W3C HCLS SPARQL service and returns the Result data in the selected Format"). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % general rule for receiving query messages % the rules first tries to understand the pragmatic context % and then tries to answer the query %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% rcvMsg(XID,esb ,From, Performative, [X|Args]) :- understandPerformative(XID, From, Performative, [X|Args]), answerQuery(XID, From, Performative, [X|Args]). rcvMsg(XID,esb ,From, Performative, [X|Args]):- sendMsg(XID,esb,From,no_further_answers,[X|Args]). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % rules for processing the query %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % simple taxonomy of performatives for queries % query = request performative(request):-performative(query). performative(query). understandPerformative(XID, From, Performative, PayLoad) :- performative(Performative). understandPerformative(XID, From, Performative, PayLoad) :- not(performative(Performative)), sendMsg(XID,esb,From,answer, notUnderstood(Performative)), fail(). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % rules for answering the query %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % answers query answerQuery(XID, From, Performative, [X|Args]):- derive([X|Args]), sendMsg(XID,esb,From, answer, [X|Args]), !. answerQuery(XID, From, Performative, [X|Args]):- sendMsg(XID,esb,From,answer, notUnderstood([X|Args])), fail(). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Internal rule base of the HCLS Rule Service %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Submits a Query to a HCLS Service % and returns the Result data in the selected % Format % % modes signature: retrieveDate(-, +,+,+) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% retrieveData(Result, Service, Format, Query):- bound(Service), bound(Query), bound(Format), buildServiceURL(URL,Service, Format, Query), InputStream = URL.openStream(), OutStream = java.io.ByteArrayOutputStream(), copy_stream(InputStream,OutStream), byte_stream(Result,"UTF-8",OutStream). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Submits a Query to a HCLS Service % and returns the Result as a StreamReader % % modes signature: retrieveReader(-, +,+,+) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% retrieveReader(Reader, Service, Format, Query):- bound(Service), bound(Query), bound(Format), buildServiceURL(URL,Service, Format, Query), InputStream = URL.openStream(), Reader=java.io.InputStreamReader(InputStream).