module Tripod::EagerLoading
Attributes
array of resources that represent the objects of the triples of this resource
array of resources that represent the predicates of the triples of this resource
Public Instance Methods
build a list of optional predicates
for the input
build_multifield_query(RDF::SKOS.prefLabel, RDF::RDFS.label, RDF::DC.title],"?p")
the follwing query is generated
CONSTRUCT {
?p <http://www.w3.org/2004/02/skos/core#prefLabel> ?pref_label . ?p <http://www.w3.org/2000/01/rdf-schema#label> ?label . ?p <http://purl.org/dc/elements/1.1/title> ?title . } WHERE { <http://data.hampshirehub.net/data/miscelleanous/2011-census-ks101ew-usual-resident-population-key-statistics-ks> ?p ?o . OPTIONAL { ?p <http://www.w3.org/2004/02/skos/core#prefLabel> ?pref_label . } OPTIONAL { ?p <http://www.w3.org/2000/01/rdf-schema#label> ?label . } OPTIONAL { ?p <http://purl.org/dc/elements/1.1/title> ?title . } }
# File lib/tripod/eager_loading.rb, line 66 def build_multifield_query(predicates,subject_position_as) clauses = [] iter = 0 predicates.each do |p| variable_name = "var#{iter.to_s}" clauses << "#{subject_position_as} <#{p.to_s}> ?#{variable_name} . " iter +=1 end construct_query = "CONSTRUCT { " clauses.each do |c| construct_query += c end construct_query += " } WHERE { <#{self.uri.to_s}> ?p ?o . " clauses.each do |c| construct_query += " OPTIONAL { #{c} } " end construct_query += " }" # close WHERE end
get all the triples in the db where the object uri is their subject stick the results in this resource's repo options: labels_only (default false) options: predicates (default nil) array of predicaets (as URIs or strings representing URIs) for fieldnames to fetch
# File lib/tripod/eager_loading.rb, line 33 def eager_load_object_triples!(opts={}) object_uris = [] if opts[:labels_only] construct_query = "CONSTRUCT { ?o <#{RDF::RDFS.label}> ?obj_label } WHERE { <#{self.uri.to_s}> ?p ?o . ?o <#{RDF::RDFS.label}> ?obj_label }" elsif (opts[:predicates] && opts[:predicates].length > 0) construct_query = build_multifield_query(opts[:predicates],"?o") else construct_query = "CONSTRUCT { ?o ?obj_pred ?obj_label } WHERE { <#{self.uri.to_s}> ?p ?o . ?o ?obj_pred ?obj_label }" end extra_triples = self.class._graph_of_triples_from_construct_or_describe construct_query self.class.add_data_to_repository(extra_triples, self.repository) end
get all the triples in the db where the predicate uri is their subject stick the results in this resource's repo options: labels_only (default false) options: predicates (default nil) array of predicaets (as URIs or strings representing URIs) for fieldnames to fetch
# File lib/tripod/eager_loading.rb, line 15 def eager_load_predicate_triples!(opts={}) if opts[:labels_only] construct_query = "CONSTRUCT { ?p <#{RDF::RDFS.label}> ?pred_label } WHERE { <#{self.uri.to_s}> ?p ?o . ?p <#{RDF::RDFS.label}> ?pred_label }" elsif (opts[:predicates] && opts[:predicates].length > 0) construct_query = build_multifield_query(opts[:predicates],"?p") else construct_query = "CONSTRUCT { ?p ?pred_pred ?pred_label } WHERE { <#{self.uri.to_s}> ?p ?o . ?p ?pred_pred ?pred_label }" end extra_triples = self.class._graph_of_triples_from_construct_or_describe construct_query self.class.add_data_to_repository(extra_triples, self.repository) end