owl/commit
First version of a owl:sameAs library
author | Jan Wielemaker |
---|---|
Thu Dec 2 13:39:15 2010 +0100 | |
committer | Jan Wielemaker |
Thu Dec 2 13:39:15 2010 +0100 | |
commit | 6c633b76fb45b518de4cf660214a2fad7d8dcddf |
tree | dd3f995871ce3d1692b28f8f98245d49050cec16 |
parent | aa63a904c12443009d809c6e98c95ca3ec3b1bb6 |
Diff style: patch stat
diff --git a/config-available/DEFAULTS b/config-available/DEFAULTS deleted file mode 100644 index d50f569..0000000 --- a/config-available/DEFAULTS +++ /dev/null @@ -1 +0,0 @@ -config(owl, link). diff --git a/config-available/owl.pl b/config-available/owl.pl deleted file mode 100644 index b35c969..0000000 --- a/config-available/owl.pl +++ /dev/null @@ -1,5 +0,0 @@ -:- module(conf_owl, []). - -/** <module> Library of OWL based predicates -*/ - diff --git a/lib/semweb/owl_sameas.pl b/lib/semweb/owl_sameas.pl new file mode 100644 index 0000000..caf0de0 --- /dev/null +++ b/lib/semweb/owl_sameas.pl @@ -0,0 +1,123 @@ +/* Part of ClioPatria SeRQL and SPARQL server + + Author: Jan Wielemaker + E-mail: J.Wielemaker@cs.vu.nl + WWW: http://www.swi-prolog.org + Copyright (C): 2010, University of Amsterdam, + VU University Amsterdam + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + As a special exception, if you link this library with other files, + compiled with a Free Software compiler, to produce an executable, this + library does not by itself cause the resulting executable to be covered + by the GNU General Public License. This exception does not however + invalidate any other reasons why the executable file might be covered by + the GNU General Public License. +*/ + +:- module(owl_sameas, + [ owl_sameas/2, % ?R1, ?R2 + owl_sameas_partition/2, % +List, -PowerSet + owl_sameas_representative/3 % +Algorithm, +Set, -Representative + ]). +:- use_module(library(semweb/rdf_db)). +:- use_module(library(ordsets)). +:- use_module(library(count)). + +:- initialization + rdf_set_predicate(owl:sameAs, symmetric(true)). + +:- if((rdf_version(V),V<20900)). +:- multifile prolog:message//1. +prolog:message(rdf_version(MinVersion)) --> + [ 'library(semweb/owl_sameas) requires version > ~w of RDF-DB'- + [MinVersion] + ]. +:- print_message(error, rdf_version(20900)). +:- endif. + +/** <module> Handle owl:sameAs predicates + +This module provides predicates that perform various operations on sets +of resources that are possibly connected through owl:sameAs reations. +*/ + +%% owl_sameas(?R1, ?R2) is nondet. +% +% True if R is equivalent to R0 through owl:sameAs properties. + +owl_sameas(R1, R2) :- + rdf_reachable(R1, owl:sameAs, R2). + +%% owl_sameas_partition(+Resources, -PowerSet) is det. +% +% True when each element of PowerSet is a set of equivalent +% resources and there are no two equivalent resources in different +% members of PowerSet. + +owl_sameas_partition(Resources, PowerSet) :- + sort(Resources, OrdSet), + partition(OrdSet, PowerSet). + +partition([], []). +partition([H|T], [Set0|Sets]) :- + findall(R, owl_sameas(H, R), Eq), + sort(Eq, Set0), + ord_subtract(T, Set0, Rest), + partition(Rest, Sets). + +%% owl_sameas_representative(+Algorithm, +List, -Representer) +% +% True when Representer is a member of Set that represents the +% set. There is no unique way to decide on the representer, which +% is why we provide Algorithm to select a dedicated algorithm. The +% current implementation has two algorihtms: +% +% * order +% Return the smallest resource in the standard order of terms. +% This is adequate for internal reasoning tasks. +% * default +% Find the most-connected resource that is not a blank node. +% If all resources are blank nodes, find the most connected +% one. + +owl_sameas_representative(order, List, Representative) :- + sort(List, [Representative|_]). +owl_sameas_representative(default, List, Representative) :- + ( exclude(rdf_is_bnode, List, NonBNodes), + NonBNodes \== [] + -> representative(NonBNodes, Representative) + ; representative(List, Representative) + ). + +representative([H], Representative) :- !, + Representative = H. +representative([H|T], Representative) :- + fan_in_out(H, Fan0), + best(T, Fan0, H, Representative). + +best([], _, R, R). +best([H|T], S0, R0, R) :- + fan_in_out(H, S1), + ( S1 > S0 + -> best(T, S1, H, R) + ; best(T, S0, R0, R) + ). + +fan_in_out(R, Fan) :- + proof_count(rdf(R, _, _), 100, FanOut), + proof_count(rdf(_, _, R), 100, FanIn), + Fan is FanOut + FanIn. diff --git a/rdf/cpack/owl.ttl b/rdf/cpack/owl.ttl index 941ff7f..8037825 100644 --- a/rdf/cpack/owl.ttl +++ b/rdf/cpack/owl.ttl @@ -11,7 +11,7 @@ # this. Otherwise you can specify the information inline as done below. # See http://xmlns.com/foaf/spec/ for defines fields. -<> a cpack:Package ; +<> a cpack:Library ; cpack:packageName "owl" ; dcterms:title "Library of OWL based predicates" ; cpack:author [ a foaf:Person ; @@ -24,7 +24,8 @@ ] ; cpack:description -"""The package description goes here. You can use PlDoc Wiki markup. +"""This package provides a collection of libraries to deal with OWL + related tasks, mostly reasoning with OWL-properties. """ .