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)).
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).
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)
Void vocabulary description of the server