1/*  Part of SWISH
    2
    3    Author:        Jan Wielemaker
    4    E-mail:        J.Wielemaker@cs.vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (C): 2017, VU University Amsterdam
    7			 CWI 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(swish_config_hdt, []).   37:- use_module(library(broadcast)).   38:- use_module(swish(lib/plugin/hdt)).   39:- use_module(library(semweb/rdf11),
   40              [ rdf_register_prefix/2,
   41                rdf_global_id/2,
   42                (rdf_meta)/1
   43              ]).   44:- use_module(swish(lib/render/rdf), []).

Make background RDF data available using HDT

This config file makes possibly very large amounts of RDF data available from swish using the Header Dictionary Triple (HDT) format. Steps to use this:

  1. Install an activate the HDT library using the commands below. This should work on Ubuntu out of the box. On other Unix systems you may need to tweak a little. Installing on Windows is most likely a challenge.
    sudo apt-get install libserd-dev libraptor-dev
    git submodule update --init pack/hdt
    swipl run.pl
    ?- pack_rebuild(hdt).
  2. Create a directory with HDT files in them you want to make available. You can later add files without restarting SWISH.
  3. Copy this file to config-enabled and go through the EDIT marked sections to configure HDT for your data. */
   71:- multifile user:file_search_path/2.   72
   73% EDIT: location of your HDT files
   74user:file_search_path(hdt, '../hdt-data').
   75
   76% EDIT: uncomment to make hdt available without including the library
   77% :- use_module(swish:swish(lib/plugin/hdt)).
   78
   79% EDIT: Define common RDF prefixes
   80:- rdf_register_prefix(wgs84, 'http://www.w3.org/2003/01/geo/wgs84_pos#').   81
   82:- rdf_meta(prefix(r, r)).   83
   84% EDIT: define prefixes used in the various HDT datasets.  The RDF
   85% rendering library will use to display the (english) label for
   86% resources when available.
   87rdf_prefix(hdt:geonames,      gn,    'http://www.geonames.org/').
   88rdf_prefix(hdt:geonames,      gno,   'http://www.geonames.org/ontology#').
   89rdf_prefix(hdt:linkedgeodata, lgo,   'http://linkedgeodata.org/ontology/').
   90rdf_prefix(hdt:wordnet,       wn,    'http://wordnet-rdf.princeton.edu/wn31/').
   91rdf_prefix(hdt:wordnet,       wno,   'http://wordnet-rdf.princeton.edu/ontology#').
   92rdf_prefix(hdt:wordnet,       lemon, 'http://lemon-model.net/lemon#').
   93rdf_prefix(hdt:dblp,          swrc,  'http://swrc.ontoware.org/ontology#').
   94rdf_prefix(hdt:wikidata,      wdp,   'http://www.wikidata.org/prop/').
   95rdf_prefix(hdt:wikidata,      wde,   'http://www.wikidata.org/entity/').
   96rdf_prefix(hdt:wikidata,      wds,   'http://www.wikidata.org/prop/statement/').
   97rdf_prefix(hdt:wikidata,      wdt,   'http://www.wikidata.org/prop/direct/').
   98
   99register_prefixes :-
  100    forall(rdf_prefix(_G, Prefix, IRI),
  101           rdf_register_prefix(Prefix, IRI)).
  102
  103:- listen(rdf_label(IRI, Label), label(IRI, Label)).  104
  105% EDIT: Define how to obtain the label for an IRI. The default is to use
  106% the rules above to find the HDT from   which the IRI originates and as
  107% this HDT for rdfs:label in English.
  108label(IRI, Label) :-
  109    rdf_global_id(Prefix:_Local, IRI),
  110    rdf_prefix(Graph, Prefix, _),
  111    rdf(IRI, rdfs:label, @(Label,en), Graph).
  112
  113:- initialization
  114    register_prefixes.