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.
- data/app/controllers/concerns/publish_my_data/data_download.rb +22 -0
- data/app/controllers/concerns/publish_my_data/resource_rendering.rb +40 -0
- data/app/controllers/concerns/publish_my_data/sparql_processing.rb +81 -0
- data/app/controllers/publish_my_data/datasets_controller.rb +5 -23
- data/app/controllers/publish_my_data/information_resources_controller.rb +26 -4
- data/app/controllers/publish_my_data/queries_controller.rb +1 -1
- data/app/controllers/publish_my_data/resources_controller.rb +5 -9
- data/app/controllers/publish_my_data/sparql_controller.rb +1 -1
- data/app/controllers/publish_my_data/vocabularies_controller.rb +18 -0
- data/app/models/concerns/publish_my_data/all_features.rb +79 -0
- data/app/models/concerns/publish_my_data/basic_features.rb +21 -0
- data/app/models/concerns/publish_my_data/dataset_powers.rb +130 -0
- data/{lib → app/models/concerns}/publish_my_data/defined_by_ontology.rb +5 -0
- data/app/models/publish_my_data/concept.rb +2 -2
- data/app/models/publish_my_data/concept_scheme.rb +31 -3
- data/app/models/publish_my_data/dataset.rb +2 -128
- data/app/models/publish_my_data/example_resource.rb +21 -0
- data/app/models/publish_my_data/ontology.rb +35 -6
- data/app/models/publish_my_data/ontology_class.rb +3 -5
- data/app/models/publish_my_data/property.rb +3 -5
- data/app/models/publish_my_data/rdf_type.rb +1 -2
- data/app/models/publish_my_data/resource.rb +25 -96
- data/app/models/publish_my_data/theme.rb +1 -3
- data/app/models/publish_my_data/third_party/concept_scheme.rb +30 -0
- data/app/models/publish_my_data/third_party/ontology.rb +30 -0
- data/app/models/publish_my_data/vocabulary.rb +22 -0
- data/app/views/publish_my_data/classes/show.html.erb +3 -0
- data/app/views/publish_my_data/concept_schemes/_concepts.html.erb +18 -3
- data/app/views/publish_my_data/concept_schemes/show.html.erb +3 -1
- data/app/views/publish_my_data/concepts/show.html.erb +3 -3
- data/app/views/publish_my_data/datasets/show.html.erb +2 -2
- data/app/views/publish_my_data/ontologies/show.html.erb +6 -6
- data/app/views/publish_my_data/properties/show.html.erb +3 -3
- data/app/views/publish_my_data/resources/_summaries.html.erb +18 -0
- data/app/views/publish_my_data/resources/show.html.erb +3 -3
- data/config/routes.rb +8 -4
- data/lib/publish_my_data.rb +14 -5
- data/lib/publish_my_data/engine.rb +3 -0
- data/lib/publish_my_data/version.rb +1 -1
- data/spec/controllers/publish_my_data/datasets_controller_spec.rb +3 -3
- data/spec/controllers/publish_my_data/information_resources_controller_spec.rb +158 -104
- data/spec/controllers/publish_my_data/resources_controller_spec.rb +0 -71
- data/spec/controllers/publish_my_data/vocabularies_controller_spec.rb +14 -0
- data/spec/dummy/config/environments/development.rb +1 -1
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/log/test.log +208075 -0
- data/spec/factories/concept_scheme_factories.rb +17 -13
- data/spec/factories/dataset_factories.rb +2 -0
- data/spec/factories/example_resource_factories.rb +9 -0
- data/spec/factories/ontology_factories.rb +17 -12
- data/spec/factories/property_factories.rb +1 -1
- data/spec/factories/resource_factories.rb +10 -0
- data/spec/features/running_a_sparql_query_spec.rb +2 -2
- data/spec/features/viewing_resources_spec.rb +96 -0
- data/spec/{renderers → lib}/publish_my_data/renderers_spec.rb +0 -0
- data/spec/models/publish_my_data/concept_scheme_spec.rb +20 -0
- data/spec/models/publish_my_data/dataset_spec.rb +113 -11
- data/spec/models/publish_my_data/example_resource_spec.rb +18 -0
- data/spec/models/publish_my_data/ontology_spec.rb +20 -0
- data/spec/models/publish_my_data/resource_spec.rb +63 -0
- data/spec/models/publish_my_data/third_party_concept_scheme_spec.rb +16 -0
- data/spec/models/publish_my_data/third_party_ontology_spec.rb +16 -0
- data/spec/spec_helper.rb +2 -1
- data/spec/support/all_features.rb +26 -0
- data/spec/support/data_download.rb +60 -0
- data/spec/support/vocabularies.rb +150 -0
- metadata +53 -33
- data/app/views/publish_my_data/ontologies/_classes.html.erb +0 -3
- data/app/views/publish_my_data/ontologies/_properties.html.erb +0 -3
- data/config/initializers/zz_factories.rb +0 -7
- data/lib/publish_my_data/concerns.rb +0 -4
- data/lib/publish_my_data/concerns/controllers/resource.rb +0 -23
- data/lib/publish_my_data/concerns/controllers/sparql.rb +0 -86
- data/lib/publish_my_data/concerns/models/resource.rb +0 -14
- data/lib/publish_my_data/render_params.rb +0 -7
- data/lib/publish_my_data/render_params/concept_render_params.rb +0 -18
- data/lib/publish_my_data/render_params/concept_scheme_render_params.rb +0 -31
- data/lib/publish_my_data/render_params/dataset_render_params.rb +0 -32
- data/lib/publish_my_data/render_params/ontology_class_render_params.rb +0 -18
- data/lib/publish_my_data/render_params/ontology_render_params.rb +0 -41
- data/lib/publish_my_data/render_params/property_render_params.rb +0 -18
- data/lib/publish_my_data/render_params/resource_render_params.rb +0 -17
@@ -1,23 +0,0 @@
|
|
1
|
-
module PublishMyData
|
2
|
-
module Concerns
|
3
|
-
module Controllers
|
4
|
-
module Resource
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
included do
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
|
-
def render_resource_with_uri(uri)
|
12
|
-
resource = PublishMyData::Resource.find(uri)
|
13
|
-
|
14
|
-
respond_with(resource) do |format|
|
15
|
-
format.html { render resource.render_params(request) }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
module PublishMyData
|
2
|
-
module Concerns
|
3
|
-
module Controllers
|
4
|
-
module Sparql
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
included do
|
8
|
-
|
9
|
-
rescue_from PublishMyData::SparqlQueryExecutionException, :with => :show_sparql_execution_message
|
10
|
-
|
11
|
-
rescue_from PublishMyData::SparqlQueryMissingVariablesException, :with => :missing_variables
|
12
|
-
|
13
|
-
respond_to :html, :csv, :text, :nt, :ttl, :xml, :rdf, :json
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def check_format
|
18
|
-
unless request.format
|
19
|
-
head :status => 406
|
20
|
-
return false
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def build_sparql_query(query_text)
|
25
|
-
interpolations = request.params.reject{ |p| ['controller', 'action', 'page', 'per_page', 'id', 'commit' ,'utf8', 'query'].include?(p) }
|
26
|
-
PublishMyData::SparqlQuery.new(query_text, {
|
27
|
-
:request_format => request.format.to_sym,
|
28
|
-
:interpolations => interpolations
|
29
|
-
})
|
30
|
-
end
|
31
|
-
|
32
|
-
# process the sparql query, paginating if appropriate
|
33
|
-
def process_sparql_query(sparql_query)
|
34
|
-
if sparql_query.allow_pagination?
|
35
|
-
|
36
|
-
@pagination_params = SparqlPaginationParams.from_request(request)
|
37
|
-
|
38
|
-
# if there are pagination paramters, then use them
|
39
|
-
if @pagination_params.per_page && @pagination_params.page
|
40
|
-
sparql_query_result = sparql_query.paginate(@pagination_params.page, @pagination_params.per_page)
|
41
|
-
if is_request_html_format?
|
42
|
-
count = sparql_query.as_pagination_query(@pagination_params.page, @pagination_params.per_page, 1).count
|
43
|
-
@more_pages = (count > @pagination_params.per_page)
|
44
|
-
end
|
45
|
-
# otherwise just execute
|
46
|
-
else
|
47
|
-
sparql_query_result = @sparql_query.execute
|
48
|
-
end
|
49
|
-
else
|
50
|
-
# pagination not allowed - just execute.
|
51
|
-
sparql_query_result = @sparql_query.execute
|
52
|
-
end
|
53
|
-
|
54
|
-
add_json_p_callback(sparql_query_result)
|
55
|
-
end
|
56
|
-
|
57
|
-
def respond_with_error
|
58
|
-
respond_to do |format|
|
59
|
-
format.html { render 'publish_my_data/sparql/endpoint' }
|
60
|
-
format.any { render :text => @error_message, :status => 400 }
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def missing_variables(e)
|
65
|
-
@error_message = e.message
|
66
|
-
respond_with_error
|
67
|
-
end
|
68
|
-
|
69
|
-
def show_sparql_execution_message(e)
|
70
|
-
@error_message = "There was a syntax error in your query: #{e.message}"
|
71
|
-
respond_with_error
|
72
|
-
end
|
73
|
-
|
74
|
-
def add_json_p_callback(result)
|
75
|
-
if request.format && request.format.json?
|
76
|
-
params[:callback] ? "#{params[:callback]}(#{result});" : result
|
77
|
-
else
|
78
|
-
result
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
@@ -1,7 +0,0 @@
|
|
1
|
-
require "publish_my_data/render_params/dataset_render_params"
|
2
|
-
require "publish_my_data/render_params/resource_render_params"
|
3
|
-
require "publish_my_data/render_params/ontology_render_params"
|
4
|
-
require "publish_my_data/render_params/property_render_params"
|
5
|
-
require "publish_my_data/render_params/ontology_class_render_params"
|
6
|
-
require "publish_my_data/render_params/concept_scheme_render_params"
|
7
|
-
require "publish_my_data/render_params/concept_render_params"
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module PublishMyData
|
2
|
-
class ConceptRenderParams
|
3
|
-
|
4
|
-
def initialize(resource)
|
5
|
-
@resource = resource
|
6
|
-
@concept = resource.as_concept
|
7
|
-
end
|
8
|
-
|
9
|
-
def render_params(opts={})
|
10
|
-
|
11
|
-
@concept.eager_load_predicate_triples!(:labels_only => true)
|
12
|
-
@concept.eager_load_object_triples!(:labels_only => true)
|
13
|
-
|
14
|
-
{template: 'publish_my_data/concepts/show', locals: {concept: @concept}}
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module PublishMyData
|
2
|
-
class ConceptSchemeRenderParams
|
3
|
-
|
4
|
-
def initialize(resource)
|
5
|
-
@resource = resource
|
6
|
-
@concept_scheme = resource.as_concept_scheme
|
7
|
-
end
|
8
|
-
|
9
|
-
def render_params(opts={})
|
10
|
-
|
11
|
-
@concept_scheme.eager_load_predicate_triples!(:labels_only => true)
|
12
|
-
@concept_scheme.eager_load_object_triples!(:labels_only => true)
|
13
|
-
|
14
|
-
concepts = []
|
15
|
-
|
16
|
-
concept_resources = @concept_scheme.concepts
|
17
|
-
concept_resources.each do |cr|
|
18
|
-
concept = cr.as_concept
|
19
|
-
concept.eager_load_predicate_triples!(:labels_only => true)
|
20
|
-
concept.eager_load_object_triples!(:labels_only => true)
|
21
|
-
concepts << concept
|
22
|
-
end
|
23
|
-
|
24
|
-
{
|
25
|
-
template: 'publish_my_data/concept_schemes/show',
|
26
|
-
locals: {concept_scheme: @concept_scheme, concepts: concepts}
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module PublishMyData
|
2
|
-
class DatasetRenderParams
|
3
|
-
|
4
|
-
def initialize(resource)
|
5
|
-
@resource = resource
|
6
|
-
@dataset = resource.as_dataset
|
7
|
-
end
|
8
|
-
|
9
|
-
def render_params(opts={})
|
10
|
-
|
11
|
-
@types = RdfType.where('?s a ?uri').graph(@dataset.data_graph_uri).resources
|
12
|
-
@dataset.eager_load_object_triples!(:labels_only => true) # for the owner URI label
|
13
|
-
@type_resource_counts = {}
|
14
|
-
@resources_count = 0
|
15
|
-
@types.each do |t|
|
16
|
-
count_query = "SELECT ?uri WHERE { GRAPH <#{@dataset.data_graph_uri.to_s}> { ?uri a <#{t.uri.to_s}> } }"
|
17
|
-
@type_resource_counts[t.uri.to_s] = SparqlQuery.new(count_query).count
|
18
|
-
@resources_count += @type_resource_counts[t.uri.to_s]
|
19
|
-
end
|
20
|
-
|
21
|
-
{
|
22
|
-
template: 'publish_my_data/datasets/show', locals: {
|
23
|
-
dataset: @dataset,
|
24
|
-
types: @types,
|
25
|
-
type_resource_counts: @type_resource_counts,
|
26
|
-
resources_count: @resources_count
|
27
|
-
}
|
28
|
-
}
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module PublishMyData
|
2
|
-
class OntologyClassRenderParams
|
3
|
-
|
4
|
-
def initialize(resource)
|
5
|
-
@resource = resource
|
6
|
-
@ontology_class = resource.as_ontology_class
|
7
|
-
end
|
8
|
-
|
9
|
-
def render_params(opts={})
|
10
|
-
|
11
|
-
@ontology_class.eager_load_predicate_triples!(:labels_only => true)
|
12
|
-
@ontology_class.eager_load_object_triples!(:labels_only => true)
|
13
|
-
|
14
|
-
{template: 'publish_my_data/classes/show', locals: {ontology_class: @ontology_class}}
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module PublishMyData
|
2
|
-
class OntologyRenderParams
|
3
|
-
|
4
|
-
def initialize(resource)
|
5
|
-
@resource = resource
|
6
|
-
@ontology = resource.as_ontology
|
7
|
-
end
|
8
|
-
|
9
|
-
def render_params(opts={})
|
10
|
-
|
11
|
-
@ontology.eager_load_predicate_triples!(:labels_only => true)
|
12
|
-
@ontology.eager_load_object_triples!(:labels_only => true)
|
13
|
-
|
14
|
-
ontology_classes = []
|
15
|
-
ontology_properties = []
|
16
|
-
|
17
|
-
ontology_class_resources = @ontology.ontology_classes
|
18
|
-
ontology_property_resources = @ontology.ontology_properties
|
19
|
-
|
20
|
-
ontology_class_resources.each do |ocr|
|
21
|
-
ontology_class = ocr.as_ontology_class
|
22
|
-
ontology_class.eager_load_predicate_triples!(:labels_only => true)
|
23
|
-
ontology_class.eager_load_object_triples!(:labels_only => true)
|
24
|
-
ontology_classes << ontology_class
|
25
|
-
end
|
26
|
-
|
27
|
-
ontology_property_resources.each do |opr|
|
28
|
-
ontology_property = opr.as_property
|
29
|
-
ontology_property.eager_load_predicate_triples!(:labels_only => true)
|
30
|
-
ontology_property.eager_load_object_triples!(:labels_only => true)
|
31
|
-
ontology_properties << ontology_property
|
32
|
-
end
|
33
|
-
|
34
|
-
{
|
35
|
-
template: 'publish_my_data/ontologies/show',
|
36
|
-
locals: {ontology: @ontology, ontology_classes: ontology_classes, ontology_properties: ontology_properties},
|
37
|
-
}
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module PublishMyData
|
2
|
-
class PropertyRenderParams
|
3
|
-
|
4
|
-
def initialize(resource)
|
5
|
-
@resource = resource
|
6
|
-
@property = resource.as_property
|
7
|
-
end
|
8
|
-
|
9
|
-
def render_params(opts={})
|
10
|
-
|
11
|
-
@property.eager_load_predicate_triples!(:labels_only => true)
|
12
|
-
@property.eager_load_object_triples!(:labels_only => true)
|
13
|
-
|
14
|
-
{template: 'publish_my_data/properties/show', locals: {property: @property}}
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module PublishMyData
|
2
|
-
class ResourceRenderParams
|
3
|
-
|
4
|
-
def initialize(resource)
|
5
|
-
@resource = resource
|
6
|
-
end
|
7
|
-
|
8
|
-
def render_params(opts={})
|
9
|
-
|
10
|
-
@resource.eager_load_predicate_triples!(:labels_only => true)
|
11
|
-
@resource.eager_load_object_triples!(:labels_only => true)
|
12
|
-
|
13
|
-
{template: 'publish_my_data/resources/show', locals: {resource: @resource}}
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|