ld4l-ore_rdf 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e31d9fd5075fcc5d9ca073e2edc850521ff7c2c
4
- data.tar.gz: 54e5d4ff97cb4440f19134f7aac22531985ab5c9
3
+ metadata.gz: 650e31b76de505d43da11cb67a96f9bf3013f5bf
4
+ data.tar.gz: 64e3f97cb4eef3aa5c9d5a7df26483f4e3b4a16f
5
5
  SHA512:
6
- metadata.gz: 7afdc0e5c94bc9f31e9ad2129eeb65be6d81fbf1ad8d0441c84169960017eff94f4d3296cd7a5797671318c8412d306145a88cb389eff04d81f1635524cf7b93
7
- data.tar.gz: 0f2f08759d02ce86969a0c3b98438f007ee1d343986b5417e9931450a32049f8934cac981142906450b68a7bc5952a6852d9e11ae6bb4a92c11830183a896806
6
+ metadata.gz: 31ada8c13d62de9c533d8719db93008dfa3204d41786c972b5de28c9678515ddcb6b486eccafdcb7288b8ce7364993adc25545a871c86fc08c7952636d1dab5e
7
+ data.tar.gz: 05561fe6b9a47f0ce9ce441ecbd738a16c952cc5165a8e18e49b0d7c8a5b8e4e7cecb5dfd5c968f0346b543bc3fc381f6f9375351fe192dace8834c9b1001580
@@ -1,12 +1,14 @@
1
1
  language: ruby
2
2
  bundler_args: --without debug
3
3
  script: "bundle exec rspec spec"
4
+ sudo: false
5
+ cache: bundler
4
6
  rvm:
5
- - 1.9.3
6
- - 2.0.0
7
- - 2.1.0
8
- - 2.1.1
9
- - jruby-19mode
7
+ - 2.2.4
8
+ - 2.3.0
9
+ - jruby-9.0.4.0
10
+ - rbx-2
10
11
  matrix:
11
12
  allow_failures:
12
- - rvm: jruby-19mode
13
+ - rvm: jruby-9.0.4.0
14
+ - rvm: rbx-2
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ 0.2.0
2
+ -----
3
+ * Add ability to write to solr index from PersistAggregation service
4
+
1
5
  0.1.0
2
6
  -----
3
7
  * Updated to work with ActiveTriples 0.5, 0.6, and 0.8.2
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ gem 'active-triples', :github => 'ActiveTriples/ActiveTriples', :branch => 'fix206_exclude_othersubj_preds'
data/README.md CHANGED
@@ -42,6 +42,12 @@ require 'ld4l/ore_rdf'
42
42
  # create an in-memory repository
43
43
  ActiveTriples::Repositories.add_repository :default, RDF::Repository.new
44
44
 
45
+ # configure the solr url
46
+ ActiveTriples::Solrizer.configure do |config|
47
+ config.solr_uri = "http://localhost:8983/solr/#/~cores/active_triples"
48
+ end
49
+
50
+
45
51
  p = LD4L::FoafRDF::Person.new('p4')
46
52
  ```
47
53
 
@@ -20,10 +20,11 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency('rdf', '= 1.99.0')
22
22
 
23
- spec.add_dependency('active-triples', '~> 0.5', '~> 0.6', '~>0.8.2')
24
- spec.add_dependency('active_triples-local_name', '~> 0.1')
25
- spec.add_dependency('ld4l-foaf_rdf', '~> 0.0')
26
- spec.add_dependency('doubly_linked_list', '~> 0.0')
23
+ spec.add_dependency('active-triples')
24
+ spec.add_dependency('active_triples-local_name')
25
+ spec.add_dependency('active_triples-solrizer')
26
+ spec.add_dependency('ld4l-foaf_rdf')
27
+ spec.add_dependency('doubly_linked_list')
27
28
 
28
29
  spec.add_development_dependency('pry')
29
30
  spec.add_development_dependency('pry-byebug')
@@ -1,6 +1,7 @@
1
1
  require 'rdf'
2
2
  require 'active_triples'
3
3
  require 'active_triples/local_name'
4
+ require 'active_triples/solrizer'
4
5
  require 'linkeddata'
5
6
  require 'doubly_linked_list'
6
7
  require 'ld4l/foaf_rdf'
@@ -48,6 +49,7 @@ module LD4L
48
49
  autoload :CreateAggregation, 'ld4l/ore_rdf/services/aggregation/create'
49
50
  autoload :PersistAggregation, 'ld4l/ore_rdf/services/aggregation/persist'
50
51
  autoload :ResumeAggregation, 'ld4l/ore_rdf/services/aggregation/resume'
52
+ autoload :LoadAggregationFromSolr,'ld4l/ore_rdf/services/aggregation/load_from_solr'
51
53
  autoload :DestroyAggregation, 'ld4l/ore_rdf/services/aggregation/destroy'
52
54
  autoload :FindAggregations, 'ld4l/ore_rdf/services/aggregation/find'
53
55
  autoload :AddAggregatedResource, 'ld4l/ore_rdf/services/aggregation/add_aggregated_resource'
@@ -55,22 +57,6 @@ module LD4L
55
57
 
56
58
  autoload :CreateProxy, 'ld4l/ore_rdf/services/proxy/create'
57
59
  autoload :FindProxies, 'ld4l/ore_rdf/services/proxy/find'
58
-
59
- def self.class_from_string(class_name, container_class=Kernel)
60
- container_class = container_class.name if container_class.is_a? Module
61
- container_parts = container_class.split('::')
62
- (container_parts + class_name.split('::')).flatten.inject(Kernel) do |mod, class_name|
63
- if mod == Kernel
64
- Object.const_get(class_name)
65
- elsif mod.const_defined? class_name.to_sym
66
- mod.const_get(class_name)
67
- else
68
- container_parts.pop
69
- class_from_string(class_name, container_parts.join('::'))
70
- end
71
- end
72
- end
73
-
74
60
  end
75
61
  end
76
62
 
@@ -3,36 +3,36 @@ module LD4L
3
3
  module OreRDF
4
4
  class Aggregation < DoublyLinkedList
5
5
 
6
- @@clear_first_callback = lambda { |aggregation| aggregation.first_proxy = [] }
7
- @@clear_last_callback = lambda { |aggregation| aggregation.last_proxy = [] }
6
+ @@clear_first_callback = lambda { |aggregation| aggregation.first_proxy = nil }
7
+ @@clear_last_callback = lambda { |aggregation| aggregation.last_proxy = nil }
8
8
  @@update_first_callback = lambda { |aggregation, proxies| aggregation.first_proxy = proxies.first }
9
9
  @@update_last_callback = lambda { |aggregation, proxies| aggregation.last_proxy = proxies.last }
10
10
 
11
- @@clear_next_callback = lambda { |proxies, idx| proxies[idx].next_proxy = [] }
12
- @@clear_prev_callback = lambda { |proxies, idx| proxies[idx].prev_proxy = [] }
11
+ @@clear_next_callback = lambda { |proxies, idx| proxies[idx].next_proxy = nil }
12
+ @@clear_prev_callback = lambda { |proxies, idx| proxies[idx].prev_proxy = nil }
13
13
  @@update_next_callback = lambda { |proxies, idx| proxies[idx].next_proxy = proxies[idx+1] }
14
14
  @@update_prev_callback = lambda { |proxies, idx| proxies[idx].prev_proxy = proxies[idx-1] }
15
15
 
16
16
  @@find_first_callback = lambda do |aggregation, proxies|
17
17
  first_proxy = aggregation.first_proxy
18
- return first_proxy.first if first_proxy && !first_proxy.empty?
18
+ return first_proxy unless first_proxy.nil?
19
19
 
20
20
  # if first isn't set, try to figure out first by looking for an item with prev_proxy == nil
21
21
  # NOTE: If multiple items have prev_proxy == nil, it will return the first one it finds.
22
- first_idx = proxies.index { |proxy| proxy.prev_proxy == [] }
22
+ first_idx = proxies.index { |proxy| proxy.prev_proxy.nil? }
23
23
  first_idx ? proxies[first_idx] : nil
24
24
  end
25
25
  @@find_last_callback = lambda do |aggregation, proxies|
26
26
  last_proxy = aggregation.last_proxy
27
- return last_proxy.first if last_proxy && !last_proxy.empty?
27
+ return last_proxy unless last_proxy.nil?
28
28
 
29
29
  # if last isn't set, try to figure out last by looking for an item with next_proxy == nil
30
30
  # NOTE: If multiple items have next_proxy == nil, it will return the first one it finds.
31
- last_idx = proxies.index { |proxy| proxy.next_proxy == [] }
31
+ last_idx = proxies.index { |proxy| proxy.next_proxy.nil? }
32
32
  last_idx ? proxies[last_idx] : nil
33
33
  end
34
- @@find_next_callback = lambda { |proxies, current_proxy| current_proxy.next_proxy.first }
35
- @@find_prev_callback = lambda { |proxies, current_proxy| current_proxy.prev_proxy.first }
34
+ @@find_next_callback = lambda { |proxies, current_proxy| current_proxy.next_proxy }
35
+ @@find_prev_callback = lambda { |proxies, current_proxy| current_proxy.prev_proxy }
36
36
 
37
37
 
38
38
  def self.initialize
@@ -74,24 +74,14 @@ module LD4L
74
74
 
75
75
  def title
76
76
  titles = list_info.title
77
- title = ""
78
- if list_info.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8
79
- title = titles.first if titles.kind_of?(ActiveTriples::Relation) && titles.size > 0
80
- else # < ActiveTriples 0.8
81
- title = titles.first if titles.kind_of?(Array) && titles.size > 0
82
- end
83
- title
77
+ titles = titles.to_a if Object::ActiveTriples.const_defined?("Relation") && titles.kind_of?(ActiveTriples::Relation)
78
+ titles.kind_of?(Array) && titles.size > 0 ? titles.first : ""
84
79
  end
85
80
 
86
81
  def description
87
82
  descriptions = list_info.description
88
- description = ""
89
- if list_info.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8
90
- description = descriptions.first if descriptions.kind_of?(ActiveTriples::Relation) && descriptions.size > 0
91
- else # < ActiveTriples 0.8
92
- description = descriptions.first if descriptions.kind_of?(Array) && descriptions.size > 0
93
- end
94
- description
83
+ descriptions = descriptions.to_a if Object::ActiveTriples.const_defined?("Relation") && descriptions.kind_of?(ActiveTriples::Relation)
84
+ descriptions.kind_of?(Array) && descriptions.size > 0 ? descriptions.first : ""
95
85
  end
96
86
 
97
87
  def aggregation_resource
@@ -106,6 +96,15 @@ module LD4L
106
96
  # ActiveModel::Name.new(LD4L::OreRDF::Aggregation)
107
97
  # end
108
98
 
99
+ private
100
+ def self.get_first_value source, value, as_subject=false
101
+ val = value
102
+ val = val.to_a if Object::ActiveTriples.const_defined?("Relation") && val.kind_of?(ActiveTriples::Relation)
103
+ return nil if val.nil? || val.size <= 0
104
+ val = val.first if val.is_a? Array
105
+ val = val.rdf_subject.to_s if as_subject && (val.is_a? ActiveTriples::Resource)
106
+ val
107
+ end
109
108
  end
110
109
  end
111
110
  end
@@ -21,14 +21,53 @@ module LD4L
21
21
  configure :type => RDFVocabularies::ORE.Aggregation, :base_uri => LD4L::OreRDF.configuration.base_uri, :repository => :default
22
22
 
23
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
24
+ property :title, :predicate => RDF::DC.title do |index|
25
+ index.data_type = :text
26
+ index.as :indexed, :sortable
27
+ end
28
+ property :description, :predicate => RDF::DC.description do |index|
29
+ index.data_type = :text
30
+ index.as :indexed
31
+ end
32
+ property :owner, :predicate => RDFVocabularies::DCTERMS.creator, :class_name => LD4L::FoafRDF::Person do |index|
33
+ index.data_type = :string
34
+ index.as :stored, :indexed
35
+ end
27
36
 
28
37
  # properties from ORE.Aggregation
29
- property :aggregates, :predicate => RDFVocabularies::ORE.aggregates, :cast => false # 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
38
+ property :aggregates, :predicate => RDFVocabularies::ORE.aggregates, :cast => false do |index|
39
+ index.data_type = :text
40
+ index.as :stored, :indexed, :multiValued
41
+ end
42
+ property :first_proxy_, :predicate => RDFVocabularies::IANA.first, :class_name => LD4L::OreRDF::ProxyResource
43
+ property :last_proxy_, :predicate => RDFVocabularies::IANA.last, :class_name => LD4L::OreRDF::ProxyResource
44
+
45
+
46
+ def first_proxy= value
47
+ value = [] if value.nil?
48
+ self.first_proxy_ = value
49
+ end
50
+
51
+ def first_proxy
52
+ OreRDF::Aggregation.get_first_value self, first_proxy_
53
+ end
54
+
55
+ def first_proxy_subject
56
+ OreRDF::Aggregation.get_first_value self, first_proxy_, true
57
+ end
58
+
59
+ def last_proxy= value
60
+ value = [] if value.nil?
61
+ self.last_proxy_ = value
62
+ end
63
+
64
+ def last_proxy
65
+ OreRDF::Aggregation.get_first_value self, last_proxy_
66
+ end
67
+
68
+ def last_proxy_subject
69
+ OreRDF::Aggregation.get_first_value self, last_proxy_, true
70
+ end
32
71
 
33
72
 
34
73
  # --------------------- #
@@ -92,7 +131,35 @@ module LD4L
92
131
  # TODO Stubbed to always return false until ordered lists are implemented
93
132
  return false
94
133
  end
134
+
135
+ ##
136
+ # Generate the solr document hash specific to a aggregation resource.
137
+ #
138
+ # @param [Array<LD4L::OreRDF::ProxyResource>] :all_proxies - pass in proxies instead of querying (optional)
139
+ #
140
+ # @returns [Hash] solr document
141
+ #
142
+ # NOTE: If all_proxies is [], then will try to query from triple store which means that if the proxies have not
143
+ # yet been persisted, then they will not be found.
144
+ # NOTE: This method should not be called directory. Use LD4L::OreRDF::Aggregation.generate_solr_documents instead.
145
+ def generate_solr_document( all_proxies=[] )
146
+ solr_doc = ActiveTriples::Solrizer::IndexingService.new(self).generate_solr_document do |solr_doc|
147
+ # TODO add owner_name and owner sort field
148
+ # solr_doc.merge!(:owner_name_ti => owner.name) # TODO add name to FOAF Gem
149
+ # solr_doc.merge!(:owner_name_sort_ss => owner.name)
150
+
151
+ # add all item_proxies
152
+ all_proxies = get_items if all_proxies.empty? # NOTE: get_items depends on aggregation_resource being persisted prior to this call
153
+ proxy_ids = all_proxies.collect { |item| item.id }
154
+ solr_doc.merge!(self.class.item_proxies_solr_name => proxy_ids)
155
+ solr_doc
156
+ end
157
+ solr_doc
158
+ end
159
+
160
+ def self.item_proxies_solr_name
161
+ :item_proxies_ssm
162
+ end
95
163
  end
96
164
  end
97
165
  end
98
-
@@ -8,11 +8,64 @@ module LD4L
8
8
  # configure :base_uri => LD4L::OreRDF.configuration.base_uri, repository => :default
9
9
  configure :type => RDFVocabularies::ORE.Proxy, :base_uri => LD4L::OreRDF.configuration.base_uri, :repository => :default
10
10
 
11
- property :proxy_for, :predicate => RDFVocabularies::ORE.proxyFor, :cast => false
12
- property :proxy_in, :predicate => RDFVocabularies::ORE.proxyIn, :class_name => LD4L::OreRDF::AggregationResource
13
- property :next_proxy, :predicate => RDFVocabularies::IANA.next, :class_name => LD4L::OreRDF::ProxyResource
14
- property :prev_proxy, :predicate => RDFVocabularies::IANA.prev, :class_name => LD4L::OreRDF::ProxyResource
15
- property :contributor, :predicate => RDF::DC.contributor, :class_name => LD4L::FoafRDF::Person # TODO User who added this item to the Aggregation (default=Aggregation's owner)
11
+ property :proxy_for_, :predicate => RDFVocabularies::ORE.proxyFor, :cast => false
12
+ property :proxy_in_, :predicate => RDFVocabularies::ORE.proxyIn, :class_name => LD4L::OreRDF::AggregationResource
13
+ property :next_proxy_, :predicate => RDFVocabularies::IANA.next, :class_name => LD4L::OreRDF::ProxyResource
14
+ property :prev_proxy_, :predicate => RDFVocabularies::IANA.prev, :class_name => LD4L::OreRDF::ProxyResource
15
+ property :contributor, :predicate => RDF::DC.contributor, :class_name => LD4L::FoafRDF::Person # TODO User who added this item to the Aggregation (default=Aggregation's owner)
16
+
17
+
18
+ def proxy_for= value
19
+ value = [] if value.nil?
20
+ self.proxy_for_ = value
21
+ end
22
+
23
+ def proxy_for
24
+ OreRDF::Aggregation.get_first_value self, proxy_for_
25
+ end
26
+
27
+ def proxy_for_subject
28
+ OreRDF::Aggregation.get_first_value self, proxy_for_, true
29
+ end
30
+
31
+ def proxy_in= value
32
+ value = [] if value.nil?
33
+ self.proxy_in_ = value
34
+ end
35
+
36
+ def proxy_in
37
+ OreRDF::Aggregation.get_first_value self, proxy_in_
38
+ end
39
+
40
+ def proxy_in_subject
41
+ OreRDF::Aggregation.get_first_value self, proxy_in_, true
42
+ end
43
+
44
+ def next_proxy= value
45
+ self.next_proxy_ = value
46
+ value = [] if value.nil?
47
+ end
48
+
49
+ def next_proxy
50
+ OreRDF::Aggregation.get_first_value self, next_proxy_
51
+ end
52
+
53
+ def next_proxy_subject
54
+ OreRDF::Aggregation.get_first_value self, next_proxy_, true
55
+ end
56
+
57
+ def prev_proxy= value
58
+ value = [] if value.nil?
59
+ self.prev_proxy_ = value
60
+ end
61
+
62
+ def prev_proxy
63
+ OreRDF::Aggregation.get_first_value self, prev_proxy_
64
+ end
65
+
66
+ def prev_proxy_subject
67
+ OreRDF::Aggregation.get_first_value self, prev_proxy_, true
68
+ end
16
69
 
17
70
 
18
71
  # --------------------- #
@@ -28,15 +81,17 @@ module LD4L
28
81
  def self.get_range( aggregation, start=0, limit=nil )
29
82
  # TODO: Stubbed to return all items. Need to implement start and limit features.
30
83
 
31
- # argument validation
32
- # raise ArgumentError, 'Argument must be a string with at least one character' unless
33
- # tag_value.kind_of?(String) && tag_value.size > 0
84
+ raise ArgumentError, 'aggregation must be Aggregation or AggregationResource' unless
85
+ aggregation.kind_of?(LD4L::OreRDF::Aggregation) || aggregation.kind_of?(LD4L::OreRDF::AggregationResource)
86
+
87
+ aggregation_resource = aggregation
88
+ aggregation_resource = aggregation.list_info if aggregation.kind_of?(LD4L::OreRDF::Aggregation)
34
89
 
35
90
  graph = ActiveTriples::Repositories.repositories[repository]
36
91
  query = RDF::Query.new({
37
92
  :proxy => {
38
93
  RDF.type => RDFVocabularies::ORE.Proxy,
39
- RDFVocabularies::ORE.proxyIn => aggregation,
94
+ RDFVocabularies::ORE.proxyIn => aggregation_resource,
40
95
  }
41
96
  })
42
97
 
@@ -44,8 +99,8 @@ module LD4L
44
99
  results = query.execute(graph)
45
100
  results.each do |r|
46
101
  proxy_uri = r.to_hash[:proxy]
47
- if aggregation.list_info.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8
48
- proxy = LD4L::OreRDF::ProxyResource.new(proxy_uri,aggregation.list_info)
102
+ if aggregation_resource.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8
103
+ proxy = LD4L::OreRDF::ProxyResource.new(proxy_uri,aggregation_resource)
49
104
  else # < ActiveTriples 0.8
50
105
  proxy = LD4L::OreRDF::ProxyResource.new(proxy_uri)
51
106
  end
@@ -23,27 +23,19 @@ module LD4L
23
23
  resource.kind_of?(String) || resource.kind_of?(RDF::URI)
24
24
 
25
25
  # make sure resource is a String - HANGING ERROR will occur if set as RDF::URI
26
- resource = resource.to_s if resource.kind_of?(RDF::URI)
26
+ resource = resource.to_s if resource.kind_of?(RDF::URI)
27
27
 
28
28
  # validate aggregation is of correct type
29
29
  raise ArgumentError, "aggregation is not LD4L::OreRDF::Aggregation" unless
30
30
  aggregation.kind_of?(LD4L::OreRDF::Aggregation)
31
31
 
32
-
33
- # aggregates = get_values('aggregates')
34
- # aggregates << resource_uri
35
- # set_value('aggregates',aggregates)
36
-
37
- aggregates = aggregation.aggregates.dup
38
- aggregates << resource
39
- aggregation.aggregates = aggregates
32
+ aggregation.aggregates << resource
40
33
 
41
34
  LD4L::OreRDF::CreateProxy.call(
42
35
  :resource => resource,
43
36
  :aggregation => aggregation,
44
37
  :insert_position => insert_position)
45
38
  end
46
-
47
39
  end
48
40
  end
49
41
  end
@@ -19,8 +19,8 @@ module LD4L
19
19
  # all_aggs = LD4L::OreRDF.FindAggregations
20
20
  def self.call( options={} )
21
21
  repository = options[:repository] || :default
22
- raise ArgumentError, 'repository must be a symbol' unless repository.kind_of?(Symbol)
23
- raise ArgumentError, 'repository must be a registered repository' unless
22
+ raise ArgumentError, "repository (#{repository}) is not a symbol" unless repository.kind_of?(Symbol)
23
+ raise ArgumentError, "repository (#{repository}) is not a registered repository" unless
24
24
  ActiveTriples::Repositories.repositories.has_key?(repository)
25
25
 
26
26
  resume = options[:resume] || false