Sha256: e0cfda1f75046dfcbe8d26c24be5fe9b3daa5caaca5b1119a97f410eb4e76a13

Contents?: true

Size: 1.24 KB

Versions: 8

Compression:

Stored size: 1.24 KB

Contents

module PublishMyData
  class ConceptScheme
    include Tripod::Resource
    include AllFeatures

    rdf_type RDF::SKOS.ConceptScheme
    deprecated_rdf_type 'http://publishmydata.com/def/concept-scheme#DeprecatedConceptScheme'

    def self.uri_from_slug(slug)
      "http://#{PublishMyData.local_domain}/def/#{slug}"
    end

    def concepts
      @concepts ||= Concept.find_by_sparql(
        "SELECT DISTINCT ?uri ?graph
          WHERE {
            GRAPH ?graph {
              ?uri <#{RDF::SKOS.inScheme.to_s}> <#{self.uri}> .
              ?uri a <#{RDF::SKOS.Concept.to_s}> .
          }
        }"
      )
    end

    def local?
      true
    end

    def eager_load!
      super
      self.concepts.each{|c| c.eager_load!}
    end

    # Overrides
    ['to_rdf', 'to_ttl', 'to_nt', 'to_json'].each do |method_name|
      define_method method_name do |opts={}|
        resources = Resource.find_by_sparql("
          SELECT DISTINCT ?uri
          WHERE {
            { SELECT ?uri WHERE { GRAPH <#{self.graph_uri}> {?uri ?p ?o} } }
            UNION
            { SELECT ?uri WHERE { GRAPH <#{self.data_graph_uri}> {?uri ?p ?o} } }
          }
        ")
        Tripod::ResourceCollection.new(resources).send(method_name)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
publish_my_data-1.0.4 app/models/publish_my_data/concept_scheme.rb
publish_my_data-1.0.3 app/models/publish_my_data/concept_scheme.rb
publish_my_data-1.0.2 app/models/publish_my_data/concept_scheme.rb
publish_my_data-1.0.1 app/models/publish_my_data/concept_scheme.rb
publish_my_data-1.0.0 app/models/publish_my_data/concept_scheme.rb
publish_my_data-0.0.32 app/models/publish_my_data/concept_scheme.rb
publish_my_data-0.0.31 app/models/publish_my_data/concept_scheme.rb
publish_my_data-0.0.30 app/models/publish_my_data/concept_scheme.rb