Class: LD4L::OreRDF::FindAggregations
- Inherits:
-
Object
- Object
- LD4L::OreRDF::FindAggregations
- Defined in:
- lib/ld4l/ore_rdf/services/aggregation/find.rb
Class Method Summary collapse
-
.call(options = {}) ⇒ Object
Find aggregations matching the specified criteria.
Class Method Details
.call(options = {}) ⇒ Object
Find aggregations matching the specified criteria.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ld4l/ore_rdf/services/aggregation/find.rb', line 20 def self.call( ={} ) repository = [:repository] || :default raise ArgumentError, 'repository must be a symbol' unless repository.kind_of?(Symbol) raise ArgumentError, 'repository must be a registered repository' unless ActiveTriples::Repositories.repositories.has_key?(repository) resume = [:resume] || false raise ArgumentError, 'resume must be true or false' unless resume.kind_of?(TrueClass) || resume.kind_of?(FalseClass) criteria = [:criteria] || nil raise ArgumentError, 'criteria must be a hash of attribute-value pairs for searching for aggregations' unless criteria.nil? || criteria.kind_of?(Hash) criteria = criteria ? criteria.dup : {} criteria[RDF.type] = RDFVocabularies::ORE.Aggregation # properties are ignored when resume==true because all properties are returned as part of the resumed aggregations properties = [:properties] || nil raise ArgumentError, 'properties must be an array of predicates' unless properties.nil? || properties.kind_of?(Hash) || resume properties.each_key { |k| criteria[properties[k]] = k unless criteria.has_key?(properties[k]) } unless properties.nil? || resume process_properties = properties.nil? || resume ? false : true graph = ActiveTriples::Repositories.repositories[repository] query = RDF::Query.new({ :aggregation => criteria }) process_properties || resume ? aggregations = {} : aggregations = [] results = query.execute(graph) results.each do |r| h = r.to_hash uri = h[:aggregation] if resume # if resume, return Hash of aggregation uri => resumed aggregation for each found aggregations[uri] = LD4L::OreRDF::ResumeAggregation.call(uri) elsif process_properties # if properties, return Hash of aggregation uri => Hash of property => value for each found properties = h properties.delete(:aggregation) aggregations[uri] = properties else # if no properties && not resumed, return array of aggregation uris aggregations << uri end end aggregations end |