Sha256: 54475c042652c6d826856c7defd7e652f89727a10c3ba2ecac43d4a34d0c424a

Contents?: true

Size: 1.99 KB

Versions: 31

Compression:

Stored size: 1.99 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 classes_sorted
      Ontology.sort_by_label_or_uri(classes)
    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 properties_sorted
      Ontology.sort_by_label_or_uri(properties)
    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

31 entries across 31 versions & 1 rubygems

Version Path
publish_my_data-1.3.25 app/models/publish_my_data/ontology.rb
publish_my_data-1.3.24 app/models/publish_my_data/ontology.rb
publish_my_data-1.3.23 app/models/publish_my_data/ontology.rb
publish_my_data-1.3.22 app/models/publish_my_data/ontology.rb
publish_my_data-1.3.21 app/models/publish_my_data/ontology.rb
publish_my_data-1.3.20 app/models/publish_my_data/ontology.rb
publish_my_data-1.3.19 app/models/publish_my_data/ontology.rb
publish_my_data-1.3.18 app/models/publish_my_data/ontology.rb
publish_my_data-1.3.17 app/models/publish_my_data/ontology.rb
publish_my_data-1.3.16 app/models/publish_my_data/ontology.rb
publish_my_data-1.3.15 app/models/publish_my_data/ontology.rb
publish_my_data-1.3.14 app/models/publish_my_data/ontology.rb
publish_my_data-1.3.13 app/models/publish_my_data/ontology.rb
publish_my_data-1.3.12 app/models/publish_my_data/ontology.rb
publish_my_data-1.3.11 app/models/publish_my_data/ontology.rb
publish_my_data-1.3.10 app/models/publish_my_data/ontology.rb
publish_my_data-1.3.9 app/models/publish_my_data/ontology.rb
publish_my_data-1.3.8 app/models/publish_my_data/ontology.rb
publish_my_data-1.3.7 app/models/publish_my_data/ontology.rb
publish_my_data-1.3.6 app/models/publish_my_data/ontology.rb