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@vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (c)  2015-2018, University of Amsterdam,
    7                              VU University Amsterdam
    8    All rights reserved.
    9
   10    Redistribution and use in source and binary forms, with or without
   11    modification, are permitted provided that the following conditions
   12    are met:
   13
   14    1. Redistributions of source code must retain the above copyright
   15       notice, this list of conditions and the following disclaimer.
   16
   17    2. Redistributions in binary form must reproduce the above copyright
   18       notice, this list of conditions and the following disclaimer in
   19       the documentation and/or other materials provided with the
   20       distribution.
   21
   22    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   23    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   24    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   25    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   26    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   27    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   28    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   29    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   30    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   31    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   32    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   33    POSSIBILITY OF SUCH DAMAGE.
   34*/
   35
   36:- module(api_void,
   37          [
   38          ]).   39:- use_module(library(http/http_dispatch)).   40:- use_module(library(settings)).   41:- use_module(library(semweb/rdf_turtle_write)).   42:- use_module(library(semweb/rdf_db)).   43:- use_module(library(http/http_host)).   44:- use_module(library(http/http_wrapper)).

Void vocabulary description of the server

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