publish_my_data 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.md +37 -0
- data/Rakefile +41 -0
- data/app/assets/javascripts/publish_my_data/application.js +15 -0
- data/app/assets/javascripts/publish_my_data/resources.js +2 -0
- data/app/assets/stylesheets/publish_my_data/application.css +13 -0
- data/app/assets/stylesheets/publish_my_data/resources.css +4 -0
- data/app/controllers/publish_my_data/application_controller.rb +49 -0
- data/app/controllers/publish_my_data/datasets_controller.rb +48 -0
- data/app/controllers/publish_my_data/errors_controller.rb +9 -0
- data/app/controllers/publish_my_data/home_controller.rb +4 -0
- data/app/controllers/publish_my_data/resources_controller.rb +103 -0
- data/app/controllers/publish_my_data/sparql_controller.rb +50 -0
- data/app/helpers/publish_my_data/application_helper.rb +4 -0
- data/app/helpers/publish_my_data/resources_helper.rb +28 -0
- data/app/helpers/publish_my_data/sparql_helper.rb +7 -0
- data/app/models/publish_my_data/concept_scheme.rb +5 -0
- data/app/models/publish_my_data/dataset.rb +61 -0
- data/app/models/publish_my_data/ontology.rb +5 -0
- data/app/models/publish_my_data/rdf_type.rb +6 -0
- data/app/models/publish_my_data/resource.rb +21 -0
- data/app/views/layouts/publish_my_data/application.html.erb +14 -0
- data/app/views/layouts/publish_my_data/error.html.erb +3 -0
- data/app/views/publish_my_data/datasets/index.html.erb +20 -0
- data/app/views/publish_my_data/datasets/show.html.erb +18 -0
- data/app/views/publish_my_data/datasets/themes.html.erb +3 -0
- data/app/views/publish_my_data/errors/not_found.html.erb +1 -0
- data/app/views/publish_my_data/resources/_predicates_table.html.erb +22 -0
- data/app/views/publish_my_data/resources/_predicates_table_head.html.erb +6 -0
- data/app/views/publish_my_data/resources/_resource_formats.html.erb +11 -0
- data/app/views/publish_my_data/resources/_uri_and_label.html.erb +3 -0
- data/app/views/publish_my_data/resources/index.html.erb +39 -0
- data/app/views/publish_my_data/resources/show.html.erb +3 -0
- data/app/views/publish_my_data/sparql/_ask_formats.html.erb +3 -0
- data/app/views/publish_my_data/sparql/_construct_formats.html.erb +3 -0
- data/app/views/publish_my_data/sparql/_describe_formats.html.erb +1 -0
- data/app/views/publish_my_data/sparql/_error_message.html.erb +3 -0
- data/app/views/publish_my_data/sparql/_form.html.erb +4 -0
- data/app/views/publish_my_data/sparql/_formats.html.erb +6 -0
- data/app/views/publish_my_data/sparql/_pagination.html.erb +6 -0
- data/app/views/publish_my_data/sparql/_results.html.erb +5 -0
- data/app/views/publish_my_data/sparql/_results_data.html.erb +4 -0
- data/app/views/publish_my_data/sparql/_select_formats.html.erb +3 -0
- data/app/views/publish_my_data/sparql/endpoint.html.erb +10 -0
- data/config/initializers/tripod.rb +5 -0
- data/config/initializers/vocabularies.rb +1 -0
- data/config/routes.rb +33 -0
- data/lib/publish_my_data.rb +43 -0
- data/lib/publish_my_data/engine.rb +9 -0
- data/lib/publish_my_data/renderers.rb +44 -0
- data/lib/publish_my_data/sparql_query.rb +117 -0
- data/lib/publish_my_data/sparql_query_result.rb +49 -0
- data/lib/publish_my_data/version.rb +3 -0
- data/lib/tasks/publish_my_data_tasks.rake +4 -0
- data/spec/controllers/publish_my_data/datasets_controller_spec.rb +190 -0
- data/spec/controllers/publish_my_data/resources_controller_spec.rb +399 -0
- data/spec/controllers/publish_my_data/sparql_controller_spec.rb +172 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +68 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +38 -0
- data/spec/dummy/config/environments/production.rb +65 -0
- data/spec/dummy/config/environments/test.rb +41 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +10 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/log/development.log +211 -0
- data/spec/dummy/log/test.log +105012 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories/dataset_factories.rb +12 -0
- data/spec/factories/property_factories.rb +13 -0
- data/spec/factories/resource_factories.rb +37 -0
- data/spec/features/running_a_sparql_query_spec.rb +324 -0
- data/spec/features/uri_dereferencing_flow_spec.rb +61 -0
- data/spec/features/uri_dereferencing_spec.rb +89 -0
- data/spec/features/viewing_a_def_spec.rb +45 -0
- data/spec/features/viewing_a_doc_spec.rb +124 -0
- data/spec/features/viewing_resource_not_in_our_domain_spec.rb +31 -0
- data/spec/lib/publish_my_data/sparql_query_spec.rb +495 -0
- data/spec/models/publish_my_data/dataset_spec.rb +29 -0
- data/spec/models/publish_my_data/resource_spec.rb +23 -0
- data/spec/renderers/publish_my_data/renderers_spec.rb +79 -0
- data/spec/spec_helper.rb +53 -0
- metadata +242 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
module PublishMyData
|
|
2
|
+
class Dataset
|
|
3
|
+
include Tripod::Resource
|
|
4
|
+
|
|
5
|
+
field :title, RDF::DC.title
|
|
6
|
+
field :description, RDF::DC.description
|
|
7
|
+
field :theme, PMD_DS.theme
|
|
8
|
+
|
|
9
|
+
rdf_type PMD_DS.Dataset
|
|
10
|
+
|
|
11
|
+
def slug
|
|
12
|
+
Dataset.slug_from_uri(self.uri)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def data_graph_uri
|
|
16
|
+
Dataset.data_graph_uri(self.slug)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def to_param
|
|
20
|
+
slug
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class << self
|
|
24
|
+
|
|
25
|
+
def by_theme_criteria(theme)
|
|
26
|
+
Dataset.where("?uri <#{PMD_DS.theme}> '#{theme}'")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def count_by_theme(theme)
|
|
30
|
+
by_theme_criteria(theme).count
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def by_theme(theme)
|
|
34
|
+
by_theme_criteria(theme).resources
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# this is the graph that dataset metadata goes in.
|
|
38
|
+
def metadata_graph_uri(slug)
|
|
39
|
+
"#{data_graph_uri(slug)}/metadata"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# this is the dataset that the actual data will go in
|
|
43
|
+
def data_graph_uri(slug)
|
|
44
|
+
"http://#{PublishMyData.local_domain}/graph/#{slug}"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def find_by_slug(slug)
|
|
48
|
+
Dataset.find(uri_from_slug(slug))
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def uri_from_slug(slug)
|
|
52
|
+
"http://#{PublishMyData.local_domain}/datasets/#{slug}"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def slug_from_uri(uri)
|
|
56
|
+
uri.to_s.split('/').last
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module PublishMyData
|
|
2
|
+
class Resource
|
|
3
|
+
|
|
4
|
+
include Tripod::Resource
|
|
5
|
+
|
|
6
|
+
field :label, RDF::RDFS.label
|
|
7
|
+
|
|
8
|
+
# Is this resource in the host domain?
|
|
9
|
+
def local?
|
|
10
|
+
uri.starts_with?("http://" + PublishMyData.local_domain)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class << self
|
|
14
|
+
|
|
15
|
+
def uri_from_host_and_doc_path(host, doc_path, format="")
|
|
16
|
+
'http://' + host + '/id/' + doc_path.split('?')[0].sub(/\.#{format}$/,'')
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>PublishMyData</title>
|
|
5
|
+
<%= stylesheet_link_tag "publish_my_data/application", :media => "all" %>
|
|
6
|
+
<%= javascript_include_tag "publish_my_data/application" %>
|
|
7
|
+
<%= csrf_meta_tags %>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
|
|
11
|
+
<%= yield %>
|
|
12
|
+
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<h1>datasets index</h1>
|
|
2
|
+
|
|
3
|
+
<% if @theme %>
|
|
4
|
+
Datasets in theme: <%= @theme %>
|
|
5
|
+
<br/><br/>
|
|
6
|
+
<% end %>
|
|
7
|
+
|
|
8
|
+
<% @datasets.each do |d| %>
|
|
9
|
+
<%= link_to d.title, d.uri.to_s %> <br/>
|
|
10
|
+
<% end %>
|
|
11
|
+
|
|
12
|
+
<%= paginate @datasets %>
|
|
13
|
+
|
|
14
|
+
<br/>
|
|
15
|
+
|
|
16
|
+
Get this list as:
|
|
17
|
+
<%= link_to 'N-triples', :format => 'nt', :page => @page, :per_page => @per_page %>
|
|
18
|
+
<%= link_to 'Turtle', :format => 'ttl', :page => @page, :per_page => @per_page %>
|
|
19
|
+
<%= link_to 'RDF/XML', :format => 'rdf',:page => @page, :per_page => @per_page %>
|
|
20
|
+
<%= link_to 'JSON', :format => 'json', :page => @page, :per_page => @per_page %>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<h1><%= @dataset.title %></h1>
|
|
2
|
+
|
|
3
|
+
<%= @dataset.description %>
|
|
4
|
+
|
|
5
|
+
<h2> Types in this ds</h2>
|
|
6
|
+
|
|
7
|
+
<% @types.each do |t| %>
|
|
8
|
+
<%= link_to t.label || t.uri, resource_path_from_uri(t.uri) %>
|
|
9
|
+
(<%= link_to "#{@type_resource_counts[t.uri.to_s]} resources", list_resources_path(dataset: @dataset.slug, type_uri: t.uri)%>)
|
|
10
|
+
<br/>
|
|
11
|
+
<% end %>
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
Get this page as:
|
|
15
|
+
<%= link_to 'N-triples', format: 'nt' %>
|
|
16
|
+
<%= link_to 'Turtle', format: 'ttl' %>
|
|
17
|
+
<%= link_to 'RDF/XML', format: 'rdf' %>
|
|
18
|
+
<%= link_to 'JSON', format: 'json' %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Not found.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<table>
|
|
2
|
+
<thead>
|
|
3
|
+
<tr>
|
|
4
|
+
<th>Predicate</th>
|
|
5
|
+
<th>Object</th>
|
|
6
|
+
</tr>
|
|
7
|
+
</thead>
|
|
8
|
+
<tbody>
|
|
9
|
+
<% @resource.predicates.each do |pred| %>
|
|
10
|
+
<tr>
|
|
11
|
+
<td>
|
|
12
|
+
<%= resource_uri_or_label(pred) %>
|
|
13
|
+
</td>
|
|
14
|
+
<td>
|
|
15
|
+
<% @resource.read_predicate(pred).each do |obj| %>
|
|
16
|
+
<%= resource_uri_or_label(obj) %>
|
|
17
|
+
<% end %>
|
|
18
|
+
</td>
|
|
19
|
+
</tr>
|
|
20
|
+
<% end %>
|
|
21
|
+
</tbody>
|
|
22
|
+
</table>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<% if @resource.local? %>
|
|
2
|
+
<%= link_to "JSON", :format => 'json' %>
|
|
3
|
+
<%= link_to "RDF/XML", :format => 'rdf' %>
|
|
4
|
+
<%= link_to "Turtle", :format => 'ttl' %>
|
|
5
|
+
<%= link_to "N-triples", :format => 'nt' %>
|
|
6
|
+
<% else %>
|
|
7
|
+
<%= link_to "JSON", show_resource_path(:uri => @resource.uri, :format => 'json') %>
|
|
8
|
+
<%= link_to "RDF/XML", show_resource_path(:uri => @resource.uri, :format => 'rdf') %>
|
|
9
|
+
<%= link_to "Turtle", show_resource_path(:uri => @resource.uri, :format => 'ttl') %>
|
|
10
|
+
<%= link_to "N-triples", show_resource_path(:uri => @resource.uri, :format => 'nt') %>
|
|
11
|
+
<% end %>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<h1>Resources</h1>
|
|
2
|
+
|
|
3
|
+
<!-- Filter info -->
|
|
4
|
+
|
|
5
|
+
<% if @type_filter %>
|
|
6
|
+
Of type:
|
|
7
|
+
<% if @type %>
|
|
8
|
+
<%= link_to @type.label || @type.uri, resource_path_from_uri(@type.uri) %>
|
|
9
|
+
<% else %>
|
|
10
|
+
<%= link_to @type_filter, resource_path_from_uri(@type_filter) %>
|
|
11
|
+
<% end %>
|
|
12
|
+
<br/>
|
|
13
|
+
<% end %>
|
|
14
|
+
|
|
15
|
+
<% if @dataset_filter %>
|
|
16
|
+
In dataset:
|
|
17
|
+
<% if @dataset %>
|
|
18
|
+
<%= link_to @dataset.title, @dataset %>
|
|
19
|
+
<% else %>
|
|
20
|
+
<%= link_to @dataset_filter, resource_path_from_uri(@dataset_filter) %>
|
|
21
|
+
<% end %>
|
|
22
|
+
<br/>
|
|
23
|
+
<% end %>
|
|
24
|
+
|
|
25
|
+
<br/>
|
|
26
|
+
|
|
27
|
+
<% @resources.each do |r| %>
|
|
28
|
+
<%= link_to (r.label || r.uri), resource_path_from_uri(r.uri) %><br/>
|
|
29
|
+
<% end %>
|
|
30
|
+
|
|
31
|
+
<%= paginate @resources %>
|
|
32
|
+
|
|
33
|
+
<br/>
|
|
34
|
+
|
|
35
|
+
Get this list as:
|
|
36
|
+
<%= link_to 'N-triples', :format => 'nt', :page => @page, :per_page => @per_page %>
|
|
37
|
+
<%= link_to 'Turtle', :format => 'ttl', :page => @page, :per_page => @per_page %>
|
|
38
|
+
<%= link_to 'RDF/XML', :format => 'rdf',:page => @page, :per_page => @per_page %>
|
|
39
|
+
<%= link_to 'JSON', :format => 'json', :page => @page, :per_page => @per_page %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= render 'construct_formats' %>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<nav class="pagination clearfix">
|
|
2
|
+
<% #only show prev link if there's a previous page %>
|
|
3
|
+
<%= link_to("Previous #{@per_page} results".html_safe, params.merge({:page => (@page-1)})) if @page > 1 %>
|
|
4
|
+
<% #only show the next page if the results for this page is bigger than the page size %>
|
|
5
|
+
<%= link_to("Next #{@per_page} results".html_safe, params.merge({:page => (@page+1)}), :style => 'float:right' ) if @more_pages%>
|
|
6
|
+
</nav>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
PMD_DS = RDF::Vocabulary.new("http://publishmydata.com/def/dataset#")
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
PublishMyData::Engine.routes.draw do
|
|
2
|
+
|
|
3
|
+
# data home
|
|
4
|
+
root :to => 'home#index'
|
|
5
|
+
|
|
6
|
+
# resource show
|
|
7
|
+
match "/resource(.:format)" => "resources#show", :as => 'show_resource' # http://resource?uri=http://foo.bar
|
|
8
|
+
|
|
9
|
+
# resources lists
|
|
10
|
+
match "/resources(.:format)" => "resources#index", :as => 'list_resources' # +filters on thh query string
|
|
11
|
+
|
|
12
|
+
# datasets
|
|
13
|
+
resources :datasets, :only => [:show, :index] do
|
|
14
|
+
collection do
|
|
15
|
+
get 'themes'
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# URI dereferencing
|
|
20
|
+
match "/id/*path" => "resources#id"
|
|
21
|
+
match "/doc/*path.:format" => "resources#doc"
|
|
22
|
+
match "/doc/*path" => "resources#doc"
|
|
23
|
+
|
|
24
|
+
# def pages
|
|
25
|
+
match "/def/*path.:format" => "resources#definition"
|
|
26
|
+
match "/def/*path" => "resources#definition"
|
|
27
|
+
|
|
28
|
+
# SPARQL
|
|
29
|
+
match "sparql" => "sparql#endpoint", :as => 'sparql_endpoint' # the main sparql endpoint
|
|
30
|
+
|
|
31
|
+
#http://techoctave.com/c7/posts/36-rails-3-0-rescue-from-routing-error-solution
|
|
32
|
+
match '*a', :to => 'errors#routing'
|
|
33
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require "publish_my_data/engine"
|
|
2
|
+
require "publish_my_data/renderers"
|
|
3
|
+
require "publish_my_data/sparql_query"
|
|
4
|
+
require "publish_my_data/sparql_query_result"
|
|
5
|
+
|
|
6
|
+
module PublishMyData
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# The local domain of the website. Used to decide if resources andexdsf
|
|
10
|
+
# datasets are local or not
|
|
11
|
+
mattr_accessor :local_domain
|
|
12
|
+
@@local_domain = 'pmd.dev'
|
|
13
|
+
|
|
14
|
+
mattr_accessor :sparql_timeout_seconds
|
|
15
|
+
@@sparql_timeout_seconds = 30
|
|
16
|
+
|
|
17
|
+
mattr_accessor :sparql_endpoint
|
|
18
|
+
@@sparql_endpoint = 'http://localhost:3030/pmd/sparql'
|
|
19
|
+
|
|
20
|
+
mattr_accessor :tripod_cache_store
|
|
21
|
+
|
|
22
|
+
# Use +configure+ to override PublishMyData configuration in an app, e.g.:
|
|
23
|
+
# (defaults shown)
|
|
24
|
+
#
|
|
25
|
+
# PublishMyData.configure do |config|
|
|
26
|
+
# config.sparql_endpoint = 'http://localhost:3030/pmd/sparql'
|
|
27
|
+
# config.local_domain = 'pmd.dev'
|
|
28
|
+
# config.sparql_timeout_seconds = 30
|
|
29
|
+
# config.tripod_cache_store = nil #e.g Tripod::CacheStores::MemcachedCacheStore.new('localhost:11211')
|
|
30
|
+
# # note: if using memcached, make sure you set the -I (slab size) to big enough to store each result (i.e. to more than SparqlQueryResult.MAX_SIZE)
|
|
31
|
+
# # and set the -m (total size) to something quite big (or the cache will recycle too often).
|
|
32
|
+
# end
|
|
33
|
+
def self.configure
|
|
34
|
+
yield self
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
require 'kaminari'
|
|
40
|
+
|
|
41
|
+
Kaminari.configure do |config|
|
|
42
|
+
config.default_per_page = 20
|
|
43
|
+
end
|