From f519c7cf4ef23289dd3511fc00312dbed2b56d09 Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Fri, 26 Oct 2012 14:45:52 +0200 Subject: Added shims for SPARQL retrieval --- lib/utils/shims/dataset.rb | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'lib') diff --git a/lib/utils/shims/dataset.rb b/lib/utils/shims/dataset.rb index 75948e0..b5faf18 100644 --- a/lib/utils/shims/dataset.rb +++ b/lib/utils/shims/dataset.rb @@ -23,6 +23,43 @@ module OpenTox end + # Load features via SPARQL (fast) + # @param [String] Dataset URI + # @return [Array] Features in order + def self.find_features(uri) + sparql = "SELECT DISTINCT ?s FROM <#{uri}> WHERE { + ?s <#{RDF.type}> <#{RDF::OT.Feature}> ; + <#{RDF::OLO.index}> ?fidx + } ORDER BY ?fidx" + OpenTox::Backend::FourStore.query(sparql, "text/uri-list").split("\n").collect { |uri| OpenTox::Feature.new uri.strip } + end + + # Load compounds via SPARQL (fast) + # @param [String] Dataset URI + # @return [Array] Compounds in order + def self.find_compounds(uri) + sparql = "SELECT DISTINCT ?compound FROM <#{uri}> WHERE { + ?s <#{RDF.type}> <#{RDF::OT.DataEntry}> ; + <#{RDF::OLO.index}> ?cidx; + <#{RDF::OT.compound}> ?compound + } ORDER BY ?cidx" + OpenTox::Backend::FourStore.query(sparql, "text/uri-list").split("\n").collect { |uri| OpenTox::Compound.new uri.strip } + end + + # Load data entries via SPARQL (fast) + # @param [String] Dataset uri + # @return [Array] Data entries, ordered primarily over rows and secondarily over cols + def self.find_data_entries(uri) + sparql = "SELECT ?value FROM <#{uri}> WHERE { + ?data_entry <#{RDF::OLO.index}> ?cidx ; + <#{RDF::OT.values}> ?v . + ?v <#{RDF::OT.feature}> ?f; + <#{RDF::OT.value}> ?value . + ?f <#{RDF::OLO.index}> ?fidx. + } ORDER BY ?cidx ?fidx" + OpenTox::Backend::FourStore.query(sparql,"text/uri-list").split("\n").collect { |val| val.strip } + end + ### Index Structures -- cgit v1.2.3