/* 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(earl, [ earl_report/2 % +Results, +Options ]). :- use_module(library(semweb/rdf_db)). :- use_module(library(semweb/rdf_turtle_write)). :- use_module(library(option)). :- use_module(library(apply)). /** Generate an EARL report */ :- rdf_register_prefix(dc, 'http://purl.org/dc/elements/1.1/'). :- rdf_register_prefix(earl, 'http://www.w3.org/ns/earl#'). :- rdf_register_prefix(foaf, 'http://xmlns.com/foaf/0.1/'). :- rdf_register_prefix(doap, 'http://usefulinc.com/ns/doap#'). %% earl_report(+Results, +Options) % % Generate an EARL report in a given graph. Options processed: % % * project(+Project) % RDF file holding project data. % * graph(Graph) % Destination graph earl_report(Results, Options) :- load_project(Options, Props), put_dict(Props, Options, Options1), maplist(earl_result(Options1), Results), save_results(Options1). load_project(Options, earl{project:Project, tester:Tester, graph:Graph}) :- option(project(Header), Options, 'earl_header.ttl'), option(graph(Graph), Options, earl), module_property(earl, file(Base)), absolute_file_name(Header, File, [ relative_to(Base), access(read) ]), rdf_load(File, [graph(Graph)|Options]), rdf(Project, rdf:type, doap:'Project', Graph), rdf(Tester, rdf:type, foaf:'Person', Graph). earl_result(Dict, Result) :- rdf_bnode(BN), rdf_bnode(ResNode), Graph = Dict.graph, xsd_date_time(Result.date, Date), rdf_global_id(earl:Result.outcome, OutCome), rdf_assert(BN, rdf:type, earl:'Assertion', Graph), rdf_assert(BN, earl:result, ResNode, Graph), rdf_assert(ResNode, rdf:type, earl:'TestResult', Graph), rdf_assert(ResNode, dc:date, Date, Graph), rdf_assert(ResNode, earl:outcome, OutCome, Graph), rdf_assert(BN, earl:assertedBy, Dict.tester, Graph), rdf_assert(BN, earl:subject, Dict.project, Graph), rdf_assert(BN, earl:test, Result.test, Graph). xsd_date_time(Stamp, literal(type(DT, String))) :- rdf_equal(xsd:dateTime, DT), format_time(atom(String), '%FT%T%:z', Stamp). %% save_results(+Options) is det. % % Save the result ERAL graph into File if save(File) is provided. save_results(Options) :- _{save:File} :< Options, !, rdf_save_turtle(File, [ graph(Options.graph), only_known_prefixes(true) ]). save_results(_).