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@cs.vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (C): 2004-2010, University of Amsterdam,
    7			      VU University Amsterdam
    8
    9    This program is free software; you can redistribute it and/or
   10    modify it under the terms of the GNU General Public License
   11    as published by the Free Software Foundation; either version 2
   12    of the License, or (at your option) any later version.
   13
   14    This program is distributed in the hope that it will be useful,
   15    but WITHOUT ANY WARRANTY; without even the implied warranty of
   16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17    GNU General Public License for more details.
   18
   19    You should have received a copy of the GNU General Public
   20    License along with this library; if not, write to the Free Software
   21    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   22
   23    As a special exception, if you link this library with other files,
   24    compiled with a Free Software compiler, to produce an executable, this
   25    library does not by itself cause the resulting executable to be covered
   26    by the GNU General Public License. This exception does not however
   27    invalidate any other reasons why the executable file might be covered by
   28    the GNU General Public License.
   29*/
   30
   31
   32:- module(rdfslite_entailment,
   33	  [
   34	  ]).   35:- use_module(rdfql(rdfql_runtime)).	% runtime tests
   36:- use_module(library('semweb/rdf_db'),
   37	      [ rdf_global_id/2,
   38		rdf_reachable/3,
   39		rdf_has/3,
   40		rdf_has/4,
   41		rdf_subject/1,
   42		rdf_equal/2,
   43		(rdf_meta)/1,
   44		op(_,_,_)
   45	      ]).   46:- use_module(library('semweb/rdfs'),
   47	      [ rdfs_subclass_of/2,
   48		rdfs_subproperty_of/2,
   49		rdfs_individual_of/2
   50	      ]).   51
   52/** <module> RDFS-Lite entailment
   53
   54The function of an entailment module is  to provide an implementation of
   55rdf/3 that extends basic triple-lookup using the entailment rules of the
   56semantic web sub language of RDF.
   57
   58This entailment module does the part  of   RDFS  that can be implemented
   59efficiently  using  backward  chaining.  Notably    it   does  *not*  do
   60type-reasoning on the basis of domains/ranges of properties. It does:
   61
   62	* Use the property hierarchy
   63	* Define the serql special relations
   64	* Handle rdfs:subClassOf as transitive
   65	* Handle rdfs:subPropertyOf as transitive
   66	* Handle rdf:type using subProperties and rdfs:subClassOf
   67*/
   68
   69:- rdf_meta
   70	rdf(o,o,o).   71
   72:- public
   73	rdf/3,
   74	rdf/4.   75
   76rdf(S, P, O) :-
   77	var(P), !,
   78	rdf_db:rdf(S,P,O).
   79rdf(S, serql:directSubClassOf, O) :- !,
   80	rdf_has(S, rdfs:subClassOf, O).
   81rdf(S, serql:directType, O) :- !,
   82	rdf_has(S, rdf:type, O).
   83rdf(S, serql:directSubPropertyOf, O) :- !,
   84	rdf_has(S, rdfs:subPropertyOf, O).
   85rdf(S, rdfs:subClassOf, O) :- ( atom(S) ; atom(O) ), !,
   86	rdf_reachable(S, rdfs:subClassOf, O).
   87rdf(S, rdfs:subClassOf, O) :- !,
   88       rdf_has(S, rdfs:subClassOf, Direct),
   89       rdf_reachable(Direct, rdfs:subClassOf, O).
   90rdf(S, rdfs:subPropertyOf, O) :- !,
   91	rdf_reachable(S, rdfs:subPropertyOf, O).
   92rdf(S, rdf:type, O) :- !,
   93	(   var(S), var(O)
   94	->  rdf_subject(S)
   95	;   true
   96	),
   97	rdfs_individual_of(S, O).
   98rdf(S, P, O) :-
   99	rdf_has(S, P, O).
  100
  101%!	rdf(?S, ?P, ?O, ?G)
  102
  103rdf(S, P, O, G) :-
  104	var(P),
  105	!,
  106	rdf_db:rdf(S, P, O, G).
  107rdf(S, P, O, G) :-
  108	rdf_has(S, P, O, RP),
  109	rdf_db:rdf(S, RP, O, G).
  110
  111		 /*******************************
  112		 *	       REGISTER		*
  113		 *******************************/
  114
  115:- multifile
  116	cliopatria:entailment/2.  117
  118cliopatria:entailment(rdfslite, rdfslite_entailment)