tripod 0.10.6 → 0.10.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de26dbd697bf235132169fcd79cd217f12703968
4
- data.tar.gz: 51f05ee55133a0efdb7fc818721e6fab2992b994
3
+ metadata.gz: 28357534b22227c55bd266ea70d5ef438876e164
4
+ data.tar.gz: b1cca62a80cc3d792a78347df41b5291ae79a9ab
5
5
  SHA512:
6
- metadata.gz: dc24de2078906bcbef21306de4803fff5792b6be1f124a8ce543b8269edddc0b85623f51634211b92a0d8fddc52b2f2fe71c9e42af73076c880eac18fc6522a0
7
- data.tar.gz: 568716881b92d6d8b0c31380a45235afaebc04694b130c6f7340a55f592601a8de90c5493746d8e51d67c46ebdd005d7858316f3c6a864e15df3af332f02a098
6
+ metadata.gz: 23a8ac7dfb43dc3350b06f8f14f4b4dfeba832927d6e0a690dec71b1136204919c66d7bd1fdaca18b2bf60b421684363e0120a732fbac41bcd1f4ec82b6437fd
7
+ data.tar.gz: 464e6b785fbe6522e118cc6874b881474c9ace312b97e0adfc689ae2b56575352a4abffdbec7ddadc857e6b52320f584afddff409aa151572872bfdd906d0bf5
data/lib/tripod.rb CHANGED
@@ -93,7 +93,6 @@ require "tripod/predicates"
93
93
  require "tripod/attributes"
94
94
  require "tripod/callbacks"
95
95
  require "tripod/validations/is_url"
96
- require "tripod/rdf_type"
97
96
  require "tripod/errors"
98
97
  require "tripod/repository"
99
98
  require "tripod/fields"
@@ -105,9 +104,6 @@ require "tripod/eager_loading"
105
104
  require "tripod/serialization"
106
105
  require "tripod/state"
107
106
  require "tripod/graphs"
108
- require "tripod/embeds"
109
- require "tripod/embeds/many"
110
- require "tripod/embedded_resource"
111
107
  require "tripod/version"
112
108
 
113
109
  # these need to be at the end
@@ -17,11 +17,9 @@ module Tripod::Components
17
17
  include Tripod::Attributes
18
18
  include Tripod::Callbacks
19
19
  include Tripod::Validations
20
- include Tripod::RdfType
21
20
  include Tripod::Persistence
22
21
  include Tripod::Fields
23
22
  include Tripod::Links
24
- include Tripod::Embeds
25
23
  include Tripod::Finders
26
24
  include Tripod::Repository
27
25
  include Tripod::EagerLoading
@@ -109,7 +109,7 @@ module Tripod::Finders
109
109
  uris_sparql_str = uris.map{ |u| "<#{u.to_s}>" }.join(" ")
110
110
 
111
111
  # Do a big describe statement, and read the results into an in-memory repo
112
- ntriples_string = Tripod::SparqlClient::Query.query("CONSTRUCT { ?s ?p ?o } WHERE { VALUES ?s { #{uris_sparql_str} } ?s ?p ?o . }", "application/n-triples")
112
+ ntriples_string = Tripod::SparqlClient::Query.query("CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o . VALUES ?s { #{uris_sparql_str} } }", "application/n-triples")
113
113
  graph = _rdf_graph_from_ntriples_string(ntriples_string, graph)
114
114
  end
115
115
 
@@ -172,20 +172,16 @@ module Tripod::Finders
172
172
  def _describe_query_for_select(select_sparql, opts={})
173
173
  uri_variable = opts[:uri_variable] || "uri"
174
174
  "
175
- CONSTRUCT {
176
- ?tripod_construct_s ?tripod_construct_p ?tripod_construct_o .
177
- # ?tripod_construct_o ?tripod_construct_ep ?tripod_construct_eo .
178
- }
179
- WHERE {
180
- {
181
- SELECT (?#{uri_variable} as ?tripod_construct_s)
175
+ CONSTRUCT { ?tripod_construct_s ?tripod_construct_p ?tripod_construct_o }
176
+ WHERE {
177
+ ?tripod_construct_s ?tripod_construct_p ?tripod_construct_o .
182
178
  {
183
- #{select_sparql}
179
+ SELECT (?#{uri_variable} as ?tripod_construct_s)
180
+ {
181
+ #{select_sparql}
182
+ }
184
183
  }
185
- }
186
- ?tripod_construct_s ?tripod_construct_p ?tripod_construct_o .
187
- # OPTIONAL { ?tripod_construct_o ?tripod_construct_ep ?tripod_construct_eo . }
188
- }
184
+ }
189
185
  "
190
186
  end
191
187
 
@@ -220,10 +216,6 @@ module Tripod::Finders
220
216
  data_graph = RDF::Graph.new
221
217
  repo.query( [RDF::URI.new(u), :predicate, :object] ) do |statement|
222
218
  data_graph << statement
223
-
224
- if statement.object.is_a? RDF::Node
225
- repo.query( [statement.object, :predicate, :object] ) {|s| data_graph << s}
226
- end
227
219
  end
228
220
 
229
221
  # use it to hydrate this resource
@@ -56,7 +56,11 @@ module Tripod::Repository
56
56
  end
57
57
 
58
58
  def retrieve_triples_from_database(accept_header="application/n-triples")
59
- Tripod::SparqlClient::Query.query(self.class.all_triples_query(uri, graph_uri: self.graph_uri), accept_header)
59
+ graph_selector = self.graph_uri.present? ? "<#{graph_uri.to_s}>" : "?g"
60
+ Tripod::SparqlClient::Query.query(
61
+ "CONSTRUCT {<#{uri}> ?p ?o} WHERE { GRAPH #{graph_selector} { <#{uri}> ?p ?o } }",
62
+ accept_header
63
+ )
60
64
  end
61
65
 
62
66
  # returns a graph of triples from the underlying repository where this resource's uri is the subject.
@@ -83,12 +87,6 @@ module Tripod::Repository
83
87
  repo
84
88
  end
85
89
 
86
- def all_triples_query(uri, opts={})
87
- graph_uri = opts.fetch(:graph_uri, nil)
88
- graph_selector = graph_uri.present? ? "<#{graph_uri.to_s}>" : "?g"
89
- "CONSTRUCT {<#{uri}> ?p ?o . ?o ?ep ?eo . } WHERE { GRAPH #{graph_selector} { <#{uri}> ?p ?o . OPTIONAL { ?o ?ep ?eo } } }"
90
- end
91
-
92
90
  end
93
91
 
94
- end
92
+ end
@@ -13,6 +13,8 @@ module Tripod::Resource
13
13
  validates_presence_of :graph_uri
14
14
  # uri is a valid linked data url
15
15
  validates :uri, is_url: true
16
+ # every instance of a resource has an rdf type field, which is set at the class level
17
+ class_attribute :_RDF_TYPE
16
18
  # the Graph URI is set at the class level by default also, although this can be overridden in the constructor
17
19
  class_attribute :_GRAPH_URI
18
20
  end
@@ -50,7 +52,7 @@ module Tripod::Resource
50
52
  run_callbacks :initialize do
51
53
  graph_uri ||= self.class.get_graph_uri unless ignore_graph
52
54
  @graph_uri = RDF::URI(graph_uri) if graph_uri
53
- set_rdf_type
55
+ self.rdf_type = self.class.get_rdf_type if respond_to?(:rdf_type=) && self.class.get_rdf_type
54
56
  end
55
57
  end
56
58
 
@@ -105,6 +107,17 @@ module Tripod::Resource
105
107
  other.class == Class ? self <= other : other.is_a?(self)
106
108
  end
107
109
 
110
+ # makes a "field" on this model called rdf_type
111
+ # and sets a class level _RDF_TYPE variable with the rdf_type passed in.
112
+ def rdf_type(new_rdf_type)
113
+ self._RDF_TYPE = RDF::URI.new(new_rdf_type.to_s)
114
+ field :rdf_type, RDF.type, :multivalued => true, :is_uri => true # things can have more than 1 type and often do
115
+ end
116
+
117
+ def get_rdf_type
118
+ self._RDF_TYPE
119
+ end
120
+
108
121
  def graph_uri(new_graph_uri)
109
122
  self._GRAPH_URI = new_graph_uri
110
123
  end
@@ -117,4 +130,4 @@ module Tripod::Resource
117
130
  end
118
131
 
119
132
  # causes any hooks to be fired, if they've been setup on_load of :tripod.
120
- ActiveSupport.run_load_hooks(:triploid, Tripod::Resource)
133
+ ActiveSupport.run_load_hooks(:triploid, Tripod::Resource)
@@ -1,3 +1,3 @@
1
1
  module Tripod
2
- VERSION = "0.10.6"
2
+ VERSION = "0.10.7"
3
3
  end
@@ -14,6 +14,4 @@ class Dog
14
14
 
15
15
  linked_to :arch_enemy, 'http://example.com/archenemy', class_name: 'Dog'
16
16
  linked_to :enemies, 'http://example.com/enemy', class_name: 'Dog'
17
-
18
- embeds :fleas, 'http://example.com/fleas'
19
- end
17
+ end
data/spec/spec_helper.rb CHANGED
@@ -31,7 +31,7 @@ Tripod.configure do |config|
31
31
  # config.update_endpoint = 'http://127.0.0.1:3030/tripod-test/update'
32
32
  # config.query_endpoint = 'http://127.0.0.1:3030/tripod-test/sparql'
33
33
  # config.data_endpoint = 'http://127.0.0.1:3030/tripod-test/data'
34
-
34
+
35
35
  config.update_endpoint = 'http://127.0.0.1:3002/sparql/raw/update'
36
36
  config.query_endpoint = 'http://127.0.0.1:3002/sparql/raw'
37
37
  #config.data_endpoint = 'http://127.0.0.1:3030/tripod-test/data'
@@ -41,4 +41,4 @@ end
41
41
  Dir[ File.join(MODELS, "*.rb") ].sort.each do |file|
42
42
  name = File.basename(file, ".rb")
43
43
  autoload name.camelize.to_sym, name
44
- end
44
+ end
@@ -30,7 +30,9 @@ describe Tripod::Repository do
30
30
 
31
31
  context 'graph_uri set on object' do
32
32
  it 'populates the object with triples, restricted to the graph_uri' do
33
- Tripod::SparqlClient::Query.should_receive(:query).with(Person.all_triples_query(person.uri, graph_uri: person.graph_uri), 'application/n-triples').and_call_original
33
+ Tripod::SparqlClient::Query.should_receive(:query).with(
34
+ "CONSTRUCT {<#{person.uri}> ?p ?o} WHERE { GRAPH <#{person.graph_uri}> { <#{person.uri}> ?p ?o } }",
35
+ "application/n-triples").and_call_original
34
36
  person.hydrate!
35
37
  person.repository.should_not be_empty
36
38
  end
@@ -38,7 +40,9 @@ describe Tripod::Repository do
38
40
 
39
41
  context 'graph_uri not set on object' do
40
42
  it 'populates the object with triples, not to a graph' do
41
- Tripod::SparqlClient::Query.should_receive(:query).with(Person.all_triples_query(person.uri), 'application/n-triples').and_call_original
43
+ Tripod::SparqlClient::Query.should_receive(:query).with(
44
+ "CONSTRUCT {<#{graphless_resource.uri}> ?p ?o} WHERE { GRAPH ?g { <#{graphless_resource.uri}> ?p ?o } }",
45
+ "application/n-triples").and_call_original
42
46
  graphless_resource.hydrate!
43
47
  graphless_resource.repository.should_not be_empty
44
48
  end
@@ -69,4 +73,4 @@ describe Tripod::Repository do
69
73
  end
70
74
 
71
75
 
72
- end
76
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tripod
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.6
4
+ version: 0.10.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ric Roberts