publish_my_data 0.0.29 → 0.0.30

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/app/controllers/concerns/publish_my_data/data_download.rb +22 -0
  2. data/app/controllers/concerns/publish_my_data/resource_rendering.rb +40 -0
  3. data/app/controllers/concerns/publish_my_data/sparql_processing.rb +81 -0
  4. data/app/controllers/publish_my_data/datasets_controller.rb +5 -23
  5. data/app/controllers/publish_my_data/information_resources_controller.rb +26 -4
  6. data/app/controllers/publish_my_data/queries_controller.rb +1 -1
  7. data/app/controllers/publish_my_data/resources_controller.rb +5 -9
  8. data/app/controllers/publish_my_data/sparql_controller.rb +1 -1
  9. data/app/controllers/publish_my_data/vocabularies_controller.rb +18 -0
  10. data/app/models/concerns/publish_my_data/all_features.rb +79 -0
  11. data/app/models/concerns/publish_my_data/basic_features.rb +21 -0
  12. data/app/models/concerns/publish_my_data/dataset_powers.rb +130 -0
  13. data/{lib → app/models/concerns}/publish_my_data/defined_by_ontology.rb +5 -0
  14. data/app/models/publish_my_data/concept.rb +2 -2
  15. data/app/models/publish_my_data/concept_scheme.rb +31 -3
  16. data/app/models/publish_my_data/dataset.rb +2 -128
  17. data/app/models/publish_my_data/example_resource.rb +21 -0
  18. data/app/models/publish_my_data/ontology.rb +35 -6
  19. data/app/models/publish_my_data/ontology_class.rb +3 -5
  20. data/app/models/publish_my_data/property.rb +3 -5
  21. data/app/models/publish_my_data/rdf_type.rb +1 -2
  22. data/app/models/publish_my_data/resource.rb +25 -96
  23. data/app/models/publish_my_data/theme.rb +1 -3
  24. data/app/models/publish_my_data/third_party/concept_scheme.rb +30 -0
  25. data/app/models/publish_my_data/third_party/ontology.rb +30 -0
  26. data/app/models/publish_my_data/vocabulary.rb +22 -0
  27. data/app/views/publish_my_data/classes/show.html.erb +3 -0
  28. data/app/views/publish_my_data/concept_schemes/_concepts.html.erb +18 -3
  29. data/app/views/publish_my_data/concept_schemes/show.html.erb +3 -1
  30. data/app/views/publish_my_data/concepts/show.html.erb +3 -3
  31. data/app/views/publish_my_data/datasets/show.html.erb +2 -2
  32. data/app/views/publish_my_data/ontologies/show.html.erb +6 -6
  33. data/app/views/publish_my_data/properties/show.html.erb +3 -3
  34. data/app/views/publish_my_data/resources/_summaries.html.erb +18 -0
  35. data/app/views/publish_my_data/resources/show.html.erb +3 -3
  36. data/config/routes.rb +8 -4
  37. data/lib/publish_my_data.rb +14 -5
  38. data/lib/publish_my_data/engine.rb +3 -0
  39. data/lib/publish_my_data/version.rb +1 -1
  40. data/spec/controllers/publish_my_data/datasets_controller_spec.rb +3 -3
  41. data/spec/controllers/publish_my_data/information_resources_controller_spec.rb +158 -104
  42. data/spec/controllers/publish_my_data/resources_controller_spec.rb +0 -71
  43. data/spec/controllers/publish_my_data/vocabularies_controller_spec.rb +14 -0
  44. data/spec/dummy/config/environments/development.rb +1 -1
  45. data/spec/dummy/config/environments/test.rb +1 -1
  46. data/spec/dummy/log/test.log +208075 -0
  47. data/spec/factories/concept_scheme_factories.rb +17 -13
  48. data/spec/factories/dataset_factories.rb +2 -0
  49. data/spec/factories/example_resource_factories.rb +9 -0
  50. data/spec/factories/ontology_factories.rb +17 -12
  51. data/spec/factories/property_factories.rb +1 -1
  52. data/spec/factories/resource_factories.rb +10 -0
  53. data/spec/features/running_a_sparql_query_spec.rb +2 -2
  54. data/spec/features/viewing_resources_spec.rb +96 -0
  55. data/spec/{renderers → lib}/publish_my_data/renderers_spec.rb +0 -0
  56. data/spec/models/publish_my_data/concept_scheme_spec.rb +20 -0
  57. data/spec/models/publish_my_data/dataset_spec.rb +113 -11
  58. data/spec/models/publish_my_data/example_resource_spec.rb +18 -0
  59. data/spec/models/publish_my_data/ontology_spec.rb +20 -0
  60. data/spec/models/publish_my_data/resource_spec.rb +63 -0
  61. data/spec/models/publish_my_data/third_party_concept_scheme_spec.rb +16 -0
  62. data/spec/models/publish_my_data/third_party_ontology_spec.rb +16 -0
  63. data/spec/spec_helper.rb +2 -1
  64. data/spec/support/all_features.rb +26 -0
  65. data/spec/support/data_download.rb +60 -0
  66. data/spec/support/vocabularies.rb +150 -0
  67. metadata +53 -33
  68. data/app/views/publish_my_data/ontologies/_classes.html.erb +0 -3
  69. data/app/views/publish_my_data/ontologies/_properties.html.erb +0 -3
  70. data/config/initializers/zz_factories.rb +0 -7
  71. data/lib/publish_my_data/concerns.rb +0 -4
  72. data/lib/publish_my_data/concerns/controllers/resource.rb +0 -23
  73. data/lib/publish_my_data/concerns/controllers/sparql.rb +0 -86
  74. data/lib/publish_my_data/concerns/models/resource.rb +0 -14
  75. data/lib/publish_my_data/render_params.rb +0 -7
  76. data/lib/publish_my_data/render_params/concept_render_params.rb +0 -18
  77. data/lib/publish_my_data/render_params/concept_scheme_render_params.rb +0 -31
  78. data/lib/publish_my_data/render_params/dataset_render_params.rb +0 -32
  79. data/lib/publish_my_data/render_params/ontology_class_render_params.rb +0 -18
  80. data/lib/publish_my_data/render_params/ontology_render_params.rb +0 -41
  81. data/lib/publish_my_data/render_params/property_render_params.rb +0 -18
  82. data/lib/publish_my_data/render_params/resource_render_params.rb +0 -17
@@ -0,0 +1,22 @@
1
+ module PublishMyData
2
+ module DataDownload
3
+ def find_latest_download_url_for_resource(resource)
4
+ # find the latest download for this dataset
5
+ # Note: filenames on s3 take the format: "<prefix>_<slug>_<time>.nt.zip"
6
+ # Only look for ones that were made on the same day as the the modified date, to restrict the results
7
+ # (v. small possibility of errors for changes aroung midnight, but unlikely people will be changing datasets then anyway!)
8
+ s3 = AWS::S3.new
9
+ downloads = s3.buckets[PublishMyData.downloads_s3_bucket].objects.with_prefix(resource.download_prefix).to_a
10
+
11
+ download_url = nil
12
+ if downloads.any?
13
+ download_url = downloads.last.public_url.to_s
14
+ end
15
+ download_url
16
+ end
17
+
18
+ def type_for_resource(resource)
19
+ resource.class.name.demodulize.underscore # ontology, concept_scheme or vocabulary
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,40 @@
1
+ module PublishMyData
2
+ module ResourceRendering
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+
7
+ private
8
+
9
+ def render_resource(resource)
10
+ respond_with(resource) do |format|
11
+ format.html do
12
+ resource.eager_load!
13
+
14
+ logger.debug(locals_for_resource(resource))
15
+ render template: template_for_resource(resource), locals: locals_for_resource(resource)
16
+ end
17
+ end
18
+ end
19
+
20
+ def template_for_resource(resource)
21
+ {
22
+ Dataset => 'publish_my_data/datasets/show',
23
+ Ontology => 'publish_my_data/ontologies/show',
24
+ ConceptScheme => 'publish_my_data/concept_schemes/show',
25
+ OntologyClass => 'publish_my_data/classes/show',
26
+ Property => 'publish_my_data/properties/show',
27
+ Concept => 'publish_my_data/concepts/show',
28
+ Resource => 'publish_my_data/resources/show',
29
+ ThirdParty::Ontology => 'publish_my_data/ontologies/show',
30
+ ThirdParty::ConceptScheme => 'publish_my_data/concept_schemes/show'
31
+ }[resource.class]
32
+ end
33
+
34
+ def locals_for_resource(resource)
35
+ key = resource.class.name.demodulize.underscore.to_sym
36
+ {key => resource}
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,81 @@
1
+ module PublishMyData
2
+ module SparqlProcessing
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+
7
+ rescue_from PublishMyData::SparqlQueryExecutionException, :with => :show_sparql_execution_message
8
+
9
+ rescue_from PublishMyData::SparqlQueryMissingVariablesException, :with => :missing_variables
10
+
11
+ respond_to :html, :csv, :text, :nt, :ttl, :xml, :rdf, :json
12
+
13
+ private
14
+
15
+ def check_format
16
+ unless request.format
17
+ head :status => 406
18
+ return false
19
+ end
20
+ end
21
+
22
+ def build_sparql_query(query_text)
23
+ interpolations = request.params.reject{ |p| ['controller', 'action', 'page', 'per_page', 'id', 'commit' ,'utf8', 'query'].include?(p) }
24
+ PublishMyData::SparqlQuery.new(query_text, {
25
+ :request_format => request.format.to_sym,
26
+ :interpolations => interpolations
27
+ })
28
+ end
29
+
30
+ # process the sparql query, paginating if appropriate
31
+ def process_sparql_query(sparql_query)
32
+ if sparql_query.allow_pagination?
33
+
34
+ @pagination_params = SparqlPaginationParams.from_request(request)
35
+
36
+ # if there are pagination paramters, then use them
37
+ if @pagination_params.per_page && @pagination_params.page
38
+ sparql_query_result = sparql_query.paginate(@pagination_params.page, @pagination_params.per_page)
39
+ if is_request_html_format?
40
+ count = sparql_query.as_pagination_query(@pagination_params.page, @pagination_params.per_page, 1).count
41
+ @more_pages = (count > @pagination_params.per_page)
42
+ end
43
+ # otherwise just execute
44
+ else
45
+ sparql_query_result = @sparql_query.execute
46
+ end
47
+ else
48
+ # pagination not allowed - just execute.
49
+ sparql_query_result = @sparql_query.execute
50
+ end
51
+
52
+ add_json_p_callback(sparql_query_result)
53
+ end
54
+
55
+ def respond_with_error
56
+ respond_to do |format|
57
+ format.html { render 'publish_my_data/sparql/endpoint' }
58
+ format.any { render :text => @error_message, :status => 400 }
59
+ end
60
+ end
61
+
62
+ def missing_variables(e)
63
+ @error_message = e.message
64
+ respond_with_error
65
+ end
66
+
67
+ def show_sparql_execution_message(e)
68
+ @error_message = "There was a syntax error in your query: #{e.message}"
69
+ respond_with_error
70
+ end
71
+
72
+ def add_json_p_callback(result)
73
+ if request.format && request.format.json?
74
+ params[:callback] ? "#{params[:callback]}(#{result});" : result
75
+ else
76
+ result
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -2,36 +2,18 @@ require_dependency "publish_my_data/application_controller"
2
2
 
3
3
  module PublishMyData
4
4
  class DatasetsController < ApplicationController
5
+ include PublishMyData::DataDownload
5
6
 
6
7
  respond_to :html, :ttl, :rdf, :nt, :json, :text
7
8
 
8
9
  def dump
9
- s3 = AWS::S3.new
10
10
  @dataset = Dataset.find_by_slug(params[:id])
11
-
12
- # find the latest download for this dataset
13
- # Note: filenames on s3 take the format: "dataset_data_<slug>_time.nt.zip"
14
- # Only look for ones that were made on the same day as the the modified date, to restrict the results
15
- # (v. small possibility of errors for changes aroung midnight, but unlikely people will be changing datasets then anyway!)
16
- prefix = "dataset_data_#{@dataset.slug.gsub('/', '|')}_#{@dataset.modified.strftime("%Y%m%d")}"
17
- downloads = s3.buckets[PublishMyData.dataset_downloads_s3_bucket].objects.with_prefix(prefix).to_a
18
-
19
- # filter the downloads to only include ones with a timestamp equal to or after the dataset modified date.
20
- # (ones older than this are out of date)
21
- current_downloads = downloads.select do |d|
22
- date_portion = d.public_url.to_s.split("_").last.split('.').first #between last underscore and first dot.
23
- file_timestamp = DateTime.parse(date_portion)
24
- file_timestamp >= @dataset.modified
25
- end
26
-
27
11
  # if we can't find a current download it's cos we haven't generated it yet since ds was modified
28
12
  # ... and we should 404.
29
- if current_downloads.any?
30
- latest_download = current_downloads.last
31
- redirect_to latest_download.public_url.to_s
32
- else
33
- raise Tripod::Errors::ResourceNotFound
34
- end
13
+ url = find_latest_download_url_for_resource(@dataset)
14
+ raise Tripod::Errors::ResourceNotFound unless url
15
+
16
+ redirect_to url
35
17
  end
36
18
 
37
19
  # /data?page=2&per_page=10
@@ -3,15 +3,37 @@ require_dependency "publish_my_data/application_controller"
3
3
  module PublishMyData
4
4
  class InformationResourcesController < ApplicationController
5
5
 
6
+ include ResourceRendering
7
+ include DataDownload
8
+
6
9
  respond_to :html, :ttl, :rdf, :nt, :json, :text
7
10
 
8
- include PublishMyData::Concerns::Controllers::Resource
11
+ # http://example.com/data/blah
12
+ def data
13
+ uri = "http://#{PublishMyData.local_domain}/data/#{params[:id]}"
14
+ resource = PublishMyData::Resource.find(uri, local: true)
15
+ render_resource(resource)
16
+ end
9
17
 
10
- def show
11
- the_uri = "http://#{PublishMyData.local_domain}/data/#{params[:id]}"
12
- render_resource_with_uri(the_uri)
18
+ # http://example.com/def/blah
19
+ def def
20
+ uri = "http://#{PublishMyData.local_domain}/def/#{params[:id]}"
21
+ resource = PublishMyData::Resource.find(uri, local: true)
22
+ render_resource(resource)
13
23
  end
14
24
 
25
+ # http://example.com/def/blah/dump
26
+ def dump
27
+ uri = "http://#{PublishMyData.local_domain}/def/#{params[:id]}"
28
+ resource = PublishMyData::Resource.find(uri, local: true)
29
+
30
+ # if we can't find a current download it's cos we haven't generated it yet since ds was modified
31
+ # ... and we should 404.
32
+ url = find_latest_download_url_for_resource(resource)
33
+ raise Tripod::Errors::ResourceNotFound unless url
34
+
35
+ redirect_to url
36
+ end
15
37
  end
16
38
 
17
39
  end
@@ -3,7 +3,7 @@ require_dependency "publish_my_data/application_controller"
3
3
  module PublishMyData
4
4
  class QueriesController < ApplicationController
5
5
 
6
- include PublishMyData::Concerns::Controllers::Sparql
6
+ include PublishMyData::SparqlProcessing
7
7
 
8
8
  before_filter :check_format, :only => [:show]
9
9
 
@@ -3,7 +3,7 @@ require_dependency "publish_my_data/application_controller"
3
3
  module PublishMyData
4
4
  class ResourcesController < ApplicationController
5
5
 
6
- include PublishMyData::Concerns::Controllers::Resource
6
+ include ResourceRendering
7
7
 
8
8
  respond_to :html, :ttl, :rdf, :nt, :json, :text
9
9
 
@@ -30,7 +30,8 @@ module PublishMyData
30
30
 
31
31
  if uri.present?
32
32
  begin
33
- render_resource_with_uri(uri)
33
+ resource = PublishMyData::Resource.find(uri, local: uri.starts_with?('http://' + PublishMyData.local_domain))
34
+ render_resource(resource)
34
35
  rescue Tripod::Errors::ResourceNotFound
35
36
  # if it's not there
36
37
  respond_to do |format|
@@ -58,13 +59,8 @@ module PublishMyData
58
59
  # http://example.com/doc/blah
59
60
  def doc
60
61
  uri = Resource.uri_from_host_and_doc_path(request.host, params[:path], params[:format])
61
- render_resource_with_uri(uri)
62
- end
63
-
64
- # http://example.com/def/blah
65
- def definition
66
- uri = 'http://' + request.host + '/def/' + params[:path]
67
- render_resource_with_uri(uri)
62
+ resource = PublishMyData::Resource.find(uri)
63
+ render_resource(resource)
68
64
  end
69
65
 
70
66
  private
@@ -3,7 +3,7 @@ require_dependency "publish_my_data/application_controller"
3
3
  module PublishMyData
4
4
  class SparqlController < ApplicationController
5
5
 
6
- include PublishMyData::Concerns::Controllers::Sparql
6
+ include PublishMyData::SparqlProcessing
7
7
 
8
8
  before_filter :check_format, :only => [:endpoint]
9
9
 
@@ -0,0 +1,18 @@
1
+ require_dependency "publish_my_data/application_controller"
2
+
3
+ module PublishMyData
4
+ class VocabulariesController < ApplicationController
5
+ include PublishMyData::DataDownload
6
+
7
+ def dump
8
+ vocabulary = Vocabulary.find_by_data_dump(request.url)
9
+
10
+ # if we can't find a current download it's cos we haven't generated it yet since ds was modified
11
+ # ... and we should 404.
12
+ url = find_latest_download_url_for_resource(vocabulary)
13
+ raise Tripod::Errors::ResourceNotFound unless url
14
+
15
+ redirect_to url
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,79 @@
1
+ module PublishMyData
2
+ module AllFeatures
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ include PublishMyData::BasicFeatures
7
+
8
+ # basics
9
+ field :title, RDF::DC.title
10
+ field :description, RDF::DC.description # long desc
11
+
12
+ # licence, owner, contact
13
+ field :publisher, RDF::DC.publisher, :is_uri => true # value is a URI of a publisher
14
+ field :license, RDF::DC.license, :is_uri => true # value is URI of where licence is defined.
15
+ field :contact_email, RDF::PMD_DS.contactEmail, :is_uri => true
16
+ # NOTE: for contact, use :publisher's foaf:mbox value (in this metadata graph).
17
+
18
+ # quality, updates, maintenance
19
+ field :issued, RDF::DC.issued, :datatype => RDF::XSD.dateTime # value is DateTime literal
20
+ field :modified, RDF::DC.modified, :datatype => RDF::XSD.dateTime # value is DateTime literal
21
+ # field :update_periodicity, RDF::DC.accrualPeriodicity # waiting for response on what the value should be.
22
+
23
+ # where to get it
24
+ field :data_dump, RDF::VOID.dataDump, :is_uri => true # full download URI
25
+
26
+ # what the data is about
27
+ field :tags, RDF::DCAT.keyword, :multivalued => true # values are string literals
28
+
29
+ # field :spatial_coverage, RDF::DC.spatial # value is a URI for region covered, e.g. England.
30
+ # field :temporal_coverage, RDF::DC.temporal # value is a time interval URI
31
+ # field :spatial_granularity, RDF::DC.spatial # value is class of the objects of refArea
32
+ # field :temporal_granularity, RDF::DC.temporal # value is class of objects of refPeriod
33
+
34
+ field :size, RDF::VOID.triples # value is integer.
35
+ field :replaced_by, RDF::DC.isReplacedBy, is_uri: true
36
+
37
+ cattr_accessor :_DEPRECATED_RDF_TYPE
38
+ end
39
+
40
+ def deprecated?
41
+ self.rdf_type.include?(self.class.get_deprecated_rdf_type)
42
+ end
43
+
44
+ def slug
45
+ self.class.slug_from_uri(self.uri)
46
+ end
47
+
48
+ def resource_type
49
+ self.class.name.demodulize.underscore
50
+ end
51
+
52
+ def download_prefix
53
+ "#{self.resource_type}_data_#{self.slug.gsub('/', '|')}_#{self.modified.strftime("%Y%m%d")}"
54
+ end
55
+
56
+ module ClassMethods
57
+ def deprecated_rdf_type(type)
58
+ self._DEPRECATED_RDF_TYPE = type
59
+ end
60
+
61
+ def get_deprecated_rdf_type
62
+ self._DEPRECATED_RDF_TYPE
63
+ end
64
+
65
+ def uri_from_slug(slug)
66
+ # Implement!
67
+ end
68
+
69
+ def slug_from_uri(uri)
70
+ root_uri = self.uri_from_slug('')
71
+ uri.to_s.gsub(root_uri, '')
72
+ end
73
+
74
+ def find_by_slug(slug)
75
+ find(uri_from_slug(slug))
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,21 @@
1
+ module PublishMyData
2
+ module BasicFeatures
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ field :label, RDF::RDFS.label # same as the title
7
+ field :comment, RDF::RDFS.comment #short desc
8
+ field :data_graph_uri, RDF::PMD_DS.graph, is_uri: true
9
+ end
10
+
11
+ # Is this resource in the host domain?
12
+ def in_domain?(domain)
13
+ uri.starts_with?("http://" + domain)
14
+ end
15
+
16
+ def eager_load!
17
+ eager_load_object_triples!(labels_only: true)
18
+ eager_load_predicate_triples!(labels_only: true)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,130 @@
1
+ module PublishMyData
2
+ module DatasetPowers
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ include PublishMyData::AllFeatures
7
+ field :theme, RDF::DCAT.theme, :is_uri => true
8
+ end
9
+
10
+ def metadata_graph_uri
11
+ self.class.metadata_graph_uri(self.slug)
12
+ end
13
+
14
+ def to_param
15
+ slug
16
+ end
17
+
18
+ def resources_in_dataset_criteria
19
+ Resource.all.graph(self.data_graph_uri)
20
+ end
21
+
22
+ def types
23
+ @types ||= RdfType.where('?s a ?uri').graph(self.data_graph_uri).resources
24
+ end
25
+
26
+ def type_count(type_uri)
27
+ count_query = "SELECT ?uri WHERE { GRAPH <#{self.data_graph_uri.to_s}> { ?uri a <#{type_uri.to_s}> } }"
28
+ SparqlQuery.new(count_query).count
29
+ end
30
+
31
+ def resource_count
32
+ self.types.map{|t| type_count(t.uri)}.sum
33
+ end
34
+
35
+ def example_resources
36
+ return @example_resources if @example_resources
37
+
38
+ resource_queries = self.types.map do |t|
39
+ "{ SELECT DISTINCT ?uri WHERE { ?uri a <#{t.uri.to_s}> } LIMIT 1 }"
40
+ end
41
+ query = "SELECT ?uri WHERE { GRAPH <#{self.data_graph_uri.to_s}> {"
42
+ query << resource_queries.join(" UNION ")
43
+ query << "}}"
44
+ @example_resources = ExampleResource.find_by_sparql(query)
45
+ @example_resources.each {|r| r.eager_load!}
46
+ @example_resources
47
+ end
48
+
49
+ def ontologies
50
+ return @ontologies if @ontologies
51
+
52
+ query = "SELECT DISTINCT ?uri WHERE {"
53
+ query << " GRAPH <#{self.data_graph_uri.to_s}> {?s ?p ?o}"
54
+ query << " { ?p <http://www.w3.org/2000/01/rdf-schema#isDefinedBy> ?uri } UNION { ?o <http://www.w3.org/2000/01/rdf-schema#isDefinedBy> ?uri }"
55
+ query << " ?uri a <http://www.w3.org/2002/07/owl#Ontology>."
56
+ query << "}"
57
+ @ontologies = Ontology.find_by_sparql(query)
58
+ end
59
+
60
+ def concept_schemes
61
+ return @concept_schemes if @concept_schemes
62
+
63
+ query = "SELECT DISTINCT ?uri WHERE {"
64
+ query << " GRAPH <#{self.data_graph_uri.to_s}> {?s ?p ?o}"
65
+ query << " { ?p <http://www.w3.org/2004/02/skos/core#inScheme> ?uri } UNION { ?o <http://www.w3.org/2004/02/skos/core#inScheme> ?uri }"
66
+ query << " ?uri a <http://www.w3.org/2004/02/skos/core#ConceptScheme>"
67
+ query << "}"
68
+ @concept_schemes = ConceptScheme.find_by_sparql(query)
69
+ end
70
+
71
+ def theme_obj
72
+ Theme.find(self.theme.to_s) rescue nil
73
+ end
74
+
75
+ module ClassMethods
76
+ include PublishMyData::AllFeatures::ClassMethods
77
+
78
+ # this is the graph that dataset metadata goes in.
79
+ def metadata_graph_uri(slug)
80
+ "#{data_graph_uri(slug)}/metadata"
81
+ end
82
+
83
+ # this is the dataset that the actual data will go in
84
+ def data_graph_uri(slug)
85
+ "http://#{PublishMyData.local_domain}/graph/#{slug}"
86
+ end
87
+
88
+ def uri_from_data_graph_uri(data_graph_uri)
89
+ data_graph_uri.to_s.sub("/graph/", "/data/")
90
+ end
91
+
92
+ def uri_from_slug(slug)
93
+ "http://#{PublishMyData.local_domain}/data/#{slug}"
94
+ end
95
+
96
+ # Criteria etc.
97
+
98
+ def ordered_by_title
99
+ all.where("?uri <#{RDF::DC.title}> ?title").order("?title")
100
+ end
101
+
102
+ def deprecation_last_query_str
103
+ "
104
+ SELECT ?uri where {
105
+ # this bit is all the non-deprecated ones
106
+ {
107
+ SELECT * WHERE {
108
+ ?uri a <http://publishmydata.com/def/dataset#Dataset> .
109
+ ?uri <#{RDF::DC.title}> ?title . # select title so we can order
110
+ MINUS {
111
+ ?uri a <http://publishmydata.com/def/dataset#DeprecatedDataset>
112
+ }
113
+ }
114
+ ORDER BY ?title
115
+ }
116
+ UNION
117
+ # this bit is all the deprecated ones
118
+ {
119
+ SELECT * WHERE {
120
+ ?uri a <http://publishmydata.com/def/dataset#DeprecatedDataset> .
121
+ ?uri <#{RDF::DC.title}> ?title . # select title so we can order
122
+ }
123
+ ORDER BY ?title
124
+ }
125
+ }
126
+ "
127
+ end
128
+ end
129
+ end
130
+ end