View source with formatted 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)  2010-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(rdfslite_entailment,
   37          [
   38          ]).   39:- use_module(rdfql(rdfql_runtime)).    % runtime tests
   40:- use_module(library('semweb/rdf_db'),
   41              [ rdf_global_id/2,
   42                rdf_reachable/3,
   43                rdf_has/3,
   44                rdf_has/4,
   45                rdf_subject/1,
   46                rdf_equal/2,
   47                (rdf_meta)/1,
   48                op(_,_,_)
   49              ]).   50:- use_module(library('semweb/rdfs'),
   51              [ rdfs_subclass_of/2,
   52                rdfs_subproperty_of/2,
   53                rdfs_individual_of/2
   54              ]).   55
   56/** <module> RDFS-Lite entailment
   57
   58The function of an entailment module is  to provide an implementation of
   59rdf/3 that extends basic triple-lookup using the entailment rules of the
   60semantic web sub language of RDF.
   61
   62This entailment module does the part  of   RDFS  that can be implemented
   63efficiently  using  backward  chaining.  Notably    it   does  *not*  do
   64type-reasoning on the basis of domains/ranges of properties. It does:
   65
   66        * Use the property hierarchy
   67        * Define the serql special relations
   68        * Handle rdfs:subClassOf as transitive
   69        * Handle rdfs:subPropertyOf as transitive
   70        * Handle rdf:type using subProperties and rdfs:subClassOf
   71*/
   72
   73:- rdf_meta
   74        rdf(o,o,o).   75
   76:- public
   77    rdf/3,
   78    rdf/4.   79
   80rdf(S, P, O) :-
   81    var(P),
   82    !,
   83    rdf_db:rdf(S,P,O).
   84rdf(S, serql:directSubClassOf, O) :-
   85    !,
   86    rdf_has(S, rdfs:subClassOf, O).
   87rdf(S, serql:directType, O) :-
   88    !,
   89    rdf_has(S, rdf:type, O).
   90rdf(S, serql:directSubPropertyOf, O) :-
   91    !,
   92    rdf_has(S, rdfs:subPropertyOf, O).
   93rdf(S, rdfs:subClassOf, O) :- ( atom(S) ; atom(O) ),
   94    !,
   95    rdf_reachable(S, rdfs:subClassOf, O).
   96rdf(S, rdfs:subClassOf, O) :-
   97    !,
   98    rdf_has(S, rdfs:subClassOf, Direct),
   99    rdf_reachable(Direct, rdfs:subClassOf, O).
  100rdf(S, rdfs:subPropertyOf, O) :-
  101    !,
  102    rdf_reachable(S, rdfs:subPropertyOf, O).
  103rdf(S, rdf:type, O) :-
  104    !,
  105    (   var(S), var(O)
  106    ->  rdf_subject(S)
  107    ;   true
  108    ),
  109    rdfs_individual_of(S, O).
  110rdf(S, P, O) :-
  111    rdf_has(S, P, O).
  112
  113%!  rdf(?S, ?P, ?O, ?G)
  114
  115rdf(S, P, O, G) :-
  116    var(P),
  117    !,
  118    rdf_db:rdf(S, P, O, G).
  119rdf(S, P, O, G) :-
  120    rdf_has(S, P, O, RP),
  121    rdf_db:rdf(S, RP, O, G).
  122
  123                 /*******************************
  124                 *             REGISTER         *
  125                 *******************************/
  126
  127:- multifile
  128    cliopatria:entailment/2.  129
  130cliopatria:entailment(rdfslite, rdfslite_entailment)