Sha256: 29709938ad99007f6228d4d2e18382ecff0dd7ca090ff2b427cf18a5569e4090

Contents?: true

Size: 1.84 KB

Versions: 8

Compression:

Stored size: 1.84 KB

Contents

module PublishMyData
  class Ontology
    include Tripod::Resource
    include AllFeatures

    rdf_type RDF::OWL.Ontology
    deprecated_rdf_type 'http://publishmydata.com/def/ontology#DeprecatedOntology'

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

    def classes
      @classes ||= OntologyClass.find_by_sparql("
        SELECT DISTINCT ?uri ?graph
        WHERE {
          GRAPH ?graph {
            {
              ?uri <http://www.w3.org/2000/01/rdf-schema#isDefinedBy> <#{self.uri}> .
              ?uri a <http://www.w3.org/2002/07/owl#Class> .
            }
            UNION
            {
              ?uri <http://www.w3.org/2000/01/rdf-schema#isDefinedBy> <#{self.uri}> .
              ?uri a <http://www.w3.org/2000/01/rdf-schema#Class>
            }
          }
        }"
      )
    end

    def properties
      @properties ||= Property.find_by_sparql("
        SELECT DISTINCT ?uri ?graph
         WHERE {
          GRAPH ?graph {
            ?uri <http://www.w3.org/2000/01/rdf-schema#isDefinedBy> <#{self.uri}> .
            ?uri a <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property> .
          }
        }"
      )
    end

    def local?
      true
    end

    def eager_load!
      super
      classes.each{|c| c.eager_load!}
      properties.each{|p| p.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/ontology.rb
publish_my_data-1.0.3 app/models/publish_my_data/ontology.rb
publish_my_data-1.0.2 app/models/publish_my_data/ontology.rb
publish_my_data-1.0.1 app/models/publish_my_data/ontology.rb
publish_my_data-1.0.0 app/models/publish_my_data/ontology.rb
publish_my_data-0.0.32 app/models/publish_my_data/ontology.rb
publish_my_data-0.0.31 app/models/publish_my_data/ontology.rb
publish_my_data-0.0.30 app/models/publish_my_data/ontology.rb