ld4l-ore_rdf 0.0.4

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.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +25 -0
  4. data/.travis.yml +12 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE.txt +14 -0
  7. data/README.md +171 -0
  8. data/Rakefile +2 -0
  9. data/ld4l-ore_rdf.gemspec +45 -0
  10. data/lib/ld4l/ore_rdf/configuration.rb +41 -0
  11. data/lib/ld4l/ore_rdf/models/aggregation.rb +50 -0
  12. data/lib/ld4l/ore_rdf/models/aggregation_resource.rb +98 -0
  13. data/lib/ld4l/ore_rdf/models/proxy_resource.rb +54 -0
  14. data/lib/ld4l/ore_rdf/services/aggregation/add_aggregated_resource.rb +49 -0
  15. data/lib/ld4l/ore_rdf/services/aggregation/add_aggregated_resources.rb +28 -0
  16. data/lib/ld4l/ore_rdf/services/aggregation/create.rb +39 -0
  17. data/lib/ld4l/ore_rdf/services/aggregation/destroy.rb +47 -0
  18. data/lib/ld4l/ore_rdf/services/aggregation/destroy_with_id.rb +22 -0
  19. data/lib/ld4l/ore_rdf/services/aggregation/find.rb +72 -0
  20. data/lib/ld4l/ore_rdf/services/aggregation/persist.rb +34 -0
  21. data/lib/ld4l/ore_rdf/services/aggregation/resume.rb +30 -0
  22. data/lib/ld4l/ore_rdf/services/proxy/create.rb +64 -0
  23. data/lib/ld4l/ore_rdf/services/proxy/find.rb +93 -0
  24. data/lib/ld4l/ore_rdf/version.rb +5 -0
  25. data/lib/ld4l/ore_rdf/vocab/co.rb +27 -0
  26. data/lib/ld4l/ore_rdf/vocab/dcterms.rb +6 -0
  27. data/lib/ld4l/ore_rdf/vocab/iana.rb +9 -0
  28. data/lib/ld4l/ore_rdf/vocab/ore.rb +16 -0
  29. data/lib/ld4l/ore_rdf.rb +76 -0
  30. data/spec/ld4l/ore_rdf/configuration_spec.rb +174 -0
  31. data/spec/ld4l/ore_rdf/models/aggregation_resource_spec.rb +830 -0
  32. data/spec/ld4l/ore_rdf/models/aggregation_spec.rb +9 -0
  33. data/spec/ld4l/ore_rdf/models/proxy_resource_spec.rb +690 -0
  34. data/spec/ld4l/ore_rdf/services/aggregation/add_aggregated_resource_spec.rb +36 -0
  35. data/spec/ld4l/ore_rdf/services/aggregation/add_aggregated_resources_spec.rb +78 -0
  36. data/spec/ld4l/ore_rdf/services/aggregation/create_spec.rb +62 -0
  37. data/spec/ld4l/ore_rdf/services/aggregation/destroy_spec.rb +169 -0
  38. data/spec/ld4l/ore_rdf/services/aggregation/find_spec.rb +198 -0
  39. data/spec/ld4l/ore_rdf/services/aggregation/persist_spec.rb +13 -0
  40. data/spec/ld4l/ore_rdf/services/aggregation/resume_spec.rb +46 -0
  41. data/spec/ld4l/ore_rdf/services/proxy/create_spec.rb +143 -0
  42. data/spec/ld4l/ore_rdf/services/proxy/find_spec.rb +138 -0
  43. data/spec/ld4l/ore_rdf_spec.rb +53 -0
  44. data/spec/spec_helper.rb +23 -0
  45. metadata +259 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 42f818dcf199be0185f9263e59b29021005da3ff
4
+ data.tar.gz: ee3b57a06cf31f8cff3960671084125dc36c97c0
5
+ SHA512:
6
+ metadata.gz: 4d14dc0c0b6fd35c6dfe8cf219f4fb76634c9e068e6d5cb1de12a1b85aabd309460ec6d29c8a5f0940f5c8935fd983ab61f4f422df04695b0f12dd252d060a7b
7
+ data.tar.gz: 3138b70ced75abfd2cda84bef5ad24acfa5a3f2c58ab01828397234669533261574890c67b0a47d0708544d832d4f6a6465afc7effbe19213cf3f8bfe3697b21
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,25 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .idea
24
+ .ruby-gemset
25
+ .ruby-version
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ bundler_args: --without debug
3
+ script: "bundle exec rspec spec"
4
+ rvm:
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.0
8
+ - 2.1.1
9
+ - jruby-19mode
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: jruby-19mode
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (c) 2014 Cornell University
2
+
3
+ ##########################################################################
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
data/README.md ADDED
@@ -0,0 +1,171 @@
1
+ #LD4L::OreRDF
2
+
3
+ [![Build Status](https://travis-ci.org/ld4l/ore_rdf.png?branch=rework_with_service_objects)](https://travis-ci.org/ld4l/ore_rdf)
4
+ [![Coverage Status](https://coveralls.io/repos/ld4l/ore_rdf/badge.png?branch=rework_with_service_objects)](https://coveralls.io/r/ld4l/ore_rdf?branch=rework_with_service_objects)
5
+ [![Gem Version](https://badge.fury.io/rb/ld4l-ore_rdf.svg)](http://badge.fury.io/rb/ld4l-ore_rdf)
6
+ [![Dependency Status](https://www.versioneye.com/ruby/ld4l-ore_rdf/0.0.3/badge.svg)](https://www.versioneye.com/ruby/ld4l-ore_rdf/0.0.3)
7
+
8
+
9
+
10
+ LD4L ORE RDF provides tools for modeling list triples based on the ORE ontology and persisting to a triplestore.
11
+
12
+
13
+ ## Installation
14
+
15
+ Temporary get the gem from github until the gem is released publicly.
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ gem 'ld4l-ore_rdf'
20
+
21
+
22
+ And then execute:
23
+
24
+ $ bundle install
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install ld4l-ore_rdf
29
+
30
+
31
+ ## Usage
32
+
33
+ **Caveat:** This gem is part of the LD4L Project and is being used in that context. There is no guarantee that the
34
+ code will work in a usable way outside of its use in LD4L Use Cases.
35
+
36
+ ### Examples
37
+
38
+ *Setup required for all examples.*
39
+ ```
40
+ require 'ld4l/ore_rdf'
41
+
42
+ # create an in-memory repository
43
+ ActiveTriples::Repositories.add_repository :default, RDF::Repository.new
44
+
45
+ p = LD4L::FoafRDF::Person.new('p4')
46
+ ```
47
+
48
+ #### Example: Aggregation with items individually
49
+ ```
50
+ agg10 = LD4L::OreRDF::CreateAggregation.call( :id=>'agg10', :title=>'My Resources', :description=>'Resources that I like', :owner=>p )
51
+
52
+ LD4L::OreRDF::AddAggregatedResource.call( agg10,'http://exmple.org/resource_1')
53
+ LD4L::OreRDF::AddAggregatedResource.call( agg10'http://exmple.org/resource_2')
54
+ LD4L::OreRDF::AddAggregatedResource.call( agg10,'http://exmple.org/resource_3')
55
+
56
+ LD4L::OreRDF::PersistAggregation.call(agg10)
57
+
58
+ puts agg10.dump :ttl
59
+
60
+ # To resume the aggregation at a later time, use...
61
+ agg = LD4L::OreRDF::ResumeAggregation.call( 'agg10' )
62
+ ```
63
+
64
+ #### Example: Aggregation with items as array
65
+ ```
66
+ agg11 = LD4L::OreRDF::CreateAggregation.call( :id=>'agg11', :title=>'More Resources', :description=>'More resources that I like', :owner=>p )
67
+
68
+ resources = [ 'http://exmple.org/resource_5', 'http://exmple.org/resource_6', 'http://exmple.org/resource_7' ]
69
+ LD4L::OreRDF::AddAggregatedResources.call( agg11,resources)
70
+
71
+ LD4L::OreRDF::PersistAggregation.call(agg11)
72
+
73
+ puts agg11.dump :ttl
74
+
75
+ # To resume the aggregation at a later time, use...
76
+ agg = LD4L::OreRDF::ResumeAggregation.call( 'agg10' )
77
+ ```
78
+
79
+ #### Example: Find all aggregations
80
+ ```
81
+ # Find all and return only the URIs for each aggregation
82
+ aggregation_uris = LD4L::OreRDF::FindAggregations.call
83
+
84
+ # Find all and return title and description
85
+ aggregation_properties = LD4L::OreRDF::FindAggregations.call(
86
+ :properties => { :title => RDF::DC.title, :description => RDF::DC.description } )
87
+
88
+ ```
89
+
90
+
91
+ ### Configurations
92
+
93
+ * base_uri - base URI used when new resources are created (default="http://localhost/")
94
+ * localname_minter - minter function to use for creating unique local names (default=nil which uses default minter in active_triples-local_name gem)
95
+
96
+ *Setup for all examples.*
97
+
98
+ * Restart your interactive session (e.g. irb, pry).
99
+ * Use the Setup for all examples in main Examples section above.
100
+
101
+ *Example usage using configured base_uri and default localname_minter.*
102
+ ```
103
+ LD4L::OreRDF.configure do |config|
104
+ config.base_uri = "http://example.org/"
105
+ end
106
+
107
+ a = LD4L::OreRDF::AggregationResource.new(ActiveTriples::LocalName::Minter.generate_local_name(
108
+ LD4L::OreRDF::AggregationResource, 10, {:prefix=>'ag'} ))
109
+
110
+ puts a.dump :ttl
111
+ ```
112
+ NOTE: If base_uri is not used, you need to restart your interactive environment (e.g. irb, pry). Once the
113
+ Aggregation class is instantiated the first time, the base_uri for the class is set. If you ran
114
+ through the main Examples, the base_uri was set to the default base_uri.
115
+
116
+
117
+ *Example triples created for an aggregation with configured base_uri and default minter.*
118
+ ```
119
+ <http://example.org/ag45c9c85b-25af-4c52-96a4-cf0d8b70a768> a <http://www.openarchives.org/ore/terms/Aggregation> .
120
+ ```
121
+
122
+ *Example usage using configured base_uri and configured localname_minter.*
123
+ ```
124
+ LD4L::OreRDF.configure do |config|
125
+ config.base_uri = "http://example.org/"
126
+ config.localname_minter = lambda { |prefix=""| prefix+'_configured_'+SecureRandom.uuid }
127
+ end
128
+
129
+ a = LD4L::OreRDF::AggregationResource.new(ActiveTriples::LocalName::Minter.generate_local_name(
130
+ LD4L::OreRDF::AggregationResource, 10, 'ag',
131
+ &LD4L::OreRDF.configuration.localname_minter ))
132
+
133
+ puts a.dump :ttl
134
+ ```
135
+ NOTE: If base_uri is not used, you need to restart your interactive environment (e.g. irb, pry). Once the
136
+ Aggregation class is instantiated the first time, the base_uri for the class is set. If you ran
137
+ through the main Examples, the base_uri was set to the default base_uri.
138
+
139
+
140
+ *Example triples created for an aggregation with configured base_uri and configured minter.*
141
+ ```
142
+ <http://example.org/ag_configured_6498ba05-8b21-4e8c-b9d4-a6d5d2180966> a <http://www.openarchives.org/ore/terms/Aggregation> .
143
+ ```
144
+
145
+
146
+ ### Models
147
+
148
+ The LD4L::OreRDF gem provides model definitions using the
149
+ [ActiveTriples](https://github.com/ActiveTriples/ActiveTriples) framework extension of
150
+ [ruby-rdf/rdf](https://github.com/ruby-rdf/rdf). The following models are provided:
151
+
152
+ 1. LD4L::OreRDF::AggregationResource - Implements the Aggregation class in the ORE ontology.
153
+ 1. LD4L::OreRDF::ProxyResource - Implements the Proxy class in the ORE ontology.
154
+
155
+ ### Ontologies
156
+
157
+ The listed ontologies are used to represent the primary metadata about aggregation lists.
158
+ Other ontologies may also be used that aren't listed.
159
+
160
+ * [ORE](http://www.openarchives.org/ore/1.0/vocabulary)
161
+ * [FOAF](http://xmlns.com/foaf/spec/)
162
+ * [RDF](http://www.w3.org/TR/rdf-syntax-grammar/)
163
+
164
+
165
+ ## Contributing
166
+
167
+ 1. Fork it ( https://github.com/[my-github-username]/ld4l-ore_rdf/fork )
168
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
169
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
170
+ 4. Push to the branch (`git push origin my-new-feature`)
171
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,45 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ld4l/ore_rdf/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ld4l-ore_rdf"
8
+ spec.version = LD4L::OreRDF::VERSION
9
+ spec.authors = ["E. Lynette Rayle"]
10
+ spec.email = ["elr37@cornell.edu"]
11
+ spec.platform = Gem::Platform::RUBY
12
+ spec.summary = %q{ORE RDF models.}
13
+ spec.description = %q{LD4L ORE RDF provides tools for modeling list triples based on the ORE ontology and persisting to a triplestore.}
14
+ spec.homepage = "https://github.com/ld4l/ore_rdf"
15
+ spec.license = "APACHE2"
16
+ spec.required_ruby_version = '>= 1.9.3'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ # spec.test_files = `git ls-files -- {spec}/*`.split("\n") # FROM ActiveTriples gemspec file
21
+ # spec.require_paths = ["lib"] # NOT IN ActiveTriples gemspec file
22
+
23
+ # spec.add_dependency('ffi', '~> 1.9.5')
24
+ spec.add_dependency('rdf', '~> 1.1')
25
+
26
+ spec.add_dependency('active-triples', '~> 0.5')
27
+ spec.add_dependency('active_triples-local_name', '~> 0.1')
28
+ spec.add_dependency('ld4l-foaf_rdf', '~> 0.0')
29
+ spec.add_dependency('doubly_linked_list', '~> 0.0')
30
+
31
+ spec.add_development_dependency('pry')
32
+ # spec.add_development_dependency('pry-byebug') # Works with ruby > 2
33
+ # spec.add_development_dependency('pry-debugger') # Works with ruby < 2
34
+ spec.add_development_dependency('rdoc')
35
+ spec.add_development_dependency('rspec')
36
+ spec.add_development_dependency('coveralls')
37
+ spec.add_development_dependency('guard-rspec')
38
+ spec.add_development_dependency('webmock')
39
+
40
+ spec.extra_rdoc_files = [
41
+ "LICENSE.txt",
42
+ "README.md"
43
+ ]
44
+ end
45
+
@@ -0,0 +1,41 @@
1
+ module LD4L
2
+ module OreRDF
3
+ class Configuration
4
+
5
+ attr_reader :base_uri
6
+ attr_reader :localname_minter
7
+
8
+ def self.default_base_uri
9
+ @default_base_uri = "http://localhost/".freeze
10
+ end
11
+ private_class_method :default_base_uri
12
+
13
+ def self.default_localname_minter
14
+ # by setting to nil, it will use the default minter in the minter gem
15
+ @default_localname_minter = nil
16
+ end
17
+ private_class_method :default_localname_minter
18
+
19
+ def initialize
20
+ @base_uri = self.class.send(:default_base_uri)
21
+ @localname_minter = self.class.send(:default_localname_minter)
22
+ end
23
+
24
+ def base_uri=(new_base_uri)
25
+ @base_uri = new_base_uri
26
+ end
27
+
28
+ def reset_base_uri
29
+ @base_uri = self.class.send(:default_base_uri)
30
+ end
31
+
32
+ def localname_minter=(new_minter)
33
+ @localname_minter = new_minter
34
+ end
35
+
36
+ def reset_localname_minter
37
+ @localname_minter = self.class.send(:default_localname_minter)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,50 @@
1
+ require 'active_model'
2
+ module LD4L
3
+ module OreRDF
4
+ class Aggregation < DoublyLinkedList
5
+
6
+ def self.initialize
7
+ super
8
+ end
9
+
10
+ def initialize(*args)
11
+ new_args = args[0].dup unless args.empty?
12
+ unless args.empty?
13
+ new_args[:items] = new_args[:proxy_resources] if new_args.is_a?(Hash) && new_args.key?(:proxy_resources)
14
+ new_args[:list_info] = new_args[:aggregation_resource] if new_args.is_a?(Hash) && new_args.key?(:aggregation_resource)
15
+ new_args.delete(:proxy_resources)
16
+ new_args.delete(:aggregation_resource)
17
+ end
18
+ super(new_args)
19
+ end
20
+
21
+ def id
22
+ list_info.rdf_subject.to_s
23
+ end
24
+
25
+ def title
26
+ titles = list_info.title
27
+ titles.kind_of?(Array) && titles.size > 0 ? titles[0] : ""
28
+ end
29
+
30
+ def description
31
+ descriptions = list_info.description
32
+ descriptions.kind_of?(Array) && descriptions.size > 0 ? descriptions[0] : ""
33
+ end
34
+
35
+ def aggregation_resource
36
+ list_info
37
+ end
38
+
39
+ def proxy_resources
40
+ @list
41
+ end
42
+
43
+ # def self.model_name
44
+ # ActiveModel::Name.new(LD4L::OreRDF::Aggregation)
45
+ # end
46
+
47
+ end
48
+ end
49
+ end
50
+
@@ -0,0 +1,98 @@
1
+ module LD4L
2
+ module OreRDF
3
+ class AggregationResource < ActiveTriples::Resource
4
+
5
+ class << self; attr_reader :localname_prefix end
6
+ @localname_prefix="ag"
7
+
8
+ # TODO... Can we change type from Set to List to go from unordered list to ordered list?
9
+ # TODO Should properties for ordered lists be blocked until the list is turned into an ordered list?
10
+ # TODO Can you go from an ordered list back to an unordered list?
11
+ # TODO Can you apply order to only parts of the list, or does applying order imply all items are now ordered?
12
+ # TODO If all items are now ordered, what is the process for going through all subitems and adding order information?
13
+
14
+
15
+ # TODO... items are not persisted when this class is persisted because there is not connection from this class to the items
16
+ # TODO Either the persist! method needs to be overridden to also save the items (which would also require an items attribute to hold them)
17
+ # TODO OR the item property needs to be uncommented allowing the built in functionality to save them.
18
+ # TODO DOWNSIDE: items and aggregators could get out of sync. Then which is right? Could be a problem with the first option too.
19
+
20
+
21
+ configure :type => RDFVocabularies::ORE.Aggregation, :base_uri => LD4L::OreRDF.configuration.base_uri, :repository => :default
22
+
23
+ # extended properties for LD4L implementation
24
+ property :title, :predicate => RDF::DC.title
25
+ property :description, :predicate => RDF::DC.description
26
+ property :owner, :predicate => RDFVocabularies::DCTERMS.creator, :class_name => LD4L::FoafRDF::Person
27
+
28
+ # properties from ORE.Aggregation
29
+ property :aggregates, :predicate => RDFVocabularies::ORE.aggregates # multiple values
30
+ property :first_proxy, :predicate => RDFVocabularies::IANA.first, :class_name => LD4L::OreRDF::ProxyResource
31
+ property :last_proxy, :predicate => RDFVocabularies::IANA.last, :class_name => LD4L::OreRDF::ProxyResource
32
+
33
+
34
+ # --------------------- #
35
+ # HELPER METHODS #
36
+ # --------------------- #
37
+
38
+
39
+ ########### NEED TO MOVE TO SERVICE OBJECT ####################
40
+
41
+
42
+ # Returns an array the items in the aggregation.
43
+ # TODO: How to begin at start and limit to number of returned items, effectively handling ranges of data.
44
+ def get_items_content(start=nil,limit=nil)
45
+ # TODO: Stubbed to return all items.
46
+ get_values('aggregates')
47
+ end
48
+
49
+ # Returns an array of persisted LD4L::OreRDF::ProxyResource instances for the items in the`` aggregation.
50
+ def get_items(start=nil,limit=nil)
51
+ LD4L::OreRDF::ProxyResource.get_range(self, start, limit)
52
+ end
53
+
54
+ # Get the persisted LD4L::OreRDF::ProxyResource instance that holds the content
55
+ # NOTE: Not implemented.
56
+ def find_item_with_content(content)
57
+ # TODO Stubbed - Requires definition and implementation
58
+ end
59
+
60
+ # Return the content at the specified position in an ordered collection
61
+ def get_item_content_at(position)
62
+ # TODO Stubbed - Required definition and implementation
63
+ end
64
+
65
+ # Return the LD4L::OreRDF::ProxyResource instance for the item at the specified position in an ordered collection
66
+ def get_item_at(position)
67
+ # TODO Stubbed - Required definition and implementation
68
+ end
69
+
70
+ # Determine if the content is already in the aggregation
71
+ def has_item_content?(content)
72
+ # TODO Stubbed - Requires definition and implementation
73
+ end
74
+
75
+ # Determine if an item exists at the specified position in the ordered aggregation
76
+ def has_item_at?(position)
77
+ # TODO Stubbed - Requires definition and implementation
78
+ end
79
+
80
+ # Destroy the item with the content and remove content from the aggregation
81
+ def destroy_item_with_content(content)
82
+ # TODO Stubbed - Requires definition and implementation
83
+ end
84
+
85
+ # Destroy the item at specified position and remove content from the aggregation
86
+ def destroy_item_at(position)
87
+ # TODO Stubbed - Requires definition and implementation
88
+ end
89
+
90
+ # Determine if the aggregation holds an ordered list of items
91
+ def is_ordered?
92
+ # TODO Stubbed to always return false until ordered lists are implemented
93
+ return false
94
+ end
95
+ end
96
+ end
97
+ end
98
+