aers_rewrite/commit
First simple rdfxml rewrite rules
author | Michiel Hildebrand |
---|---|
Mon Jan 14 16:58:33 2013 +0100 | |
committer | Michiel Hildebrand |
Mon Jan 14 16:58:33 2013 +0100 | |
commit | e915cc04a77cd111c9eda5a0b3ffefa4a1a9bbcc |
tree | 3c9fe0dfaa09300ce67381e0f20b3c92d5f6f2c8 |
parent | 27ba777e1bbd86b55bffed2b993a162fa40c8999 |
Diff style: patch stat
diff --git a/config-available/aers_rewrite.pl b/config-available/aers_rewrite.pl index 59b2798..0732b0a 100644 --- a/config-available/aers_rewrite.pl +++ b/config-available/aers_rewrite.pl @@ -3,3 +3,8 @@ /** <module> Create RDF from Adverse Event Database from the FDA */ +:- use_module(library(semweb/rdf_db)). + +:- rdf_register_ns(aers, 'http://aers.data2semantics.org/vocab/'). + +:- use_module(library(aers_rewrite)). diff --git a/lib/aers_rewrite.pl b/lib/aers_rewrite.pl new file mode 100644 index 0000000..eb80914 --- /dev/null +++ b/lib/aers_rewrite.pl @@ -0,0 +1,72 @@ +:- module(aers_rewrite, + [test/0, + load/0, + load_year/1, + rewrite/0 + ]). + +:- use_module(library(semweb/rdf_db)). +:- use_module(library(xmlrdf/xmlrdf)). +:- use_module(library(xmlrdf/rdf_rewrite)). +:- use_module(library(xmlrdf/rdf_convert_util)). + +:- rdf_register_ns(aers, 'http://aers.data2semantics.org/vocab/'). + +user:file_search_path(data, '../fda_data'). + +test :- + absolute_file_name(data('Adr_test.sgm'), TestFile), + load(TestFile). + +load :- + absolute_file_name(data(sgml), Dir, + [ file_type(directory) + ]), + expand_file_name(Dir, Files), + maplist(load, Files). + +load_year(Year) :- + absolute_file_name(data(sgml), Dir, + [ file_type(directory) + ]), + concat_atom([Dir, '/ADR',Year,'*.SGM'], Pattern), + expand_file_name(Pattern, Files), + maplist(load, Files). + +load(File) :- + rdf_current_ns(aers, Prefix), + load_xml_as_rdf(File, + [ dialect(xml), + unit(safetyreport), + prefix(Prefix) + ]). + +rewrite :- + rdf_rewrite(data). + +% URIs of the reports are based on the safetyreportid + +assign_uris @@ +{S, aers:safetyreportid, literal(Id)}\ +{ S } <=> + literal_to_id(['report', Id], aers, URI), + { URI }. + +% Reactions are direct properties of the report and not the patient + +reaction @@ +{Patient, aers:reaction, Reaction}, +{Report, aers:patient, Patient}\ +{Patient, aers:reaction, Reaction} +<=> +{ Report, aers:reaction, Reaction }. + +% Drugs are direct properties of the report and not the patient + +drug @@ +{Patient, aers:drug, Drug}, +{Report, aers:patient, Patient}\ +{Patient, aers:drug, Drug} +<=> +{ Report, aers:drug, Drug }. +