publish_my_data 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +37 -0
  3. data/Rakefile +41 -0
  4. data/app/assets/javascripts/publish_my_data/application.js +15 -0
  5. data/app/assets/javascripts/publish_my_data/resources.js +2 -0
  6. data/app/assets/stylesheets/publish_my_data/application.css +13 -0
  7. data/app/assets/stylesheets/publish_my_data/resources.css +4 -0
  8. data/app/controllers/publish_my_data/application_controller.rb +49 -0
  9. data/app/controllers/publish_my_data/datasets_controller.rb +48 -0
  10. data/app/controllers/publish_my_data/errors_controller.rb +9 -0
  11. data/app/controllers/publish_my_data/home_controller.rb +4 -0
  12. data/app/controllers/publish_my_data/resources_controller.rb +103 -0
  13. data/app/controllers/publish_my_data/sparql_controller.rb +50 -0
  14. data/app/helpers/publish_my_data/application_helper.rb +4 -0
  15. data/app/helpers/publish_my_data/resources_helper.rb +28 -0
  16. data/app/helpers/publish_my_data/sparql_helper.rb +7 -0
  17. data/app/models/publish_my_data/concept_scheme.rb +5 -0
  18. data/app/models/publish_my_data/dataset.rb +61 -0
  19. data/app/models/publish_my_data/ontology.rb +5 -0
  20. data/app/models/publish_my_data/rdf_type.rb +6 -0
  21. data/app/models/publish_my_data/resource.rb +21 -0
  22. data/app/views/layouts/publish_my_data/application.html.erb +14 -0
  23. data/app/views/layouts/publish_my_data/error.html.erb +3 -0
  24. data/app/views/publish_my_data/datasets/index.html.erb +20 -0
  25. data/app/views/publish_my_data/datasets/show.html.erb +18 -0
  26. data/app/views/publish_my_data/datasets/themes.html.erb +3 -0
  27. data/app/views/publish_my_data/errors/not_found.html.erb +1 -0
  28. data/app/views/publish_my_data/resources/_predicates_table.html.erb +22 -0
  29. data/app/views/publish_my_data/resources/_predicates_table_head.html.erb +6 -0
  30. data/app/views/publish_my_data/resources/_resource_formats.html.erb +11 -0
  31. data/app/views/publish_my_data/resources/_uri_and_label.html.erb +3 -0
  32. data/app/views/publish_my_data/resources/index.html.erb +39 -0
  33. data/app/views/publish_my_data/resources/show.html.erb +3 -0
  34. data/app/views/publish_my_data/sparql/_ask_formats.html.erb +3 -0
  35. data/app/views/publish_my_data/sparql/_construct_formats.html.erb +3 -0
  36. data/app/views/publish_my_data/sparql/_describe_formats.html.erb +1 -0
  37. data/app/views/publish_my_data/sparql/_error_message.html.erb +3 -0
  38. data/app/views/publish_my_data/sparql/_form.html.erb +4 -0
  39. data/app/views/publish_my_data/sparql/_formats.html.erb +6 -0
  40. data/app/views/publish_my_data/sparql/_pagination.html.erb +6 -0
  41. data/app/views/publish_my_data/sparql/_results.html.erb +5 -0
  42. data/app/views/publish_my_data/sparql/_results_data.html.erb +4 -0
  43. data/app/views/publish_my_data/sparql/_select_formats.html.erb +3 -0
  44. data/app/views/publish_my_data/sparql/endpoint.html.erb +10 -0
  45. data/config/initializers/tripod.rb +5 -0
  46. data/config/initializers/vocabularies.rb +1 -0
  47. data/config/routes.rb +33 -0
  48. data/lib/publish_my_data.rb +43 -0
  49. data/lib/publish_my_data/engine.rb +9 -0
  50. data/lib/publish_my_data/renderers.rb +44 -0
  51. data/lib/publish_my_data/sparql_query.rb +117 -0
  52. data/lib/publish_my_data/sparql_query_result.rb +49 -0
  53. data/lib/publish_my_data/version.rb +3 -0
  54. data/lib/tasks/publish_my_data_tasks.rake +4 -0
  55. data/spec/controllers/publish_my_data/datasets_controller_spec.rb +190 -0
  56. data/spec/controllers/publish_my_data/resources_controller_spec.rb +399 -0
  57. data/spec/controllers/publish_my_data/sparql_controller_spec.rb +172 -0
  58. data/spec/dummy/README.rdoc +261 -0
  59. data/spec/dummy/Rakefile +7 -0
  60. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  61. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  62. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  63. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  64. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  65. data/spec/dummy/config.ru +4 -0
  66. data/spec/dummy/config/application.rb +68 -0
  67. data/spec/dummy/config/boot.rb +10 -0
  68. data/spec/dummy/config/environment.rb +5 -0
  69. data/spec/dummy/config/environments/development.rb +38 -0
  70. data/spec/dummy/config/environments/production.rb +65 -0
  71. data/spec/dummy/config/environments/test.rb +41 -0
  72. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  73. data/spec/dummy/config/initializers/inflections.rb +15 -0
  74. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  75. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  76. data/spec/dummy/config/initializers/session_store.rb +8 -0
  77. data/spec/dummy/config/initializers/wrap_parameters.rb +10 -0
  78. data/spec/dummy/config/locales/en.yml +5 -0
  79. data/spec/dummy/config/routes.rb +4 -0
  80. data/spec/dummy/log/development.log +211 -0
  81. data/spec/dummy/log/test.log +105012 -0
  82. data/spec/dummy/public/404.html +26 -0
  83. data/spec/dummy/public/422.html +26 -0
  84. data/spec/dummy/public/500.html +25 -0
  85. data/spec/dummy/public/favicon.ico +0 -0
  86. data/spec/dummy/script/rails +6 -0
  87. data/spec/factories/dataset_factories.rb +12 -0
  88. data/spec/factories/property_factories.rb +13 -0
  89. data/spec/factories/resource_factories.rb +37 -0
  90. data/spec/features/running_a_sparql_query_spec.rb +324 -0
  91. data/spec/features/uri_dereferencing_flow_spec.rb +61 -0
  92. data/spec/features/uri_dereferencing_spec.rb +89 -0
  93. data/spec/features/viewing_a_def_spec.rb +45 -0
  94. data/spec/features/viewing_a_doc_spec.rb +124 -0
  95. data/spec/features/viewing_resource_not_in_our_domain_spec.rb +31 -0
  96. data/spec/lib/publish_my_data/sparql_query_spec.rb +495 -0
  97. data/spec/models/publish_my_data/dataset_spec.rb +29 -0
  98. data/spec/models/publish_my_data/resource_spec.rb +23 -0
  99. data/spec/renderers/publish_my_data/renderers_spec.rb +79 -0
  100. data/spec/spec_helper.rb +53 -0
  101. metadata +242 -0
@@ -0,0 +1,7 @@
1
+ module PublishMyData
2
+ module SparqlHelper
3
+ def link_to_sparql_results_format(text, format, query)
4
+ link_to text, :format => format, :query => query, :page => @page, :per_page => @per_page
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module PublishMyData
2
+ class ConceptScheme
3
+ include Tripod::Resource
4
+ end
5
+ end
@@ -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,5 @@
1
+ module PublishMyData
2
+ class Ontology
3
+ include Tripod::Resource
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ module PublishMyData
2
+ class RdfType
3
+ include Tripod::Resource
4
+ field :label, RDF::RDFS.label
5
+ end
6
+ 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,3 @@
1
+ error layout
2
+
3
+ <%= yield %>
@@ -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,3 @@
1
+ <% @themes.each do |t| %>
2
+ <%= link_to t, datasets_path(:theme => t) %> (<%= PublishMyData::Dataset.count_by_theme(t) %> datasets) <br/>
3
+ <% end %>
@@ -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,6 @@
1
+ <thead>
2
+ <tr>
3
+ <th>Predicate</th>
4
+ <th>Object</th>
5
+ </tr>
6
+ </thead>
@@ -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,3 @@
1
+ URI: <%= @resource.uri %>
2
+ <br/>
3
+ Label: <%= @resource.label.present? ? @resource.label : "No Label Set" %>
@@ -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,3 @@
1
+ <%= render 'uri_and_label' %>
2
+ <%= render 'predicates_table' %>
3
+ <%= render 'resource_formats' %>
@@ -0,0 +1,3 @@
1
+ <% Hash[*%w( JSON json XML xml Text text )].each_pair do |text, format| %>
2
+ <%= link_to_sparql_results_format( text, format, @sparql_query.query ) %>
3
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <% Hash[*%w( N-triples nt Turtle ttl RDF/XML rdf )].each_pair do |text, format| %>
2
+ <%= link_to_sparql_results_format( text, format, @sparql_query.query ) %>
3
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= render 'construct_formats' %>
@@ -0,0 +1,3 @@
1
+ <div>
2
+ <%= error_message %>
3
+ </div>
@@ -0,0 +1,4 @@
1
+ <%= form_tag sparql_endpoint_path, :method => :get do %>
2
+ <%= text_area_tag :query, @query_text %>
3
+ <%= submit_tag "Run Query" %>
4
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <%# formats %>
2
+ <% unless @error_message || @sparql_query.query_type == :unknown %>
3
+ <div>
4
+ <%= render "#{@sparql_query.query_type.to_s}_formats" %>
5
+ </div>
6
+ <% end %>
@@ -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,5 @@
1
+ <% if @error_message %>
2
+ <%= render 'error_message', :error_message => @error_message %>
3
+ <% else %>
4
+ <%= render 'results_data' %>
5
+ <% end %>
@@ -0,0 +1,4 @@
1
+ <pre><code><%= @sparql_query_result.to_s %></code></pre>
2
+ <% if @sparql_query.allow_pagination? %>
3
+ <%= render "pagination" %>
4
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <% Hash[*%w( XML xml JSON json CSV csv Text text )].each_pair do |text, format| %>
2
+ <%= link_to_sparql_results_format( text, format, @sparql_query.query ) %>
3
+ <% end %>
@@ -0,0 +1,10 @@
1
+ Execute a SPARQL query
2
+
3
+ <%# form %>
4
+ <%= render 'form' %>
5
+
6
+ <% if @sparql_query %>
7
+ <%= render 'results' %>
8
+ <%= render 'formats' %>
9
+ <% end %>
10
+
@@ -0,0 +1,5 @@
1
+ # set up tripod for dev mode.
2
+ Tripod.configure do |config|
3
+ config.query_endpoint = PublishMyData.sparql_endpoint
4
+ config.cache_store = PublishMyData.tripod_cache_store
5
+ end
@@ -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