rdf-mt/commit
Added graph_list.pl
author | Jan Wielemaker |
---|---|
Mon Dec 16 13:32:52 2013 +0100 | |
committer | Jan Wielemaker |
Mon Dec 16 13:32:52 2013 +0100 | |
commit | ef687b8bf97613037c313bb2c80ed969c2f68239 |
tree | 3c029498aeac3a7ec9117cb44ed2e96b3cd6b90a |
parent | 49a9de11382e44ad9d5a9857aa88540229801899 |
Diff style: patch stat
diff --git a/lib/rdf_mt/graph_list.pl b/lib/rdf_mt/graph_list.pl new file mode 100644 index 0000000..2cad322 --- /dev/null +++ b/lib/rdf_mt/graph_list.pl @@ -0,0 +1,73 @@ +/* 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): 2013, 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(graph_list, + [ graph_list/2 + ]). +:- use_module(library(semweb/rdf_db)). +:- use_module(library(assoc)). + +%% graph_list(+GraphName, -List) is det. +% +% Get a list of rdf(S,P,O) terms representing the triples in +% GraphName, replacing all blank nodes in the graph with Prolog +% variables. + +graph_list(GraphName, List) :- + findall(rdf(S,P,O), rdf(S,P,O,GraphName), List0), + bnode_variables(List0, List1), + List = List1. + +bnode_variables(List0, List) :- + empty_assoc(Assoc0), + bnode_variables(List0, List, Assoc0, _). + +bnode_variables([], [], Map, Map). +bnode_variables([rdf(S0,P0,O0)|T0], + [rdf(S1,P1,O1)|T1], + Map0, Map) :- + map_resource(S0, S1, Map0, Map1), + map_resource(P0, P1, Map1, Map2), + map_object(O0, O1, Map2, Map3), + bnode_variables(T0, T1, Map3, Map). + +map_resource(S0, S1, Map0, Map) :- + rdf_is_bnode(S0), !, + ( get_assoc(S0, Map0, S1) + -> Map = Map0 + ; put_assoc(S0, Map0, S1, Map) + ). +map_resource(S, S, Map, Map). + +map_object(S0, S, Map0, Map) :- + atom(S0), !, + map_resource(S0, S, Map0, Map). +map_object(L, L, Map, Map). +