xmlrdf/commit
Documented the run-people.pl file
author | Jan Wielemaker |
---|---|
Fri Mar 25 17:07:29 2011 +0100 | |
committer | Jan Wielemaker |
Fri Mar 25 17:07:29 2011 +0100 | |
commit | bb9cfa4075ec8de00ef7a784e4a3a5c8fb69104c |
tree | df10c8de6602c9d53d4064a5b996330b71c48c21 |
parent | 1b0f64cf6fa770888ab6da750d7f0f9de344d1ba |
Diff style: patch stat
diff --git a/examples/AHM/run-data.pl b/examples/AHM/run-data.pl index 158d51a..bbf921b 100644 --- a/examples/AHM/run-data.pl +++ b/examples/AHM/run-data.pl @@ -28,18 +28,11 @@ load_ontologies :- :- 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/run-people.pl b/examples/AHM/run-people.pl index 77b127a..1028881 100644 --- a/examples/AHM/run-people.pl +++ b/examples/AHM/run-people.pl @@ -1,49 +1,81 @@ :- module(ahm_convert_people, - [ run_people/0 + [ ahm_run_people/0 ]). -user:file_search_path(data, metadata('AHM')). +% Setup a search path for finding the data. Of course this can also +% use relative or absolute paths, but this is a bit easier to addapt +% to the environment. The search path 'metadata' is predefined as +% one of $RDF_METADATA_DIR or ~/RDF/metadata -:- load_files(library(semweb/rdf_db), [silent(true)]). +user:file_search_path(data, metadata('AHM')). + +% Get core libraries + +:- use_module(library(semweb/rdf_db)). % Core RDF +:- use_module(library(semweb/rdf_library)). % Load RDF from library +:- use_module(library(xmlrdf/xmlrdf)). % XML --> RDF conversion +:- use_module(library(semweb/rdf_turtle_write)).% Save results +:- use_module(library(semweb/rdf_cache)). % Cache control +:- use_module(library(semweb/rdf_persistency)). % Persistency control + +% Configure the environment: +% +% - Make prefixes (namespaces) known +% - Enable caching (speedup reloading large RDF files) +% - Disable persistency for our rewrite graph(s). :- rdf_register_ns(ahm, 'http://purl.org/collections/nl/am/'). +:- rdf_set_cache_options([ global_directory('cache/rdf'), + create_global_directory(true) + ]). +:- rdf_persistency(people, false). + +% Load our dataset specific rewrite rules -:- load_files([ library(xmlrdf/xmlrdf), - library(semweb/rdf_cache), - library(semweb/rdf_library), - library(semweb/rdf_turtle_write) - ], [silent(true)]). :- use_module(rewrite_people). +%% load_ontologies +% +% Loads ontologies that we need. The set below comes from the +% ClioPatria library. + load_ontologies :- rdf_load_library(dc), rdf_load_library(skos), rdf_load_library(rdfs), rdf_load_library(owl). +% We always need the ontologies, and thus we load them with the program -:- initialization % run *after* loading this file - ensure_dir(cache), - rdf_set_cache_options([ global_directory('cache/rdf'), - create_global_directory(true) - ]), +:- initialization load_ontologies. +%% load_people +% +% Load the AM People database from the XML source file. First +% locate the file using the Prolog file search and then use +% load_xml/1. -ensure_dir(Dir) :- - exists_directory(Dir), !. -ensure_dir(Dir) :- - make_directory(Dir). - - - -load_people:- +load_people :- absolute_file_name(data('src/people.xml'), File, [ access(read) ]), - load(File). - -load(File) :- + load_xml(File). + +%% load_xml(+File) +% +% Load the XML. Relevant options: +% +% - The file is a plain XML file (not using XML namespaces) +% - Database entries are mapped to the XML element =record=. +% we process the file record-by-record and ignore all data +% outside the record elements (e.g., header) +% - Set the RDF prefix to the =ahm= prefix. +% - Dump all data into the graph =people= +% +% After running this, we have `raw RDF'. + +load_xml(File) :- rdf_current_ns(ahm, Prefix), load_xml_as_rdf(File, [ dialect(xml), @@ -52,16 +84,31 @@ load(File) :- graph(people) ]). +%% save_thesaurus +% +% Save the result relative to the =data= search path. -run_people:- - load_people, - rewrite, - rdf_assert(ahm:'AM_PeopleScheme',rdf:type, skos:'ConceptScheme',people), - rdf_assert(ahm:'AM_PeopleScheme', rdfs:label, literal('AM People thesaurus'),people), - save_thesaurus. - -save_thesaurus:- +save_thesaurus :- absolute_file_name(data('rdf/am-people.ttl'), File, [ access(write) ]), - rdf_save_turtle(File,[graph(people)]). + rdf_save_turtle(File, [graph(people)]). + +%% ahm_run_people +% +% Perform the entire conversion: +% +% 1. Load the data. +% 2. Rewrite the RDF graph +% 3. Add some RDF statements. Note thae we can also load this +% from an RDF file. +% 4. Save the result. + +ahm_run_people:- + load_people, + rewrite, + rdf_assert(ahm:'AM_PeopleScheme', + rdf:type, skos:'ConceptScheme', people), + rdf_assert(ahm:'AM_PeopleScheme', + rdfs:label, literal('AM People thesaurus'), people), + save_thesaurus. diff --git a/examples/AHM/run-thesaurus.pl b/examples/AHM/run-thesaurus.pl index 994f506..2a89ea4 100644 --- a/examples/AHM/run-thesaurus.pl +++ b/examples/AHM/run-thesaurus.pl @@ -23,20 +23,11 @@ load_ontologies :- rdf_load(data('rdf/am-thesaurus-schema.ttl'),[graph(thesaurus_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). - - - load_thesaurus:- absolute_file_name(data('src/thesaurus.xml'), File, [ access(read)