tripod 0.7.1 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -2
- data/lib/tripod/attributes.rb +1 -1
- data/lib/tripod/criteria/execution.rb +25 -15
- data/lib/tripod/fields.rb +10 -1
- data/lib/tripod/finders.rb +70 -16
- data/lib/tripod/repository.rb +9 -6
- data/lib/tripod/resource_collection.rb +44 -8
- data/lib/tripod/serialization.rb +3 -3
- data/lib/tripod/sparql_client.rb +4 -8
- data/lib/tripod/streaming.rb +16 -1
- data/lib/tripod/version.rb +1 -1
- data/lib/tripod.rb +5 -0
- data/spec/tripod/serialization_spec.rb +14 -36
- metadata +22 -22
data/README.md
CHANGED
@@ -33,7 +33,7 @@ ActiveModel-style Ruby ORM for RDF Linked Data. Works with SPARQL 1.1 HTTP endpo
|
|
33
33
|
graph_uri 'http://example.com/people'
|
34
34
|
|
35
35
|
field :name, 'http://example.com/name'
|
36
|
-
field :knows, 'http://example.com/knows', :multivalued => true
|
36
|
+
field :knows, 'http://example.com/knows', :multivalued => true, :is_uri => true
|
37
37
|
field :aliases, 'http://example.com/alias', :multivalued => true
|
38
38
|
field :age, 'http://example.com/age', :datatype => RDF::XSD.integer
|
39
39
|
field :important_dates, 'http://example.com/importantdates', :datatype => RDF::XSD.date, :multivalued => true
|
@@ -107,10 +107,14 @@ Tripod doesn't supply a database. You need to install one. I recommend [Fuseki](
|
|
107
107
|
|
108
108
|
Resource.all #=> returns a criteria object to return resources in the database (as no rdf_type or graph_uri specified at class level)
|
109
109
|
|
110
|
-
Person.all.resources #=> returns all the actual resources for the criteria object, as an array
|
110
|
+
Person.all.resources #=> returns all the actual resources for the criteria object, as an array-like object
|
111
|
+
|
112
|
+
Person.all.resources(:return_graph) #=> returns the actual resources, but without returning the graph_uri in the select (helps avoid pagination issues). Note: doesn't set the graph uri on the instantiated resources.
|
111
113
|
|
112
114
|
Person.first #=> returns the first person (by crafting a sparql query under the covers that only returns 1 result)
|
113
115
|
|
116
|
+
Person.first(:return_graph) # as with resources, doesn't return / set the graph_uri.
|
117
|
+
|
114
118
|
Person.count #=> returns the count of all people (by crafting a count query under the covers that only returns a count)
|
115
119
|
|
116
120
|
# note that you need to use ?uri as the variable for the subject.
|
data/lib/tripod/attributes.rb
CHANGED
@@ -18,7 +18,7 @@ module Tripod::Attributes
|
|
18
18
|
# @param [ String ] name The name of the field for which to get the value.
|
19
19
|
# @param [ Field ] field An optional Field object
|
20
20
|
#
|
21
|
-
# @return
|
21
|
+
# @return Native Ruby object (e.g. String, DateTime) or array of them, depending on whether the field is multivalued or not
|
22
22
|
def read_attribute(name, field=nil)
|
23
23
|
field ||= self.fields[name]
|
24
24
|
raise Tripod::Errors::FieldNotPresent.new unless field
|
@@ -8,26 +8,38 @@ module Tripod
|
|
8
8
|
|
9
9
|
# Execute the query and return a +ResourceCollection+ of all hydrated resources
|
10
10
|
# +ResourceCollection+ is an +Enumerable+, Array-like object.
|
11
|
-
#
|
12
|
-
|
11
|
+
#
|
12
|
+
# @option options [ String ] return_graph Indicates whether to return the graph as one of the variables.
|
13
13
|
def resources(opts={})
|
14
14
|
Tripod::ResourceCollection.new(
|
15
|
-
|
15
|
+
self.resource_class._resources_from_sparql(build_select_query(opts)),
|
16
|
+
# pass in the criteria that was used to generate this collection, as well as whether the user specified return graph
|
17
|
+
:return_graph => (opts.has_key?(:return_graph) ? opts[:return_graph] : true),
|
18
|
+
:criteria => self
|
16
19
|
)
|
17
20
|
end
|
18
21
|
|
22
|
+
# run a query to get the raw serialisation of the results of this criteria object.
|
23
|
+
#
|
24
|
+
# @option options [ String ] return_graph Indicates whether to return the graph as one of the variables.
|
25
|
+
# @option options [ String ] accept_header The accept header to use for serializing (defaults to application/n-triples)
|
26
|
+
def serialize(opts={})
|
27
|
+
select_sparql = build_select_query(:return_graph => opts[:return_graph])
|
28
|
+
self.resource_class._raw_describe_select_results(select_sparql, :accept_header => opts[:accept_header]) # note that this method defaults to using application/n-triples.
|
29
|
+
end
|
30
|
+
|
19
31
|
# Execute the query and return the first result as a hydrated resource
|
20
|
-
#
|
21
|
-
#
|
32
|
+
#
|
33
|
+
# @option options [ String ] return_graph Indicates whether to return the graph as one of the variables.
|
22
34
|
def first(opts={})
|
23
35
|
sq = Tripod::SparqlQuery.new(build_select_query(opts))
|
24
36
|
first_sparql = sq.as_first_query_str
|
25
|
-
|
37
|
+
self.resource_class._resources_from_sparql(first_sparql).first
|
26
38
|
end
|
27
39
|
|
28
40
|
# Return how many records the current criteria would return
|
29
|
-
#
|
30
|
-
#
|
41
|
+
#
|
42
|
+
# @option options [ String ] return_graph Indicates whether to return the graph as one of the variables.
|
31
43
|
def count(opts={})
|
32
44
|
sq = Tripod::SparqlQuery.new(build_select_query(opts))
|
33
45
|
count_sparql = sq.as_count_query_str
|
@@ -41,17 +53,15 @@ module Tripod
|
|
41
53
|
|
42
54
|
private
|
43
55
|
|
44
|
-
|
45
|
-
uris_and_graphs = self.resource_class._select_uris_and_graphs(sparql)
|
46
|
-
self.resource_class._create_and_hydrate_resources(uris_and_graphs)
|
47
|
-
end
|
48
|
-
|
49
|
-
# options:
|
50
|
-
# :return_graph (default true) # indicates whether to return the graph as one of the variables.
|
56
|
+
# @option options [ String ] return_graph Indicates whether to return the graph as one of the variables.
|
51
57
|
def build_select_query(opts={})
|
52
58
|
|
59
|
+
Tripod.logger.debug("TRIPOD: building select query for criteria...")
|
60
|
+
|
53
61
|
return_graph = opts.has_key?(:return_graph) ? opts[:return_graph] : true
|
54
62
|
|
63
|
+
Tripod.logger.debug("TRIPOD: with return_graph: #{return_graph.inspect}")
|
64
|
+
|
55
65
|
select_query = "SELECT DISTINCT ?uri "
|
56
66
|
|
57
67
|
if return_graph
|
data/lib/tripod/fields.rb
CHANGED
@@ -17,7 +17,16 @@ module Tripod::Fields
|
|
17
17
|
# added as an instance method to the Resource.
|
18
18
|
#
|
19
19
|
# @example Define a field.
|
20
|
-
# field :name,
|
20
|
+
# field :name, 'http://example.com/name'
|
21
|
+
#
|
22
|
+
# @example Define a field of a specific RDF type
|
23
|
+
# field :modified_at, 'http://example.com/modified_at', datatype: RDF::XSD.DateTime
|
24
|
+
#
|
25
|
+
# @example Define a multi-valued field (can be combined with other options)
|
26
|
+
# field :tags, 'http://example.com/tag', multivalued: true
|
27
|
+
#
|
28
|
+
# @example Define a field containing a URI to another RDF resource
|
29
|
+
# field :knows, 'http://example.com/knows', is_uri: true
|
21
30
|
#
|
22
31
|
# @param [ Symbol ] name The name of the field.
|
23
32
|
# @param [ String, RDF::URI ] predicate The predicate for the field.
|
data/lib/tripod/finders.rb
CHANGED
@@ -62,8 +62,7 @@ module Tripod::Finders
|
|
62
62
|
#
|
63
63
|
# @return [ Array ] An array of hydrated resources of this class's type.
|
64
64
|
def find_by_sparql(sparql_query, opts={})
|
65
|
-
|
66
|
-
_create_and_hydrate_resources(uris_and_graphs)
|
65
|
+
_create_and_hydrate_resources_from_sparql(sparql_query, opts)
|
67
66
|
end
|
68
67
|
|
69
68
|
# execute a where clause on this resource.
|
@@ -95,30 +94,86 @@ module Tripod::Finders
|
|
95
94
|
uris_sparql_str = uris.map{ |u| "<#{u.to_s}>" }.join(" ")
|
96
95
|
|
97
96
|
# Do a big describe statement, and read the results into an in-memory repo
|
98
|
-
|
97
|
+
ntriples_string = Tripod::SparqlClient::Query.query("DESCRIBE #{uris_sparql_str}", "application/n-triples")
|
98
|
+
graph = _rdf_graph_from_ntriples_string(ntriples_string, graph)
|
99
|
+
end
|
99
100
|
|
100
|
-
|
101
|
-
|
102
|
-
graph << statement
|
103
|
-
end
|
104
|
-
end
|
101
|
+
graph
|
102
|
+
end
|
105
103
|
|
106
|
-
|
104
|
+
# returns a graph of triples which describe results of the sparql passed in.
|
105
|
+
#
|
106
|
+
# @option options [ String ] uri_variable The name of the uri variable in the query, if not 'uri'
|
107
|
+
def describe_select_results(select_sparql, opts={})
|
108
|
+
ntriples_string = _raw_describe_select_results(select_sparql, opts) # this defaults to using n-triples
|
109
|
+
_rdf_graph_from_ntriples_string(ntriples_string)
|
110
|
+
end
|
107
111
|
|
112
|
+
# PRIVATE utility methods (not intended to be used externally)
|
113
|
+
##########################
|
114
|
+
|
115
|
+
# given a sparql select query, create and hydrate some resources
|
116
|
+
#
|
117
|
+
# @option options [ String ] uri_variable The name of the uri variable in the query, if not 'uri'
|
118
|
+
# @option options [ String ] graph_variable The name of the uri variable in thh query, if not 'graph'
|
119
|
+
def _resources_from_sparql(select_sparql, opts={})
|
120
|
+
_create_and_hydrate_resources_from_sparql(select_sparql, opts)
|
121
|
+
end
|
122
|
+
|
123
|
+
# given a string of ntriples data, populate an RDF graph.
|
124
|
+
# If you pass a graph in, it will add to that one.
|
125
|
+
def _rdf_graph_from_ntriples_string(ntriples_string, graph=nil)
|
126
|
+
graph ||= RDF::Graph.new
|
127
|
+
RDF::Reader.for(:ntriples).new(ntriples_string) do |reader|
|
128
|
+
reader.each_statement do |statement|
|
129
|
+
graph << statement
|
130
|
+
end
|
131
|
+
end
|
108
132
|
graph
|
109
133
|
end
|
110
134
|
|
111
|
-
#
|
135
|
+
# Given a select query, perform a DESCRIBE query to get a graph of data from which we
|
136
|
+
# create and hydrate a collection of resources.
|
137
|
+
#
|
138
|
+
# @option options [ String ] uri_variable The name of the uri variable in the query, if not 'uri'
|
139
|
+
# @option options [ String ] graph_variable The name of the uri variable in the query, if not 'graph'
|
140
|
+
def _create_and_hydrate_resources_from_sparql(select_sparql, opts={})
|
141
|
+
# TODO: Optimization?: if return_graph option is false, then don't do this next line?
|
142
|
+
uris_and_graphs = _select_uris_and_graphs(select_sparql, :uri_variable => opts[:uri_variable], :graph_variable => opts[:graph_variable])
|
143
|
+
ntriples_string = _raw_describe_select_results(select_sparql, :uri_variable => opts[:uri_variable]) # this defaults to ntriples
|
144
|
+
graph = _rdf_graph_from_ntriples_string(ntriples_string, graph=nil)
|
145
|
+
_resources_from_graph(graph, uris_and_graphs)
|
146
|
+
end
|
147
|
+
|
148
|
+
# For a select query, generate a query which DESCRIBES all the results
|
149
|
+
#
|
150
|
+
# @option options [ String ] uri_variable The name of the uri variable in the query, if not 'uri'
|
151
|
+
def _describe_query_for_select(select_sparql, opts={})
|
152
|
+
uri_variable = opts[:uri_variable] || "uri"
|
153
|
+
"DESCRIBE ?#{uri_variable} WHERE { #{select_sparql} }"
|
154
|
+
end
|
112
155
|
|
113
|
-
#
|
114
|
-
#
|
115
|
-
|
156
|
+
# For a select query, get a raw serialisation of the DESCRIPTION of the resources from the database.
|
157
|
+
#
|
158
|
+
# @option options [ String ] uri_variable The name of the uri variable in the query, if not 'uri'
|
159
|
+
# @option options [ String ] accept_header The http accept header (default application/n-triples)
|
160
|
+
def _raw_describe_select_results(select_sparql, opts={})
|
161
|
+
accept_header = opts[:accept_header] || "application/n-triples"
|
162
|
+
query = _describe_query_for_select(select_sparql, :uri_variable => opts[:uri_variable])
|
163
|
+
Tripod::SparqlClient::Query.query(query, accept_header)
|
164
|
+
end
|
116
165
|
|
117
|
-
|
166
|
+
# given a graph of data, and a hash of uris=>graphs, create and hydrate some resources.
|
167
|
+
# Note: if any of the graphs are not set in the hash,
|
168
|
+
# those resources can still be constructed, but not persisted back to DB.
|
169
|
+
def _resources_from_graph(graph, uris_and_graphs)
|
118
170
|
repo = add_data_to_repository(graph)
|
119
|
-
|
120
171
|
resources = []
|
121
172
|
|
173
|
+
# TODO: ? if uris_and_graphs not passed in, we could get the
|
174
|
+
# uris from the graph, and just not create the resoruces with a graph
|
175
|
+
# (but they won't be persistable).
|
176
|
+
|
122
177
|
uris_and_graphs.each_pair do |u,g|
|
123
178
|
|
124
179
|
# instantiate a new resource
|
@@ -139,7 +194,6 @@ module Tripod::Finders
|
|
139
194
|
resources
|
140
195
|
end
|
141
196
|
|
142
|
-
|
143
197
|
# based on the query passed in, build a hash of uris->graphs
|
144
198
|
# @param [ String] sparql. The sparql query
|
145
199
|
# @param [ Hash ] opts. A hash of options.
|
data/lib/tripod/repository.rb
CHANGED
@@ -34,12 +34,7 @@ module Tripod::Repository
|
|
34
34
|
end
|
35
35
|
else
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
triples = Tripod::SparqlClient::Query.query(
|
40
|
-
"CONSTRUCT {<#{uri}> ?p ?o} WHERE { GRAPH #{graph_selector} { <#{uri}> ?p ?o } }",
|
41
|
-
"application/n-triples"
|
42
|
-
)
|
37
|
+
triples = retrieve_triples_from_database
|
43
38
|
|
44
39
|
@repository = RDF::Repository.new
|
45
40
|
RDF::Reader.for(:ntriples).new(triples) do |reader|
|
@@ -60,6 +55,14 @@ module Tripod::Repository
|
|
60
55
|
g
|
61
56
|
end
|
62
57
|
|
58
|
+
def retrieve_triples_from_database(accept_header="application/n-triples")
|
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
|
+
)
|
64
|
+
end
|
65
|
+
|
63
66
|
# returns a graph of triples from the underlying repository where this resource's uri is the subject.
|
64
67
|
def get_triples_for_this_resource
|
65
68
|
triples_graph = RDF::Graph.new
|
@@ -8,9 +8,15 @@ module Tripod
|
|
8
8
|
include Enumerable
|
9
9
|
|
10
10
|
attr_reader :resources
|
11
|
+
attr_reader :criteria # the criteria used to generate this collection
|
11
12
|
|
12
|
-
|
13
|
+
# options:
|
14
|
+
# :criteria - the criteria used to create this collection
|
15
|
+
# :return_graph - whether the original query returned the graphs or not.
|
16
|
+
def initialize(resources, opts={})
|
13
17
|
@resources = resources
|
18
|
+
@criteria = opts[:criteria]
|
19
|
+
@return_graph = opts[:return_graph]
|
14
20
|
end
|
15
21
|
|
16
22
|
def length
|
@@ -37,27 +43,57 @@ module Tripod
|
|
37
43
|
|
38
44
|
# for n-triples we can just concatenate them
|
39
45
|
def to_nt
|
40
|
-
nt
|
41
|
-
|
42
|
-
|
46
|
+
time_serialization('nt') do
|
47
|
+
if @criteria
|
48
|
+
@criteria.serialize(:return_graph => @return_graph, :accept_header => "application/n-triples")
|
49
|
+
else
|
50
|
+
# for n-triples we can just concatenate them
|
51
|
+
nt = ""
|
52
|
+
resources.each do |resource|
|
53
|
+
nt += resource.to_nt
|
54
|
+
end
|
55
|
+
nt
|
56
|
+
end
|
43
57
|
end
|
44
|
-
nt
|
45
58
|
end
|
46
59
|
|
47
60
|
def to_json(opts={})
|
48
|
-
|
61
|
+
# most databases don't have a native json-ld implementation.
|
62
|
+
time_serialization('json') do
|
63
|
+
get_graph.dump(:jsonld)
|
64
|
+
end
|
49
65
|
end
|
50
66
|
|
51
67
|
def to_rdf
|
52
|
-
|
68
|
+
time_serialization('rdf') do
|
69
|
+
if @criteria
|
70
|
+
@criteria.serialize(:return_graph => @return_graph, :accept_header => "application/rdf+xml")
|
71
|
+
else
|
72
|
+
get_graph.dump(:rdf)
|
73
|
+
end
|
74
|
+
end
|
53
75
|
end
|
54
76
|
|
55
77
|
def to_ttl
|
56
|
-
|
78
|
+
time_serialization('ttl') do
|
79
|
+
if @criteria
|
80
|
+
@criteria.serialize(:return_graph => @return_graph, :accept_header => "text/turtle")
|
81
|
+
else
|
82
|
+
get_graph.dump(:n3)
|
83
|
+
end
|
84
|
+
end
|
57
85
|
end
|
58
86
|
|
59
87
|
private
|
60
88
|
|
89
|
+
def time_serialization(format)
|
90
|
+
start_serializing = Time.now if Tripod.logger.debug?
|
91
|
+
result = yield if block_given?
|
92
|
+
serializing_duration = Time.now - start_serializing if Tripod.logger.debug?
|
93
|
+
Tripod.logger.debug( "TRIPOD: Serializing collection to #{format} took #{serializing_duration} secs" )
|
94
|
+
result
|
95
|
+
end
|
96
|
+
|
61
97
|
def get_graph
|
62
98
|
graph = RDF::Graph.new
|
63
99
|
RDF::Reader.for(:ntriples).new(self.to_nt) do |reader|
|
data/lib/tripod/serialization.rb
CHANGED
@@ -6,17 +6,17 @@ module Tripod::Serialization
|
|
6
6
|
|
7
7
|
# Serialises this resource's triples to rdf/xml
|
8
8
|
def to_rdf
|
9
|
-
|
9
|
+
retrieve_triples_from_database(accept_header="application/rdf+xml")
|
10
10
|
end
|
11
11
|
|
12
12
|
# Serialises this resource's triples to turtle
|
13
13
|
def to_ttl
|
14
|
-
|
14
|
+
retrieve_triples_from_database(accept_header="text/turtle")
|
15
15
|
end
|
16
16
|
|
17
17
|
# Serialises this resource's triples to n-triples
|
18
18
|
def to_nt
|
19
|
-
|
19
|
+
retrieve_triples_from_database(accept_header="application/n-triples")
|
20
20
|
end
|
21
21
|
|
22
22
|
# Serialises this resource's triples to JSON-LD
|
data/lib/tripod/sparql_client.rb
CHANGED
@@ -23,15 +23,11 @@ module Tripod::SparqlClient
|
|
23
23
|
|
24
24
|
# Hash.to_query from active support core extensions
|
25
25
|
stream_data = -> {
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
Rails.logger.debug "TRIPOD: Streaming opts: #{streaming_opts.inspect}"
|
30
|
-
end
|
26
|
+
Tripod.logger.debug "TRIPOD: About to run query: #{sparql}"
|
27
|
+
Tripod.logger.debug "TRIPOD: Streaming fron url: #{request_url}"
|
28
|
+
Tripod.logger.debug "TRIPOD: Streaming opts: #{streaming_opts.inspect}"
|
31
29
|
|
32
|
-
|
33
|
-
# Rails.logger.debug "TRIPOD: response: #{response}" if defined?(Rails)
|
34
|
-
response
|
30
|
+
Tripod::Streaming.get_data(request_url, streaming_opts)
|
35
31
|
}
|
36
32
|
|
37
33
|
if Tripod.cache_store # if a cache store is configured
|
data/lib/tripod/streaming.rb
CHANGED
@@ -22,17 +22,32 @@ module Tripod
|
|
22
22
|
total_bytes = 0
|
23
23
|
response_string = ""
|
24
24
|
|
25
|
+
request_start_time = Time.now if Tripod.logger.debug?
|
26
|
+
|
25
27
|
begin
|
26
28
|
http.request_get(uri.request_uri, 'Accept' => accept) do |res|
|
27
|
-
|
29
|
+
|
30
|
+
response_duration = Time.now - request_start_time if Tripod.logger.debug?
|
31
|
+
|
32
|
+
Tripod.logger.debug "TRIPOD: received response code: #{res.code} in: #{response_duration} secs"
|
28
33
|
raise Tripod::Errors::BadSparqlRequest.new(res.body) if res.code.to_s != "200"
|
29
34
|
|
35
|
+
stream_start_time = Time.now if Tripod.logger.debug?
|
36
|
+
|
30
37
|
res.read_body do |seg|
|
31
38
|
total_bytes += seg.size
|
32
39
|
response_string += seg.to_s
|
33
40
|
# if there's a limit, stop when we reach it
|
34
41
|
raise Tripod::Errors::SparqlResponseTooLarge.new if limit_in_bytes && (total_bytes > limit_in_bytes)
|
35
42
|
end
|
43
|
+
|
44
|
+
if Tripod.logger.debug?
|
45
|
+
stream_duration = Time.now - stream_start_time if
|
46
|
+
total_request_time = stream_end_time - request_start_time
|
47
|
+
end
|
48
|
+
|
49
|
+
Tripod.logger.debug "TRIPOD: #{total_bytes} bytes streamed in: #{stream_duration} secs"
|
50
|
+
Tripod.logger.debug "TRIPOD: total request time: #{total_request_time} secs"
|
36
51
|
end
|
37
52
|
rescue Timeout::Error => timeout
|
38
53
|
raise Tripod::Errors::Timeout.new
|
data/lib/tripod/version.rb
CHANGED
data/lib/tripod.rb
CHANGED
@@ -56,6 +56,10 @@ module Tripod
|
|
56
56
|
|
57
57
|
mattr_accessor :cache_store
|
58
58
|
|
59
|
+
mattr_accessor :logger
|
60
|
+
@@logger = Logger.new(STDOUT)
|
61
|
+
@@logger.level = Logger::WARN
|
62
|
+
|
59
63
|
# Use +configure+ to override configuration in an app, (defaults shown)
|
60
64
|
#
|
61
65
|
# Tripod.configure do |config|
|
@@ -66,6 +70,7 @@ module Tripod
|
|
66
70
|
# config.cache_store = nil #e.g Tripod::CacheStores::MemcachedCacheStore.new('localhost:11211')
|
67
71
|
# # note: if using memcached, make sure you set the -I (slab size) to big enough to store each result
|
68
72
|
# # and set the -m (total size) to something quite big (or the cache will recycle too often).
|
73
|
+
# config.logger = Logger.new(STDOUT) # you can set this to the Rails.logger in a rails app.
|
69
74
|
# end
|
70
75
|
#
|
71
76
|
def self.configure
|
@@ -15,32 +15,34 @@ describe Tripod::Serialization do
|
|
15
15
|
p
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
shared_examples_for "a serialisable resource" do
|
20
19
|
describe "#to_rdf" do
|
21
|
-
it "should
|
22
|
-
person.to_rdf.should == person.
|
20
|
+
it "should get the data from the database as rdf/xml" do
|
21
|
+
person.to_rdf.should == person.retrieve_triples_from_database(accept_header="application/rdf+xml")
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
26
25
|
describe "#to_ttl" do
|
27
|
-
it "should
|
28
|
-
person.to_ttl.should == person.
|
26
|
+
it "should get the data from the database as text/turtle" do
|
27
|
+
person.to_ttl.should == person.retrieve_triples_from_database(accept_header="text/turtle")
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
32
31
|
describe "#to_nt" do
|
33
|
-
it "should
|
34
|
-
person.to_nt.should == person.
|
32
|
+
it "should get the data from the database as application/n-triples" do
|
33
|
+
person.to_nt.should == person.retrieve_triples_from_database(accept_header="application/n-triples")
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
38
|
-
|
39
|
-
it "should dump the
|
40
|
-
person.to_json.should == person.
|
37
|
+
describe "#to_json" do
|
38
|
+
it "should dump the triples for this resource only as json-ld" do
|
39
|
+
person.to_json.should == person.get_triples_for_this_resource.dump(:jsonld)
|
41
40
|
end
|
42
41
|
end
|
42
|
+
end
|
43
43
|
|
44
|
+
context "where no eager loading has happened" do
|
45
|
+
it_should_behave_like "a serialisable resource"
|
44
46
|
end
|
45
47
|
|
46
48
|
context "where eager loading has happened" do
|
@@ -50,31 +52,7 @@ describe Tripod::Serialization do
|
|
50
52
|
person.eager_load_object_triples!
|
51
53
|
end
|
52
54
|
|
53
|
-
|
54
|
-
it "should dump the triples for this resource only as rdfxml" do
|
55
|
-
person.to_rdf.should == person.get_triples_for_this_resource.dump(:rdfxml)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "#to_ttl" do
|
60
|
-
it "should dump the triples for this resource only with the n3 serializer" do
|
61
|
-
person.to_ttl.should == person.get_triples_for_this_resource.dump(:n3)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "#to_nt" do
|
66
|
-
it "should dump the triples for this resource only as ntriples" do
|
67
|
-
person.to_nt.should == person.get_triples_for_this_resource.dump(:ntriples)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe "#to_json" do
|
72
|
-
it "should dump the triples for this resource only as ntriples" do
|
73
|
-
person.to_json.should == person.get_triples_for_this_resource.dump(:jsonld)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
|
55
|
+
it_should_behave_like "a serialisable resource"
|
78
56
|
|
79
57
|
end
|
80
58
|
|
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.7.
|
4
|
+
version: 0.7.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,11 +11,11 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-03-
|
14
|
+
date: 2013-03-29 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rest-client
|
18
|
-
requirement: &
|
18
|
+
requirement: &70297614006920 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ! '>='
|
@@ -23,10 +23,10 @@ dependencies:
|
|
23
23
|
version: '0'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *70297614006920
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activemodel
|
29
|
-
requirement: &
|
29
|
+
requirement: &70297614004880 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ~>
|
@@ -34,10 +34,10 @@ dependencies:
|
|
34
34
|
version: '3.2'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
|
-
version_requirements: *
|
37
|
+
version_requirements: *70297614004880
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: equivalent-xml
|
40
|
-
requirement: &
|
40
|
+
requirement: &70297614004300 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
@@ -45,10 +45,10 @@ dependencies:
|
|
45
45
|
version: '0'
|
46
46
|
type: :runtime
|
47
47
|
prerelease: false
|
48
|
-
version_requirements: *
|
48
|
+
version_requirements: *70297614004300
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: rdf
|
51
|
-
requirement: &
|
51
|
+
requirement: &70297614003240 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
53
53
|
requirements:
|
54
54
|
- - ~>
|
@@ -56,10 +56,10 @@ dependencies:
|
|
56
56
|
version: '1.0'
|
57
57
|
type: :runtime
|
58
58
|
prerelease: false
|
59
|
-
version_requirements: *
|
59
|
+
version_requirements: *70297614003240
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: rdf-rdfxml
|
62
|
-
requirement: &
|
62
|
+
requirement: &70297614002060 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
64
|
requirements:
|
65
65
|
- - ! '>='
|
@@ -67,10 +67,10 @@ dependencies:
|
|
67
67
|
version: '0'
|
68
68
|
type: :runtime
|
69
69
|
prerelease: false
|
70
|
-
version_requirements: *
|
70
|
+
version_requirements: *70297614002060
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: rdf-n3
|
73
|
-
requirement: &
|
73
|
+
requirement: &70297614019880 !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
75
75
|
requirements:
|
76
76
|
- - ! '>='
|
@@ -78,10 +78,10 @@ dependencies:
|
|
78
78
|
version: '0'
|
79
79
|
type: :runtime
|
80
80
|
prerelease: false
|
81
|
-
version_requirements: *
|
81
|
+
version_requirements: *70297614019880
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: rdf-json
|
84
|
-
requirement: &
|
84
|
+
requirement: &70297614019140 !ruby/object:Gem::Requirement
|
85
85
|
none: false
|
86
86
|
requirements:
|
87
87
|
- - ! '>='
|
@@ -89,10 +89,10 @@ dependencies:
|
|
89
89
|
version: '0'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
|
-
version_requirements: *
|
92
|
+
version_requirements: *70297614019140
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
94
|
name: json-ld
|
95
|
-
requirement: &
|
95
|
+
requirement: &70297614017680 !ruby/object:Gem::Requirement
|
96
96
|
none: false
|
97
97
|
requirements:
|
98
98
|
- - ! '>='
|
@@ -100,10 +100,10 @@ dependencies:
|
|
100
100
|
version: '0'
|
101
101
|
type: :runtime
|
102
102
|
prerelease: false
|
103
|
-
version_requirements: *
|
103
|
+
version_requirements: *70297614017680
|
104
104
|
- !ruby/object:Gem::Dependency
|
105
105
|
name: guid
|
106
|
-
requirement: &
|
106
|
+
requirement: &70297614016520 !ruby/object:Gem::Requirement
|
107
107
|
none: false
|
108
108
|
requirements:
|
109
109
|
- - ! '>='
|
@@ -111,10 +111,10 @@ dependencies:
|
|
111
111
|
version: '0'
|
112
112
|
type: :runtime
|
113
113
|
prerelease: false
|
114
|
-
version_requirements: *
|
114
|
+
version_requirements: *70297614016520
|
115
115
|
- !ruby/object:Gem::Dependency
|
116
116
|
name: dalli
|
117
|
-
requirement: &
|
117
|
+
requirement: &70297614034920 !ruby/object:Gem::Requirement
|
118
118
|
none: false
|
119
119
|
requirements:
|
120
120
|
- - ~>
|
@@ -122,7 +122,7 @@ dependencies:
|
|
122
122
|
version: '2.6'
|
123
123
|
type: :runtime
|
124
124
|
prerelease: false
|
125
|
-
version_requirements: *
|
125
|
+
version_requirements: *70297614034920
|
126
126
|
description: RDF ruby ORM
|
127
127
|
email:
|
128
128
|
- ric@swirrl.com
|