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(rdf_entailment,
   37          [ rdf/3,
   38            rdf/4
   39          ]).   40:- use_module(rdfql(rdfql_runtime)).    % runtime tests
   41:- use_module(library(semweb/rdf_db),
   42              [ rdf_global_id/2,
   43                rdf_subject/1,
   44                rdf_current_predicate/1,
   45                (rdf_meta)/1,
   46                op(_,_,_)
   47              ]).   48
   49/** <module> RDFS-Lite entailment
   50
   51The function of an entailment module is  to provide an implementation of
   52rdf/3 that extends basic triple-lookup using the entailment rules of the
   53semantic web sub language of RDF.
   54
   55This entailment module does only the core RDF inferences:
   56
   57    * Every subject is of type rdfs:Resource
   58    * Every resource that appears as a predicate is of type
   59      rdf:Property
   60*/
   61
   62:- rdf_meta
   63        rdf(r,r,o).   64
   65rdf(S, P, O) :-
   66    rdf_db:rdf(S, P, O).
   67rdf(S, rdf:type, rdf:'Property') :-
   68    var_or_resource(S),
   69    rdf_current_predicate(S),
   70    (   rdf_db:rdf(_, S, _)
   71    ->  \+ rdf_db:rdf(S, rdf:type, rdf:'Property')
   72    ).
   73rdf(S, rdf:type, rdfs:'Resource') :-
   74    var_or_resource(S),
   75    rdf_subject(S),
   76    \+ rdf_db:rdf(S, rdf:type, rdfs:'Resource').
   77rdf(S, serql:directSubClassOf, O) :-
   78    !,
   79    rdf_db:rdf(S, rdfs:subClassOf, O).
   80rdf(S, serql:directType, O) :-
   81    !,
   82    rdf_db:rdf(S, rdf:type, O).
   83rdf(S, serql:directSubPropertyOf, O) :-
   84    !,
   85    rdf_db:rdf(S, rdfs:subPropertyOf, O).
   86
   87var_or_resource(R) :-
   88    (   var(R)
   89    ->  true
   90    ;   atom(R)
   91    ).
   92
   93%!  rdf(?S, ?P, ?O, ?G)
   94
   95rdf(S, P, O, G) :-
   96    rdf_db:rdf(S, P, O, G).
   97
   98
   99                 /*******************************
  100                 *             REGISTER         *
  101                 *******************************/
  102
  103:- multifile
  104    cliopatria:entailment/2.  105
  106cliopatria:entailment(rdf, rdf_entailment)