View source with raw comments or as raw
    1/*  Part of ClioPatria SeRQL and SPARQL server
    2
    3    Author:        Jan Wielemaker
    4    E-mail:        J.Wielemaker@cs.vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (C): 2015, University of Amsterdam,
    7		   VU University Amsterdam
    8
    9    This program is free software; you can redistribute it and/or
   10    modify it under the terms of the GNU General Public License
   11    as published by the Free Software Foundation; either version 2
   12    of the License, or (at your option) any later version.
   13
   14    This program is distributed in the hope that it will be useful,
   15    but WITHOUT ANY WARRANTY; without even the implied warranty of
   16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17    GNU General Public License for more details.
   18
   19    You should have received a copy of the GNU General Public
   20    License along with this library; if not, write to the Free Software
   21    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   22
   23    As a special exception, if you link this library with other files,
   24    compiled with a Free Software compiler, to produce an executable, this
   25    library does not by itself cause the resulting executable to be covered
   26    by the GNU General Public License. This exception does not however
   27    invalidate any other reasons why the executable file might be covered by
   28    the GNU General Public License.
   29*/
   30
   31:- module(api_void,
   32	  [
   33	  ]).   34:- use_module(library(http/http_dispatch)).   35:- use_module(library(settings)).   36:- use_module(library(semweb/rdf_turtle_write)).   37:- use_module(library(semweb/rdf_db)).   38:- use_module(library(http/http_host)).   39:- use_module(library(http/http_wrapper)).

Void vocabulary description of the server

See also
- http://www.w3.org/TR/void/ */
   46:- setting(cliopatria:void_file, any, '',
   47	   'File served for /.well-known/void').   48:- setting(cliopatria:void_graph, atom, '',
   49	   'Graph holding void data').   50
   51:- http_handler(cliopatria('.well-known/void'), handle_void,
   52		[id(well_known_void)]).   53
   54handle_void(Request) :-
   55	setting(cliopatria:void_file, File), File \== '',
   56	absolute_file_name(File, Path, [access(exist)]), !,
   57	http_reply_file(Path, [unsafe(true)],  Request).
   58handle_void(Request) :-
   59	setting(cliopatria:void_graph, Graph), Graph \== '',
   60	http_link_to_id(export_graph, graph(Graph), HREF),
   61	http_redirect(see_other, HREF, Request).
   62handle_void(_Request) :-
   63	findall(rdf(S,P,O), void_triple(S,P,O), Triples0),
   64	rdf_global_term(Triples0, Triples),
   65	format('Content-type: application/x-turtle; charset="UTF-8"~n~n'),
   66	rdf_save_turtle(stream(current_output),
   67			[ expand(triple_in(Triples)),
   68			  only_known_prefixes(true)
   69			]).
   70
   71:- public triple_in/5.   72
   73triple_in(RDF, S,P,O,_G) :-
   74	member(rdf(S,P,O), RDF).
 void_triple(+Request, -Subject, -Predicate, -Object)
   78void_triple('_:dataset', rdf:type, void:'DataSet').
   79void_triple('_:dataset', dcterms:creator,
   80	    literal('ClioPatria')).
   81void_triple('_:dataset', dcterms:description,
   82	    literal(lang(en, D))) :-
   83	D = 'This Void dataset description is auto-generated from \c
   84	     the ClioPatria store content. It supports auto-discovery \c
   85	     of the SPARQL endpoint and lists the available named graphs.\n\c
   86	     If you want a nicer document, you can either supply a Turtle \c
   87	     file and use the setting `cliopatria:void_file` to serve this \c
   88	     file from `.well-known/void` or create a named graph in the \c
   89	     RDF store and use the setting `cliopatria:void_graph`.'.
   90void_triple('_:dataset', void:sparqlEndpoint, EndPoint) :-
   91	http_current_request(Request),
   92	http_public_host_url(Request, Host),
   93	http_link_to_id(sparql_query, [], Location),
   94	atom_concat(Host, Location, EndPoint).
   95void_triple(S, P, O) :-
   96	rdf_graph(Graph),
   97	graph_dataset_uri(Graph, DataSet),
   98	graph_triple(Graph, DataSet, S, P, O).
   99
  100graph_triple(_, DataSet, '_:dataset', void:subset, DataSet).
  101graph_triple(_, DataSet, DataSet, rdf:type, void:'DataSet') .
  102graph_triple(Graph, DataSet, DataSet, void:triples, literal(type(xsd:integer, Triples))) :-
  103	rdf_graph_property(Graph, triples(Count)),
  104	atom_number(Triples, Count).
  105graph_triple(Graph, DataSet, DataSet, void:dataDump, Export) :-
  106	http_current_request(Request),
  107	http_public_host_url(Request, Host),
  108	http_link_to_id(export_graph, [graph(Graph)], Location),
  109	atom_concat(Host, Location, Export).
  110
  111
  112graph_dataset_uri(Graph, Graph) :- !,
  113	uri_is_global(Graph).
  114graph_dataset_uri(_, BNode) :-
  115	rdf_bnode(BNode)