%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % The Rule-based Service for the GoPubMed Services % % http://www.gopubmed.org/ % % It allows to query the GoPubMed services and retrieve the % data in the selected output format % % Currently the queries to GoPubMed are written in the native % GoPubMed query syntax, but it is straightforward to % add further transformation rules, which translate from a % common platform-independent query language such as % XQuery, SQL, SPARQL into the platform-specific query language % of the service (following the idea of web service and RPC % calls wrapped in SOAP) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 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(goPubMed,"http://www.gopubmed.org/",text). service(goPubMed,"http://www.gopubmed.org/",rdf). service(goPubMed,"http://www.gopubmed.org/",xml). service(goPubMedStatistic,"http://www.gopubmed.org/",xml). % 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]). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Internal non-public rule base of the GoPubMed Rule Service %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Submits a Query to a GoPubMed 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(Result1,"UTF-8",OutStream), Result = java.net.URLEncoder.encode(Result1,"UTF-8"). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Submits a Query to a GoPubMed 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).