/* Part of ClioPatria SeRQL and SPARQL server Author: Jan Wielemaker E-mail: J.Wielemaker@cs.vu.nl WWW: http://www.swi-prolog.org Copyright (C): 2013, University of Amsterdam, VU University Amsterdam This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA As a special exception, if you link this library with other files, compiled with a Free Software compiler, to produce an executable, this library does not by itself cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ :- module(rdf_mt_manifest, [ load_manifest/2, % +File, +Options clean_manifests/0, mf_test/1, % ?Test mf_rdf/3, % S,P,O mf_member/2 % ?URI, +Collection ]). :- use_module(library(semweb/turtle)). :- use_module(library(semweb/rdf_db)). :- use_module(library(apply)). :- use_module(library(http/http_open)). :- use_module(library(http/http_ssl_plugin)). /** Process an RDF test manifest */ :- dynamic mf_rdf/3, mf_manifest/1. % URI :- rdf_meta mf_rdf(r, r, o). :- rdf_register_prefix( mf, 'http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#'). :- rdf_register_prefix( rdft, 'http://www.w3.org/ns/rdftest#'). %% load_manifest(+File, +Options) % % Load a new manifest load_manifest(URL, _Options) :- uri_is_global(URL), !, atom_concat('__', URL, BNPrefix), setup_call_cleanup( http_open(URL, In, [ cert_verify_hook(ssl_verify) ]), rdf_read_turtle(In, Triples, [anon_prefix(BNPrefix)]), close(In)), maplist(mf_assert, Triples), assert(mf_manifest(URL)). load_manifest(File, _Options) :- uri_file_name(URI, File), atom_concat('__', URI, BNPrefix), rdf_read_turtle(File, Triples, [anon_prefix(BNPrefix)]), maplist(mf_assert, Triples), assert(mf_manifest(URI)). :- public ssl_verify/5. %% ssl_verify(+SSL, +ProblemCert, +AllCerts, +FirstCert, +Error) % % Accept all certificates. ssl_verify(_SSL, _ProblemCertificate, _AllCertificates, _FirstCertificate, _Error). mf_assert(rdf(S,P,O)) :- assert(mf_rdf(S,P,O)). %% mf_test(?Test) :- % % True when Test is a test in the manifest mf_test(Test) :- mf_rdf(MF, rdf:type, mf:'Manifest'), mf_rdf(MF, mf:entries, Entries), mf_member(Test, Entries). %% clean_manifests % % Remove data loaded from manifests clean_manifests :- retractall(mf_manifest(_)), retractall(mf_rdf(_,_,_)). %% mf_member(?URI, +Collection) mf_member(URI, Collection) :- mf_rdf(Collection, rdf:first, URI). mf_member(URI, Collection) :- mf_rdf(Collection, rdf:rest, Next), mf_member(URI, Next).