:- module(lod_load, [ lod_load/1, % +URL sindice_query/3 % +Query, +Page, -URL ]). :- use_module(library(semweb/rdf_db)). :- use_module(library(semweb/rdfs)). :- use_module(library(uri)). :- use_module(library(semweb/rdf_turtle)). :- use_module(library(semweb/rdf_http_plugin)). /** Simple Linked Open Data query facility */ % Common RDF prefixes :- rdf_register_ns(skos, 'http://www.w3.org/2004/02/skos/core#'). :- rdf_register_ns(sindice, 'http://sindice.com/vocab/search#'). :- rdf_register_ns(dbpprop, 'http://dbpedia.org/property/'). :- rdf_register_ns(dbpedia, 'http://dbpedia.org/resource/'). :- rdf_register_ns('dbpedia-owl', 'http://dbpedia.org/ontology/'). :- rdf_register_ns(dcterms, 'http://purl.org/dc/terms/'). :- rdf_register_ns(foaf, 'http://xmlns.com/foaf/0.1/'). %% lod_load(+URL) is det. % % Cached querying of Linked Open Data. First, we remove a possible % fragment identifier (#fragment), because fragment identifiers % are a client-side issue rather than a server-side issue. % % @error domain_error(content_type, 'RDF') is raised if the URL % contains no RDF data. Note that rdf_load/1 already % raises this error if the MIME-type is incorrect. lod_load(URI) :- url_sans_fragment(URI, URI2), ( rdf_graph(URI2) -> true ; rdf_load(URI2), ( rdf_graph(URI2) -> true ; domain_error(content_type, 'RDF') ) ). url_sans_fragment(URI, URI2) :- uri_components(URI, Components), copy_components([scheme, authority, path, search], Components, Components2), uri_components(URI2, Components2). copy_components([], _, _). copy_components([H|T], In, Out) :- uri_data(H, In, Data), uri_data(H, Out, Data), copy_components(T, In, Out). %% sindice_query_url(+Query, +Page, -URL) % % URL is the URL to send to Sindice for Query. Query is a Sindice % _term_ query argument. sindice_query(Query, Page, QueryURL) :- uri_query_components(Search, [q=Query, qt=term, page=Page]), sindice_host(Host), sindice_path(Path), uri_data(scheme, Components, http), uri_data(authority, Components, Host), uri_data(path, Components, Path), uri_data(search, Components, Search), uri_components(QueryURL, Components). sindice_host('api.sindice.com'). sindice_path('/v2/search').