xmlrdf/commit
Try to get AHM example to work again
author | Jan Wielemaker |
---|---|
Mon Nov 29 14:01:28 2010 +0100 | |
committer | Jan Wielemaker |
Mon Nov 29 14:01:28 2010 +0100 | |
commit | bfb2bc723d36c2a1590abe4ddf64777698334e0e |
tree | 100dc8bcc5a76e61872d65996b05f1bf27ebc89f |
parent | 085a55ecc0837a18d9e8598c1046e85f4569f5b6 |
Diff style: patch stat
diff --git a/examples/AHM/rewrite.pl b/examples/AHM/rewrite.pl index 2d2b1e2..087e58b 100644 --- a/examples/AHM/rewrite.pl +++ b/examples/AHM/rewrite.pl @@ -5,9 +5,9 @@ list_rules/0 ]). :- use_module(library(semweb/rdf_db)). -:- use_module(xmlrdf(rdf_convert_util)). -:- use_module(xmlrdf(cvt_vocabulary)). -:- use_module(xmlrdf(rdf_rewrite)). +:- use_module(library(xmlrdf/rdf_convert_util)). +:- use_module(library(xmlrdf/cvt_vocabulary)). +:- use_module(library(xmlrdf/rdf_rewrite)). :- use_module(util). :- debug(rdf_rewrite). @@ -385,7 +385,7 @@ webtextcat @@ % clean webtextcat @@ -{T, ahm:'AHMTextsType', BN1}, +{_T, ahm:'AHMTextsType', BN1}, {BN1, rdf:type, ahm:'AHMTextsType'} <=> true. diff --git a/examples/AHM/run.pl b/examples/AHM/run.pl index b10c937..f170ad5 100644 --- a/examples/AHM/run.pl +++ b/examples/AHM/run.pl @@ -1,21 +1,13 @@ -:- prolog_load_context(directory, Dir), - asserta(user:file_search_path(ahm, Dir)). - -user:file_search_path(xmlrdf, ahm('..')). -user:file_search_path(data, ahm('../../AHM')). -user:file_search_path(cliopatria, ahm('../../ClioPatria')). -user:file_search_path(getty, ahm('../../../eculture/RDF/vocabularies/getty')). - :- load_files(library(semweb/rdf_db), [silent(true)]). :- rdf_register_ns(ahm, 'http://purl.org/collections/ahm/'). :- rdf_register_ns(ulan, 'http://e-culture.multimedian.nl/ns/getty/ulan#'). :- rdf_register_ns(aatned, 'http://e-culture.multimedian.nl/ns/rkd/aatned/'). -:- rdf_register_ns(skos, 'http://www.w3.org/2004/02/skos/core#'). -:- rdf_register_ns(foaf, 'http://xmlns.com/foaf/0.1/'). + +user:file_search_path(data, '../metadata'). :- load_files([ cliopatria(cliopatria), - xmlrdf(xmlrdf), + library(xmlrdf/xmlrdf), library(semweb/rdf_cache), library(semweb/rdf_library), library(semweb/rdf_turtle_write) @@ -23,7 +15,7 @@ user:file_search_path(getty, ahm('../../../eculture/RDF/vocabularies/getty' :- use_module(rewrite). load_ontologies :- - rdf_attach_library(cliopatria(ontologies)), + rdf_attach_library(cliopatria(rdf)), % rdf_attach_library(getty(.)), rdf_load_library(dc), rdf_load_library(skos), @@ -33,18 +25,11 @@ load_ontologies :- rdf_load(Schema). :- initialization % run *after* loading this file - ensure_dir(cache), rdf_set_cache_options([ global_directory('cache/rdf'), create_global_directory(true) ]), load_ontologies. -ensure_dir(Dir) :- - exists_directory(Dir), !. -ensure_dir(Dir) :- - make_directory(Dir). - - :- debug(xmlrdf). load :- diff --git a/examples/AHM/util.pl b/examples/AHM/util.pl index 44d8617..6c2caa4 100644 --- a/examples/AHM/util.pl +++ b/examples/AHM/util.pl @@ -1,15 +1,14 @@ % Utility predicates for -:- module(util, +:- module(ahm_util, [ role_to_property/2, % +Role, -SubProperty concat_maybe/2, % +ListofArgs, -OutputLiteral concat_maybe/3, % +ListofArgs, +Separator, -OutputLiteral object_number_to_url/2, % +Object Number -URL lang_to_langcode/2 % +AHMLangNr, -IsoLangCode - - ]). + ]). :- use_module(library(semweb/rdf_db)). -:- use_module(xmlrdf(rdf_convert_util)). +:- use_module(library(xmlrdf/rdf_convert_util)). % Utility preds that make a creator subproperty based on creator Role. diff --git a/lib/xmlrdf/cvt_vocabulary.pl b/lib/xmlrdf/cvt_vocabulary.pl new file mode 100644 index 0000000..6fdd254 --- /dev/null +++ b/lib/xmlrdf/cvt_vocabulary.pl @@ -0,0 +1,62 @@ +:- module(cvt_vocabulary, + [ find_in_vocabulary/4, % +Schema, +Root, +Literal, -Resource + find_in_vocabulary/3 % +Schema, +Root, +Literal, -Resource + ]). +:- use_module(library(semweb/rdf_db)). + +:- rdf_meta + find_in_vocabulary(r, +, -). + +%% find_in_vocabulary(?Scheme, ?Root, +Literal, -Resource) is semidet. +% +% Resource is the best mapping we can find for Name in the SKOS +% hierarchy below Root. +% +% @tbd Disambiguation +% @tbd Get the context in here + +find_in_vocabulary(Root, Name, Resource) :- + find_in_vocabulary(_, Root, Name, Resource). + +find_in_vocabulary(Scheme, Root, Name, Resource) :- + to_seach(Name, Literal), + rdf_has(Resource, skos:prefLabel, Literal), + in_scheme(Resource, Scheme), + has_root(Resource, Root). +find_in_vocabulary(Scheme, Root, Name, Resource) :- + to_seach(Name, Literal), + findall(R, ( rdf_has(R, rdfs:label, Literal), + in_scheme(R, Scheme), + has_root(R, Root) + ), + List), + List = [Resource]. + +to_seach(X, X) :- + var(X), !. +to_seach(X, X) :- + X = literal(_), !. +to_seach(A, literal(A)). + +in_scheme(R, Scheme) :- + ( var(Scheme) + -> ( rdf_has(R, skos:inScheme, Scheme) + -> true + ; true + ) + ; rdf_has(R, skos:inScheme, Scheme) + ). + +has_root(R, Root) :- + ( var(Root) + -> find_root(R, Root) + ; rdf_reachable(R, skos:broader, Root) + ). + +find_root(R, Root) :- + ( rdf_has(R, skos:broader, B) + *-> find_root(B, Root) + ; Root = R + ). + + diff --git a/lib/xmlrdf/xmlrdf.pl b/lib/xmlrdf/xmlrdf.pl index 689fac1..b4f84b5 100644 --- a/lib/xmlrdf/xmlrdf.pl +++ b/lib/xmlrdf/xmlrdf.pl @@ -1,7 +1,31 @@ -/* File: xmlrdf.pl - Author: Jan Wielemaker - Created: Oct 26 2009 - Purpose: Generic translation from XML to RDF +/* 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(xmlrdf, @@ -20,8 +44,14 @@ :- use_module(library(record)). :- use_module(library(apply)). +:- use_module(config_available(skos)). +:- use_module(config_available(foaf)). + :- rdf_register_ns(map, 'http://cs.vu.nl/eculture/map/'). +/** <module> Generic translation from XML to RDF +*/ + :- record option(units:list=[], dialect:oneof([xml,xmlns])=xmlns,