activerdf_net7 1.6.16 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +63 -0
- data/activerdf-jena/lib/activerdf_jena/jena.rb +4 -4
- data/activerdf-jena/lib/activerdf_jena/jena_adapter.rb +55 -55
- data/activerdf-jena/lib/activerdf_jena/lucene.rb +1 -1
- data/activerdf-jena/lib/activerdf_jena/ng4j.rb +7 -7
- data/activerdf-jena/lib/activerdf_jena/ng4j_adapter.rb +47 -47
- data/activerdf-jena/lib/activerdf_jena/pellet.rb +1 -1
- data/activerdf-jena/test/test_jena_adapter.rb +121 -120
- data/activerdf-jena/test/test_ng4j_adapter.rb +111 -110
- data/activerdf-rdflite/lib/activerdf_rdflite/fetching.rb +23 -19
- data/activerdf-rdflite/lib/activerdf_rdflite/rdflite.rb +153 -277
- data/activerdf-rdflite/lib/activerdf_rdflite/suggesting.rb +2 -2
- data/activerdf-rdflite/test/test_fetching.rb +7 -22
- data/activerdf-rdflite/test/test_rdflite.rb +44 -257
- data/activerdf-redland/lib/activerdf_redland/redland.rb +246 -282
- data/activerdf-redland/test/test_redland_adapter.rb +62 -224
- data/activerdf-sesame/ext/wrapper-sesame2.jar +0 -0
- data/activerdf-sesame/java/build.number +2 -2
- data/activerdf-sesame/java/build.xml +0 -0
- data/activerdf-sesame/java/lib/junit-3.8.2.jar +0 -0
- data/activerdf-sesame/java/settings.xml +0 -0
- data/activerdf-sesame/java/src/org/activerdf/wrapper/sesame2/WrapperForSesame2.java +0 -0
- data/activerdf-sesame/java/temp/build/org/activerdf/wrapper/sesame2/WrapperForSesame2.class +0 -0
- data/activerdf-sesame/java/temp/manifest/MANIFEST.MF +2 -2
- data/activerdf-sesame/java/test-src/org/activerdf/wrapper/sesame2/TestWrapperForSesame2.java +0 -0
- data/activerdf-sesame/lib/activerdf_sesame/sesame.rb +360 -364
- data/activerdf-sesame/test/test_sesame_adapter.rb +85 -83
- data/activerdf-sparql/lib/activerdf_sparql/sparql.rb +147 -148
- data/activerdf-sparql/lib/activerdf_sparql/sparql_result_parser.rb +5 -5
- data/activerdf-sparql/test/test_sparql_adapter.rb +2 -0
- data/activerdf-yars/lib/activerdf_yars/jars2.rb +85 -83
- data/lib/active_rdf/federation/active_rdf_adapter.rb +26 -39
- data/lib/active_rdf/federation/connection_pool.rb +119 -110
- data/lib/active_rdf/federation/federation_manager.rb +51 -51
- data/lib/active_rdf/objectmanager/bnode.rb +8 -2
- data/lib/active_rdf/objectmanager/literal.rb +81 -50
- data/lib/active_rdf/objectmanager/namespace.rb +117 -84
- data/lib/active_rdf/objectmanager/object_manager.rb +101 -96
- data/lib/active_rdf/objectmanager/ordered_set.rb +1 -1
- data/lib/active_rdf/objectmanager/property.rb +345 -0
- data/lib/active_rdf/objectmanager/property_list.rb +4 -4
- data/lib/active_rdf/objectmanager/property_lookup.rb +57 -0
- data/lib/active_rdf/objectmanager/resource.rb +293 -501
- data/lib/active_rdf/objectmanager/resource_like.rb +2 -2
- data/lib/active_rdf/objectmanager/resource_query.rb +85 -0
- data/lib/active_rdf/queryengine/ntriples_parser.rb +75 -68
- data/lib/active_rdf/queryengine/query.rb +237 -183
- data/lib/active_rdf/queryengine/query2jars2.rb +17 -15
- data/lib/active_rdf/queryengine/query2sparql.rb +107 -101
- data/lib/active_rdf.rb +28 -17
- data/lib/active_rdf_helpers.rb +37 -5
- data/lib/active_rdf_log.rb +11 -11
- data/test/adapters/test_activerdf_adapter.rb +138 -0
- data/test/{test_adapters.rb → adapters/test_adapters.rb} +6 -24
- data/test/adapters/test_bnode_capable_adapter.rb +31 -0
- data/test/adapters/test_context_aware_adapter.rb +31 -0
- data/test/adapters/test_network_aware_adapter.rb +29 -0
- data/test/adapters/test_persistent_adapter.rb +21 -0
- data/test/adapters/test_read_only_adapter.rb +15 -0
- data/test/adapters/test_reasoning_adapter.rb +11 -0
- data/test/adapters/test_writable_adapter.rb +163 -0
- data/test/common.rb +78 -96
- data/test/federation/test_connection_pool.rb +25 -44
- data/test/federation/test_federation_manager.rb +45 -45
- data/test/objectmanager/test_literal.rb +47 -26
- data/test/objectmanager/test_namespace.rb +3 -1
- data/test/objectmanager/test_object_manager.rb +35 -45
- data/test/objectmanager/test_ordered_set.rb +1 -1
- data/test/objectmanager/test_property.rb +261 -0
- data/test/objectmanager/test_resource_reading.rb +196 -104
- data/test/objectmanager/test_resource_reasoning.rb +26 -0
- data/test/objectmanager/test_resource_writing.rb +34 -25
- data/test/queryengine/my_external_resource.rb +5 -1
- data/test/queryengine/test_external_resource_class.rb +1 -8
- data/test/queryengine/test_ntriples_parser.rb +5 -3
- data/test/queryengine/test_query.rb +3 -3
- data/test/queryengine/test_query2jars2.rb +2 -2
- data/test/queryengine/test_query2sparql.rb +2 -2
- data/test/queryengine/test_query_engine.rb +46 -28
- metadata +16 -8
- data/activerdf-rdflite/test/test_bnode_data.nt +0 -5
- data/activerdf-rdflite/test/test_data.nt +0 -32
- data/activerdf-rdflite/test/test_escaped_data.nt +0 -2
- data/activerdf-redland/test/test_person_data.nt +0 -42
- data/test/objectmanager/test_talia_syntax.rb +0 -68
@@ -0,0 +1,261 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'active_rdf'
|
3
|
+
require 'set'
|
4
|
+
require File.dirname(File.expand_path(__FILE__)) + '/../common'
|
5
|
+
|
6
|
+
class TestProperty < Test::Unit::TestCase
|
7
|
+
include SetupAdapter
|
8
|
+
|
9
|
+
def test_to_ary
|
10
|
+
p = RDF::Property.new(TEST::age)
|
11
|
+
assert !p.respond_to?(:to_ary)
|
12
|
+
|
13
|
+
p = RDF::Property.new(TEST::age, TEST::eyal)
|
14
|
+
assert p.respond_to?(:to_ary)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_retrieve_a_triple_with_property
|
18
|
+
@adapter.load "#{File.dirname(__FILE__)}/../test_person_data.nt"
|
19
|
+
@adapter.load "#{File.dirname(__FILE__)}/../test_person2_data.nt"
|
20
|
+
eyal = TEST::eyal
|
21
|
+
age = 27
|
22
|
+
michael = TEST::michael
|
23
|
+
michael.age = age
|
24
|
+
benjamin = TEST::Person.new(TEST::benjamin)
|
25
|
+
|
26
|
+
eyal.test::member_of = ["A","B","C"]
|
27
|
+
michael.test::member_of = ["A","B"]
|
28
|
+
benjamin.test::member_of = ["B","C"]
|
29
|
+
|
30
|
+
s = Query.new.select(:s).where(:s,TEST::member_of,eyal.member_of).execute
|
31
|
+
assert_equal Set[eyal], Set.new(s)
|
32
|
+
|
33
|
+
s = Query.new.select(:s).where(:s,TEST::member_of,michael.member_of).execute
|
34
|
+
assert_equal Set[eyal,michael], Set.new(s)
|
35
|
+
|
36
|
+
s = Query.new.select(:s).where(:s,TEST::member_of,benjamin.member_of).execute
|
37
|
+
assert_equal Set[eyal,benjamin], Set.new(s)
|
38
|
+
|
39
|
+
p = RDF::Property.new(TEST::member_of, michael)
|
40
|
+
# Property will act as set of values in the object clause when @subject set
|
41
|
+
assert_equal Set[eyal,michael], Set.new(Query.new.distinct(:s).where(:s, p, p).execute)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class TestAssociatedProperty < Test::Unit::TestCase
|
46
|
+
include SetupAdapter
|
47
|
+
|
48
|
+
def setup
|
49
|
+
super
|
50
|
+
@adapter.load "#{File.dirname(__FILE__)}/../test_person_data.nt"
|
51
|
+
@email = RDF::Property.new(TEST::email,TEST::eyal)
|
52
|
+
@age = RDF::Property.new(TEST::age,TEST::eyal)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_to_a
|
56
|
+
assert_equal Set["eyal@cs.vu.nl", "eyal.oren@deri.org"], Set.new(@email)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_to_ary
|
60
|
+
assert @email.respond_to?(:to_ary)
|
61
|
+
|
62
|
+
# when comparing arrays, order matters
|
63
|
+
assert ["eyal@cs.vu.nl", "eyal.oren@deri.org"] != @email.to_ary
|
64
|
+
|
65
|
+
assert_equal Set["eyal@cs.vu.nl", "eyal.oren@deri.org"], Set.new(@email.to_ary)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_to_h
|
69
|
+
h = {"fe82da4f0b32cd8ca4f1e8eb7683fcb1"=>"eyal@cs.vu.nl", "48ba5c9312b3400d28a72b637b0b3748"=>"eyal.oren@deri.org"}
|
70
|
+
assert_equal h, @email.to_h
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_add
|
74
|
+
@email.replace "eyal@cs.vu.nl"
|
75
|
+
assert_equal ["eyal@cs.vu.nl"], @email
|
76
|
+
|
77
|
+
@email.add "eyal.oren@deri.com"
|
78
|
+
assert_equal ["eyal@cs.vu.nl","eyal.oren@deri.com"], @email
|
79
|
+
|
80
|
+
@email.replace "eyal@cs.vu.nl"
|
81
|
+
@email.add ["eyal@cs.vu.nl","eyal.oren@deri.org"]
|
82
|
+
assert_equal ["eyal@cs.vu.nl","eyal.oren@deri.org"], @email
|
83
|
+
|
84
|
+
# numbers (doesn't add them together, adds new value)
|
85
|
+
@age.replace 30
|
86
|
+
@age += 35
|
87
|
+
assert_equal [30, 35], @age
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_remove
|
91
|
+
@email -= "eyal.oren@deri.org"
|
92
|
+
assert ["eyal@cs.vu.nl"], @email
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_replace
|
96
|
+
# two ways to update values
|
97
|
+
# using an index
|
98
|
+
@email[@email.index("eyal.oren@deri.org")] = "eyal.oren@deri.net"
|
99
|
+
assert_equal ["eyal@cs.vu.nl","eyal.oren@deri.net"], @email
|
100
|
+
|
101
|
+
# using old value
|
102
|
+
@email["eyal.oren@deri.net"] = "eyal.oren@deri.org"
|
103
|
+
assert_equal ["eyal@cs.vu.nl","eyal.oren@deri.org"], @email
|
104
|
+
|
105
|
+
@age.replace 30
|
106
|
+
@age[30] += 5
|
107
|
+
assert_equal [35], @age
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_delete
|
111
|
+
assert_equal "not found", @email.delete("nothing"){"not found"}
|
112
|
+
|
113
|
+
# two ways to delete
|
114
|
+
@email.delete(@email.index("eyal@cs.vu.nl"))
|
115
|
+
@email.delete("eyal.oren@deri.org")
|
116
|
+
assert_equal 0, @email.size
|
117
|
+
|
118
|
+
# delete numbers
|
119
|
+
assert_equal 1, @age.size
|
120
|
+
@age.delete(27)
|
121
|
+
assert @age.empty?
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_clear
|
125
|
+
@email.clear
|
126
|
+
assert @email.empty? # class predicates return empty RDF::Property
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_collect!
|
130
|
+
@email.collect!{|email| email + "_XX"}
|
131
|
+
assert @email == ["eyal@cs.vu.nl_XX", "eyal.oren@deri.org_XX"]
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_delete_if
|
135
|
+
@email.delete_if{|key, val| val == "eyal@cs.vu.nl"}
|
136
|
+
assert_equal ["eyal.oren@deri.org"], @email
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_equals
|
140
|
+
assert TEST::eyal.eye == "blue"
|
141
|
+
# Order doesn't matter when comparing Property to Array
|
142
|
+
assert_equal @email, ["eyal@cs.vu.nl","eyal.oren@deri.org"]
|
143
|
+
assert_equal @email, ["eyal.oren@deri.org","eyal@cs.vu.nl"]
|
144
|
+
assert_equal ["eyal@cs.vu.nl","eyal.oren@deri.org"], @email
|
145
|
+
assert_equal ["eyal.oren@deri.org","eyal@cs.vu.nl"], @email
|
146
|
+
|
147
|
+
assert_equal @email, TEST::email
|
148
|
+
assert_equal TEST::email, @email
|
149
|
+
assert_equal TEST::eyal.eye, TEST::eye
|
150
|
+
assert_equal TEST::eye, TEST::eyal.eye
|
151
|
+
|
152
|
+
# test property w/o subject
|
153
|
+
assert_equal RDF::Property.new(TEST::email), TEST::email
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_each_index
|
157
|
+
@email.each_key do |idx|
|
158
|
+
assert_not_nil @email[idx]
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_fetch
|
163
|
+
idx = @email.index("eyal@cs.vu.nl")
|
164
|
+
assert_equal "eyal@cs.vu.nl", @email.fetch(idx)
|
165
|
+
@email.delete(idx)
|
166
|
+
assert_equal "default", @email.fetch(idx,"default")
|
167
|
+
assert_equal idx, @email.fetch(idx){|i| i}
|
168
|
+
assert_raise IndexError do
|
169
|
+
@email.fetch(idx)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_include?
|
174
|
+
assert @email.include?("eyal@cs.vu.nl")
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_keys
|
178
|
+
assert_equal 2, @email.keys.size
|
179
|
+
assert @email.keys.include?("fe82da4f0b32cd8ca4f1e8eb7683fcb1")
|
180
|
+
assert @email.keys.include?("48ba5c9312b3400d28a72b637b0b3748")
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_only
|
184
|
+
assert_equal "blue", TEST::eyal.eye.only
|
185
|
+
TEST::eyal.eye.add "white"
|
186
|
+
assert_raise ActiveRdfError do
|
187
|
+
TEST::eyal.eye.only
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_lang
|
192
|
+
@adapter.load "#{File.dirname(__FILE__)}/../rdfs.nt"
|
193
|
+
ls_en = LocalizedString.new('ActiveRDF developer', '@en')
|
194
|
+
ls_de = LocalizedString.new('ActiveRDF entwickler', '@de')
|
195
|
+
TEST::eyal.comment = ls_en
|
196
|
+
TEST::eyal.comment.add ls_de
|
197
|
+
|
198
|
+
assert_equal ['en',true], TEST::eyal.comment.lang('@en').lang
|
199
|
+
assert_equal ['de',false], TEST::eyal.comment.lang('de', false).lang
|
200
|
+
|
201
|
+
assert_equal [ls_en], TEST::eyal.comment.lang('@en')
|
202
|
+
assert_equal TEST::eyal.comment.lang('@en'), TEST::eyal.comment.lang('en') # @en and en should equate
|
203
|
+
|
204
|
+
assert_equal [ls_de], TEST::eyal.comment.lang('@de')
|
205
|
+
assert_equal [ls_en, ls_de], TEST::eyal.comment
|
206
|
+
|
207
|
+
TEST::eyal.comment.add LocalizedString.new('ActiveRDF developer', 'en')
|
208
|
+
assert_equal 1, TEST::eyal.comment.lang('en').size # no duplicates
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_datatype
|
212
|
+
@adapter.load "#{File.dirname(__FILE__)}/../rdfs.nt"
|
213
|
+
t = Time.parse("Tue Jan 20 12:00:00 -0800 2009")
|
214
|
+
TEST::eyal.comment = [1, LocalizedString.new('localized string', '@en'), "string", t]
|
215
|
+
assert_equal [1], TEST::eyal.comment.datatype(XSD::integer)
|
216
|
+
assert_equal XSD::integer, TEST::eyal.comment.datatype(XSD::integer).datatype
|
217
|
+
assert_equal ["string"], TEST::eyal.comment.datatype(XSD::string) # LocalizedString != XSD::string
|
218
|
+
assert_equal [t], TEST::eyal.comment.datatype(XSD::time)
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_context
|
222
|
+
if @adapter.contexts?
|
223
|
+
@adapter.load "#{File.dirname(__FILE__)}/../test_person2_data.nt"
|
224
|
+
context_one = RDFS::Resource.new("file:#{File.dirname(__FILE__)}/../test_person_data.nt")
|
225
|
+
context_two = RDFS::Resource.new("file:#{File.dirname(__FILE__)}/../test_person2_data.nt")
|
226
|
+
assert_equal [27], RDF::Property.new(TEST::age,TEST::eyal).context(context_one)
|
227
|
+
assert_equal [], RDF::Property.new(TEST::age,TEST::eyal).context(context_two)
|
228
|
+
assert_equal [30], RDF::Property.new(TEST::age,TEST::michael).context(context_two)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_length
|
233
|
+
assert_equal 2, @email.length
|
234
|
+
assert_equal 2, @email.size
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_values_at
|
238
|
+
idx1 = @email.index("eyal@cs.vu.nl")
|
239
|
+
idx2 = @email.index("eyal.oren@deri.org")
|
240
|
+
assert_equal ["eyal@cs.vu.nl", "eyal.oren@deri.org"], @email.values_at(idx1, idx2)
|
241
|
+
assert_equal ["eyal@cs.vu.nl"], @email.values_at(idx1)
|
242
|
+
assert_equal ["eyal.oren@deri.org"], @email.values_at(idx2)
|
243
|
+
end
|
244
|
+
|
245
|
+
def test_false_value
|
246
|
+
@email = false
|
247
|
+
assert @email == false
|
248
|
+
end
|
249
|
+
|
250
|
+
if $activerdf_internal_reasoning
|
251
|
+
def test_sub_super_properties
|
252
|
+
RDF::Property.new(TEST::relative).save
|
253
|
+
RDF::Property.new(TEST::ancestor).save.rdfs::subPropertyOf = TEST::relative
|
254
|
+
RDF::Property.new(TEST::parent).save.rdfs::subPropertyOf = TEST::ancestor
|
255
|
+
RDF::Property.new(TEST::sibling).save.rdfs::subPropertyOf = TEST::relative
|
256
|
+
|
257
|
+
assert_equal Set[TEST::ancestor, TEST::parent, TEST::sibling], Set.new(TEST::relative.sub_properties)
|
258
|
+
assert_equal Set[TEST::relative, TEST::ancestor], Set.new(TEST::parent.super_properties)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
@@ -4,147 +4,239 @@
|
|
4
4
|
|
5
5
|
require 'test/unit'
|
6
6
|
require 'active_rdf'
|
7
|
-
require '
|
7
|
+
require 'set'
|
8
8
|
require "#{File.dirname(__FILE__)}/../common"
|
9
9
|
|
10
10
|
class TestResourceReading < Test::Unit::TestCase
|
11
|
-
|
12
|
-
ConnectionPool.clear
|
13
|
-
@adapter = get_adapter
|
14
|
-
@adapter.load "#{File.dirname(__FILE__)}/../test_person_data.nt"
|
15
|
-
Namespace.register(:test, 'http://activerdf.org/test/')
|
11
|
+
include SetupAdapter
|
16
12
|
|
17
|
-
|
18
|
-
end
|
13
|
+
@@eyal = TEST::eyal
|
19
14
|
|
20
|
-
def
|
15
|
+
def setup
|
16
|
+
super
|
17
|
+
test_dir = "#{File.dirname(__FILE__)}/.."
|
18
|
+
@adapter.load "#{test_dir}/rdf.nt"
|
19
|
+
@adapter.load "#{test_dir}/rdfs.nt"
|
20
|
+
@adapter.load "#{test_dir}/test_person_data.nt"
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
23
|
+
def test_class_resource_equality
|
24
|
+
p = TEST::Person
|
25
|
+
r = RDFS::Resource.new(p.uri)
|
26
|
+
assert_equal p, r
|
27
|
+
assert_equal r, p
|
28
|
+
assert p.eql?(r)
|
29
|
+
assert r.eql?(p)
|
26
30
|
end
|
27
31
|
|
28
32
|
def test_class_predicates
|
29
|
-
assert_equal
|
33
|
+
assert_equal Set[RDF::type,RDF::value,RDFS::comment,RDFS::label,RDFS::seeAlso,RDFS::isDefinedBy,RDFS::member],
|
34
|
+
Set.new(RDFS::Resource.predicates)
|
35
|
+
assert_equal Set[TEST::age, TEST::eye, TEST::car],
|
36
|
+
Set.new(TEST::Person.predicates - RDFS::Resource.predicates)
|
30
37
|
end
|
31
38
|
|
32
|
-
def
|
39
|
+
def test_resource_predicates
|
33
40
|
# assert that eyal's three direct predicates are eye, age, and type
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
41
|
+
assert_equal Set[RDF::type, TEST::age, TEST::eye, TEST::email],
|
42
|
+
Set.new(@@eyal.direct_predicates)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_resource_type
|
46
|
+
assert_instance_of RDFS::Resource, @@eyal
|
47
|
+
assert_instance_of TEST::Person, @@eyal
|
48
|
+
end
|
39
49
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
# not default rdfs:label, rdfs:comment, etc. because not using rdfs reasoning
|
44
|
-
assert_equal 5, class_preds.size
|
50
|
+
def test_resource_types
|
51
|
+
assert_equal Set[TEST::Person.class_uri, RDFS::Resource.class_uri],
|
52
|
+
Set.new(@@eyal.type)
|
45
53
|
end
|
46
54
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
assert types.include?(TEST::Person)
|
51
|
-
assert types.include?(RDFS::Resource)
|
55
|
+
def test_resource_classes
|
56
|
+
assert_equal Set[TEST::Person, RDFS::Resource],
|
57
|
+
Set.new(@@eyal.classes)
|
52
58
|
end
|
53
59
|
|
54
|
-
def
|
60
|
+
def test_resource_values
|
55
61
|
# triple exists '<eyal> age 27'
|
56
|
-
|
57
|
-
assert_equal
|
58
|
-
assert_equal
|
62
|
+
assert_kind_of RDF::Property, @@eyal.age
|
63
|
+
assert_equal 1, @@eyal.age.size
|
64
|
+
assert_equal 27, @@eyal.age.to_a.first
|
65
|
+
assert_equal @@eyal.age.to_a.first, 27
|
66
|
+
assert_equal [27], @@eyal.age
|
67
|
+
assert_equal @@eyal.age, [27]
|
68
|
+
assert_kind_of RDF::Property, @@eyal.test::age
|
69
|
+
assert_equal 1, @@eyal.test::age.size
|
70
|
+
assert_equal 27, @@eyal.test::age.to_a.first
|
71
|
+
assert_equal @@eyal.test::age.to_a.first, 27
|
72
|
+
|
73
|
+
assert_equal 27, @@eyal.age[27]
|
59
74
|
|
60
75
|
# Person has property car, but eyal has no value for it
|
61
|
-
|
62
|
-
assert_equal
|
63
|
-
|
76
|
+
assert @@eyal.car.empty?
|
77
|
+
assert_equal [], @@eyal.car
|
78
|
+
assert @@eyal.test::car.empty?
|
79
|
+
assert_equal [], @@eyal.test::car
|
80
|
+
|
81
|
+
# non-existent property returns nil
|
82
|
+
assert_nil @@eyal.non_existing_property
|
64
83
|
|
65
|
-
# non-existent
|
66
|
-
|
84
|
+
# non-existent properties thrown errors on assignment
|
85
|
+
assert_raise ActiveRdfError do
|
86
|
+
@@eyal.non_existing_property = "value"
|
87
|
+
end
|
67
88
|
end
|
68
89
|
|
69
|
-
def
|
70
|
-
|
71
|
-
|
90
|
+
def test_predicate_management
|
91
|
+
@adapter.add(TEST::hair,RDF::type,RDF::Property)
|
92
|
+
@adapter.add(TEST::hair,RDFS::domain,TEST::Person)
|
93
|
+
assert TEST::Person.predicates.include?(TEST::hair)
|
72
94
|
end
|
73
95
|
|
74
|
-
def
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
assert_equal
|
85
|
-
|
86
|
-
found = TEST::Person.find(:order => TEST::age)
|
87
|
-
assert_equal [TEST::other, TEST::eyal].sort, found.sort
|
96
|
+
def test_custom_method
|
97
|
+
TEST::Person.class_eval{def foo; "foo"; end}
|
98
|
+
assert_equal "foo", @@eyal.foo
|
99
|
+
TEST::Graduate.class_eval{def bar; "bar"; end}
|
100
|
+
assert_nil @@eyal.bar
|
101
|
+
@@eyal.type += TEST::Graduate
|
102
|
+
assert_equal "bar", @@eyal.bar
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_find_all
|
106
|
+
assert_equal Set[@@eyal, TEST::other], Set.new(TEST::Person.find_all)
|
88
107
|
end
|
89
108
|
|
90
109
|
def test_find_methods
|
91
|
-
|
92
|
-
|
110
|
+
blue = LocalizedString.new('blue','en')
|
111
|
+
nl_blauw = LocalizedString.new('blauw','nl')
|
112
|
+
@adapter.add(TEST::eyal,TEST::eye, nl_blauw)
|
113
|
+
@adapter.add(TEST::other,TEST::eye,LocalizedString.new('rot','de'))
|
114
|
+
|
115
|
+
# find all TEST::Person resources
|
116
|
+
assert_equal Set[@@eyal, TEST::other], Set.new(TEST::Person.find_all)
|
117
|
+
|
118
|
+
# find TEST::Person resources that having the property specified
|
119
|
+
assert_equal Set[@@eyal, TEST::other], Set.new(TEST::Person.find_by.age.execute)
|
120
|
+
assert_equal [@@eyal], TEST::Person.find_by.test::email.execute
|
121
|
+
|
122
|
+
# find TEST::Person resources with property matching the supplied value(s)
|
123
|
+
assert_equal [@@eyal], TEST::Person.find_by.age(27).execute
|
124
|
+
assert_equal [@@eyal], TEST::Person.find_by.test::age(27).execute
|
125
|
+
assert_equal [@@eyal], TEST::Person.find_by.test::email('eyal@cs.vu.nl','eyal.oren@deri.org').execute
|
126
|
+
assert_equal [@@eyal], TEST::Person.find_by.test::email(['eyal@cs.vu.nl','eyal.oren@deri.org']).execute
|
127
|
+
assert_equal [@@eyal], TEST::Person.find_by.eye(blue).execute
|
128
|
+
|
129
|
+
# find TEST::Person resources with property matching the supplied value ignoring lang/datatypes
|
130
|
+
assert_equal [@@eyal], TEST::Person.find_by.eye('blue').execute(:all_types => true)
|
131
|
+
assert_equal [], TEST::Person.find_by.eye('blue').execute
|
132
|
+
|
133
|
+
# find RDFS::Resources having property matching the supplied value ignoring lang/datatypes
|
134
|
+
assert_equal [@@eyal], RDFS::Resource.find_by.test::eye('blue').execute(:all_types => true)
|
135
|
+
assert_equal [], RDFS::Resource.find_by.test::eye('blue').execute
|
136
|
+
|
137
|
+
# find TEST::Person resources with property having the specified language
|
138
|
+
assert_equal [@@eyal], TEST::Person.find_by.eye(:lang => '@en').execute
|
139
|
+
assert_equal [@@eyal], TEST::Person.find_by.eye(:lang => '@nl').execute
|
140
|
+
assert_equal [TEST::other], TEST::Person.find_by.eye(:lang => '@de').execute
|
141
|
+
|
142
|
+
# find TEST::Person resources with property having the specified datatype
|
143
|
+
assert_equal Set[@@eyal, TEST::other], Set.new(TEST::Person.find_by.age(:datatype => XSD::integer).execute)
|
144
|
+
TEST::other.age = "twenty"
|
145
|
+
assert_equal [@@eyal], TEST::Person.find_by.age(:datatype => XSD::integer).execute
|
146
|
+
|
147
|
+
# combining lang/datatype specifiers with all_types is prohibited
|
148
|
+
assert_raise ActiveRdfError do
|
149
|
+
TEST::Person.find_by.eye(:lang => '@en').execute(:all_types => true)
|
150
|
+
end
|
151
|
+
assert_raise ActiveRdfError do
|
152
|
+
TEST::Person.find_by.age(:datatype => XSD::integer).execute(:all_types => true)
|
153
|
+
end
|
93
154
|
|
94
|
-
|
95
|
-
assert_equal [
|
155
|
+
# chain multiple properties together, ANDing restrictions
|
156
|
+
assert_equal [@@eyal], TEST::Person.find_by.age(27).eye(blue).execute
|
96
157
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
end
|
158
|
+
# raise error for properties not in domain (fully qualified name required)
|
159
|
+
assert_raise ActiveRdfError do
|
160
|
+
RDFS::Resource.find_by.age(27).execute
|
161
|
+
end
|
102
162
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
163
|
+
# find RDFS::Resources having the fully qualified property
|
164
|
+
assert_equal [@@eyal], RDFS::Resource.find_by.test::email.execute
|
165
|
+
|
166
|
+
# find RDFS::Resources having the fully qualified property and value
|
167
|
+
assert_equal [@@eyal], RDFS::Resource.find_by.test::age(27).execute
|
168
|
+
assert_equal [@@eyal], RDFS::Resource.find_by.test::eye(blue).execute
|
169
|
+
|
170
|
+
# find RDFS::Resources with multiple chained properties
|
171
|
+
assert_equal [@@eyal], TEST::Person.find_by.age(27).eye(blue).execute
|
172
|
+
assert_equal [@@eyal], TEST::Person.find_by.age(27).test::eye(blue).execute
|
173
|
+
assert_equal [@@eyal], TEST::Person.find_by.test::age(27).eye(blue).execute
|
174
|
+
assert_equal [@@eyal], TEST::Person.find_by.test::age(27).test::eye(blue).execute
|
175
|
+
|
176
|
+
# bug 62481
|
177
|
+
camelCaseProperty = RDF::Property.new(TEST::camelCaseProperty).save
|
178
|
+
camelCaseProperty.domain = TEST::Person
|
179
|
+
@@eyal.camelCaseProperty = "a CamelCase property name"
|
180
|
+
assert_equal [@@eyal], TEST::Person.find_by.camelCaseProperty.execute
|
181
|
+
assert_equal [@@eyal], TEST::Person.find_by.test::camelCaseProperty.execute
|
182
|
+
assert_equal [@@eyal], TEST::Person.find_by.camelCaseProperty("a CamelCase property name").execute
|
183
|
+
|
184
|
+
underscored_property = RDF::Property.new(TEST::underscored_property).save
|
185
|
+
underscored_property.domain = TEST::Person
|
186
|
+
@@eyal.underscored_property = "an underscored property name"
|
187
|
+
assert_equal [@@eyal], TEST::Person.find_by.underscored_property.execute
|
188
|
+
assert_equal [@@eyal], TEST::Person.find_by.test::underscored_property.execute
|
189
|
+
assert_equal [@@eyal], TEST::Person.find_by.underscored_property("an underscored property name").execute
|
190
|
+
|
191
|
+
mixedCamelCase_underscored_property = RDF::Property.new(TEST::mixedCamelCase_underscored_property).save
|
192
|
+
mixedCamelCase_underscored_property.domain = TEST::Person
|
193
|
+
@@eyal.mixedCamelCase_underscored_property = "a mixed CamelCase and underscored property"
|
194
|
+
assert_equal [@@eyal], TEST::Person.find_by.mixedCamelCase_underscored_property.execute
|
195
|
+
assert_equal [@@eyal], TEST::Person.find_by.test::mixedCamelCase_underscored_property.execute
|
196
|
+
assert_equal [@@eyal], TEST::Person.find_by.mixedCamelCase_underscored_property("a mixed CamelCase and underscored property").execute
|
197
|
+
|
198
|
+
# Sqlite doesn't support regular expressions by default
|
199
|
+
unless ConnectionPool.write_adapter.class == ActiveRDF::RDFLite
|
200
|
+
# find TEST::Person resources with property matching the specified regex
|
201
|
+
assert_equal [@@eyal], TEST::Person.find_by.age(:regex => /7/).execute
|
202
|
+
assert_equal [@@eyal], TEST::Person.find_by.eye(:regex => /lu/).execute
|
203
|
+
assert_equal [TEST::other], TEST::Person.find_by.eye(:regex => /ot/).execute
|
204
|
+
end
|
108
205
|
end
|
109
206
|
|
207
|
+
|
110
208
|
def test_finders_with_options
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
209
|
+
blue = LocalizedString.new('blue','en')
|
210
|
+
|
211
|
+
assert_equal Set[TEST::car, TEST::age, TEST::eye], Set.new(RDF::Property.find_by.rdfs::domain(TEST::Person).execute)
|
212
|
+
|
213
|
+
assert_equal 2, RDFS::Resource.find_all.size
|
214
|
+
assert_equal 2, RDFS::Resource.find_all(:limit => 10).size
|
215
|
+
assert_equal 1, RDFS::Resource.find_all(:limit => 1).size
|
216
|
+
|
217
|
+
if @adapter.contexts?
|
218
|
+
file = "#{File.dirname(__FILE__)}/../test_person2_data.nt"
|
219
|
+
@adapter.load(file)
|
220
|
+
context_one = RDFS::Resource.new("file:#{File.dirname(__FILE__)}/../test_person_data.nt")
|
221
|
+
context_two = RDFS::Resource.new("file:#{file}")
|
222
|
+
|
223
|
+
assert_equal 2, RDFS::Resource.find_all(:context => context_one).size
|
224
|
+
assert_equal 1, RDFS::Resource.find_all(:context => context_two).size
|
225
|
+
assert_equal 1, RDFS::Resource.find_all(:context => context_one, :limit => 1).size
|
226
|
+
|
227
|
+
# Redland doesn't support querying more than one context at a time as of Feb 2009
|
228
|
+
assert_equal [@@eyal], TEST::Person.find_by.age(27,:context => context_one).execute
|
229
|
+
assert_equal [], TEST::Person.find_by.eye('blue', :context => context_one).execute
|
230
|
+
assert_equal [@@eyal], TEST::Person.find_by.eye('blue', :context => context_one).execute(:all_types => true)
|
231
|
+
assert_equal [@@eyal], TEST::Person.find_by.eye(blue, :context => context_one).execute
|
232
|
+
assert_equal [], TEST::Person.find_by.eye(blue, :context => context_two).execute
|
124
233
|
end
|
125
|
-
|
126
|
-
assert_equal 2, RDFS::Resource.find.size
|
127
|
-
assert_equal 2, RDFS::Resource.find(:all).size
|
128
|
-
assert_equal 2, RDFS::Resource.find(:all, :limit => 10).size
|
129
|
-
assert_equal 1, RDFS::Resource.find(:all, :limit => 1).size
|
130
|
-
assert_equal 1, RDFS::Resource.find(:all, :context => one).size
|
131
|
-
assert_equal 1, RDFS::Resource.find(:all, :context => one, :limit => 1).size
|
132
|
-
assert_equal 0, RDFS::Resource.find(:all, :context => one, :limit => 0).size
|
133
|
-
|
134
|
-
assert_equal 1, RDFS::Resource.find_by_eye('blue').size
|
135
|
-
assert_equal 1, RDFS::Resource.find_by_eye('blue', :context => one).size
|
136
|
-
assert_equal 0, RDFS::Resource.find_by_eye('blue', :context => two).size
|
137
|
-
|
138
|
-
assert_equal 2, RDFS::Resource.find_by_rdf::type(RDFS::Resource).size
|
139
|
-
assert_equal 1, RDFS::Resource.find_by_rdf::type(RDFS::Resource, :context => one).size
|
140
|
-
assert_equal 1, RDFS::Resource.find_by_eye_and_rdf::type('blue', RDFS::Resource, :context => one).size
|
141
234
|
end
|
142
235
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
@eyal.age {|query, obj| query.lang(obj, "nl"); assert_equal qs.gsub("\n",'').strip, query.to_sp.strip}
|
236
|
+
# test for writing if no write adapter is defined (like only sparqls)
|
237
|
+
def test_write_without_write_adapter
|
238
|
+
ConnectionPool.clear
|
239
|
+
get_read_only_adapter
|
240
|
+
assert_raises(ActiveRdfError) { @@eyal.test::age = 18 }
|
149
241
|
end
|
150
242
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'active_rdf'
|
2
|
+
if $activerdf_internal_reasoning
|
3
|
+
require 'test/unit'
|
4
|
+
require 'set'
|
5
|
+
require "#{File.dirname(__FILE__)}/../common"
|
6
|
+
|
7
|
+
class TestResourceReasoning < Test::Unit::TestCase
|
8
|
+
include SetupAdapter
|
9
|
+
|
10
|
+
def setup
|
11
|
+
super
|
12
|
+
test_dir = "#{File.dirname(__FILE__)}/.."
|
13
|
+
@adapter.load "#{test_dir}/rdf.nt"
|
14
|
+
@adapter.load "#{test_dir}/rdfs.nt"
|
15
|
+
@adapter.load "#{test_dir}/test_person_data.nt"
|
16
|
+
@adapter.load "#{test_dir}/test_relations.nt"
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_person
|
20
|
+
assert_equal Set[TEST::age, TEST::car, TEST::eye, TEST::ancestor, TEST::child, TEST::parent, TEST::relative, TEST::sibling] | RDFS::Resource.predicates,
|
21
|
+
Set.new(TEST::Person.predicates)
|
22
|
+
end
|
23
|
+
|
24
|
+
# TODO: add more tests
|
25
|
+
end
|
26
|
+
end
|