rtm 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/DISCLAIMER +10 -33
  2. data/LICENSE +201 -0
  3. data/README +3 -3
  4. data/lib/rtm.rb +148 -74
  5. data/lib/rtm/axes.rb +295 -0
  6. data/lib/rtm/axes/association.rb +76 -0
  7. data/lib/rtm/axes/associations.rb +96 -0
  8. data/lib/rtm/axes/assocs_names_occs.rb +56 -0
  9. data/lib/rtm/axes/characteristic.rb +68 -0
  10. data/lib/rtm/axes/characteristics.rb +93 -0
  11. data/lib/rtm/axes/string.rb +76 -0
  12. data/lib/rtm/axes/strings.rb +87 -0
  13. data/lib/rtm/axes/topic.rb +233 -0
  14. data/lib/rtm/axes/topics.rb +280 -0
  15. data/lib/rtm/{backward_compatibility.rb → deprecated/index_property_set.rb} +3 -0
  16. data/lib/rtm/engine.rb +58 -0
  17. data/lib/rtm/extensions.rb +11 -1
  18. data/lib/rtm/{locator_helpers.rb → helpers/locator.rb} +15 -4
  19. data/lib/rtm/{helpers.rb → helpers/no_output.rb} +3 -0
  20. data/lib/rtm/helpers/uri.rb +13 -0
  21. data/lib/rtm/io.rb +18 -0
  22. data/lib/rtm/io/from_xtm2_libxml.rb +2 -1
  23. data/lib/rtm/io/ontopia_io.rb +25 -0
  24. data/lib/rtm/io/tmapix.rb +234 -0
  25. data/lib/rtm/io/to_hash.rb +116 -0
  26. data/lib/rtm/io/to_jtm.rb +53 -103
  27. data/lib/rtm/io/to_rdf.rb +30 -0
  28. data/lib/rtm/io/to_string.rb +8 -6
  29. data/lib/rtm/io/to_xtm1.rb +6 -4
  30. data/lib/rtm/io/to_xtm2.rb +10 -8
  31. data/lib/rtm/io/to_yaml.rb +29 -98
  32. data/lib/rtm/navigation.rb +37 -0
  33. data/lib/rtm/navigation/association/players.rb +25 -0
  34. data/lib/rtm/navigation/name/atomify.rb +19 -0
  35. data/lib/rtm/navigation/name/characteristics.rb +33 -0
  36. data/lib/rtm/navigation/occurrence/atomify.rb +19 -0
  37. data/lib/rtm/navigation/occurrence/characteristics.rb +33 -0
  38. data/lib/rtm/navigation/topic/characteristics.rb +33 -0
  39. data/lib/rtm/navigation/topic/indicators.rb +31 -0
  40. data/lib/rtm/navigation/topic/items.rb +31 -0
  41. data/lib/rtm/navigation/topic/locators.rb +31 -0
  42. data/lib/rtm/navigation/topic/players.rb +27 -0
  43. data/lib/rtm/navigation/topic/supertypes.rb +162 -0
  44. data/lib/rtm/navigation/topic/traverse.rb +51 -0
  45. data/lib/rtm/navigation/topic/types.rb +107 -0
  46. data/lib/rtm/psi.rb +33 -2
  47. data/lib/rtm/sugar.rb +34 -0
  48. data/lib/rtm/sugar/association/hash_access.rb +46 -0
  49. data/lib/rtm/sugar/occurrence/dynamic_value.rb +75 -0
  50. data/lib/rtm/{pimp_my_api.rb → sugar/occurrence/externalize.rb} +3 -0
  51. data/lib/rtm/sugar/role/counterparts.rb +133 -46
  52. data/lib/rtm/sugar/topic/characteristics.rb +126 -12
  53. data/lib/rtm/sugar/topic/counterparts.rb +130 -7
  54. data/lib/rtm/sugar/topic/hash_access.rb +140 -30
  55. data/lib/rtm/sugar/topic/scoped.rb +65 -0
  56. data/lib/rtm/sugar/topic/topic_ref.rb +35 -0
  57. data/lib/rtm/sugar/topic/typed.rb +159 -0
  58. data/lib/rtm/sugar/typed/types.rb +38 -0
  59. data/lib/rtm/validation.rb +8 -5
  60. data/lib/rtm/version.rb +18 -0
  61. data/spec/helpers/spec_exampleexamplegroup.rb +14 -0
  62. data/spec/rtm/axes/association_spec.rb +88 -0
  63. data/spec/rtm/axes/associations_spec.rb +60 -0
  64. data/spec/rtm/axes/assocs_names_occs_spec.rb +9 -0
  65. data/spec/rtm/axes/characteristic_spec.rb +90 -0
  66. data/spec/rtm/axes/characteristics_spec.rb +85 -0
  67. data/spec/rtm/axes/string_spec.rb +145 -0
  68. data/spec/rtm/axes/strings_spec.rb +168 -0
  69. data/spec/rtm/axes/topic_spec.rb +124 -0
  70. data/spec/rtm/axes/topics_spec.rb +103 -0
  71. data/spec/rtm/base_spec.rb +32 -0
  72. data/spec/rtm/io/tmapix_spec.rb +85 -0
  73. data/spec/rtm/navigation/association/players_spec.rb +58 -0
  74. data/spec/rtm/navigation/association_spec.rb +52 -0
  75. data/spec/rtm/navigation/name/atomify_spec.rb +27 -0
  76. data/spec/rtm/navigation/name/characteristics_spec.rb +34 -0
  77. data/spec/rtm/navigation/name_spec.rb +52 -0
  78. data/spec/rtm/navigation/occurrence/atomify_spec.rb +27 -0
  79. data/spec/rtm/navigation/occurrence/characteristics_spec.rb +34 -0
  80. data/spec/rtm/navigation/occurrence_spec.rb +52 -0
  81. data/spec/rtm/navigation/string_spec.rb +51 -0
  82. data/spec/rtm/navigation/topic/characteristics_spec.rb +55 -0
  83. data/spec/rtm/navigation/topic/indicators_spec.rb +43 -0
  84. data/spec/rtm/navigation/topic/items_spec.rb +44 -0
  85. data/spec/rtm/navigation/topic/locators_spec.rb +44 -0
  86. data/spec/rtm/navigation/topic/players_spec.rb +48 -0
  87. data/spec/rtm/navigation/topic/scope_spec.rb +41 -0
  88. data/spec/rtm/navigation/topic/supertypes_spec.rb +376 -0
  89. data/spec/rtm/navigation/topic/traverse_spec.rb +64 -0
  90. data/spec/rtm/navigation/topic/types_spec.rb +195 -0
  91. data/spec/rtm/navigation/topic_spec.rb +153 -0
  92. data/spec/rtm/sugar/association/hash_access_spec.rb +55 -0
  93. data/spec/rtm/sugar/occurrence/dynamic_value_spec.rb +16 -0
  94. data/spec/rtm/sugar/role/counterparts_spec.rb +191 -0
  95. data/spec/rtm/sugar/topic/characteristics_spec.rb +318 -0
  96. data/spec/rtm/sugar/topic/counterparts_spec.rb +184 -0
  97. data/spec/rtm/sugar/topic/hash_access_spec.rb +234 -0
  98. data/spec/rtm/sugar/topic/scoped_spec.rb +131 -0
  99. data/spec/rtm/sugar/topic/topic_ref_spec.rb +44 -0
  100. data/spec/rtm/sugar/topic/typed_spec.rb +155 -0
  101. data/spec/rtm/sugar/typed/types_spec.rb +24 -0
  102. data/spec/rtm/tmapi/core/association_spec.rb +169 -0
  103. data/spec/rtm/tmapi/core/construct_spec.rb +25 -0
  104. data/spec/rtm/tmapi/core/name_spec.rb +85 -0
  105. data/spec/rtm/tmapi/core/occurrence_spec.rb +96 -0
  106. data/spec/rtm/tmapi/core/reifiable_spec.rb +168 -0
  107. data/spec/rtm/tmapi/core/role_spec.rb +73 -0
  108. data/spec/rtm/tmapi/core/scoped_spec.rb +403 -0
  109. data/spec/rtm/tmapi/core/topic_map_spec.rb +648 -0
  110. data/spec/rtm/tmapi/core/topic_spec.rb +992 -0
  111. data/spec/rtm/tmapi/core/typed_spec.rb +112 -0
  112. data/spec/rtm/tmapi/core/variant_spec.rb +52 -0
  113. data/spec/rtm/tmapi/ext/java_util_set_spec.rb +34 -0
  114. data/spec/rtm/tmapi_spec.rb +44 -0
  115. data/spec/rtm/utils/sparql_spec.rb +26 -0
  116. data/spec/rtm_spec.rb +94 -0
  117. data/spec/spec_helper.rb +23 -0
  118. data/test/base_unit_test.rb +161 -0
  119. data/test/{base_test.rb → base_unit_test_tmapi.rb} +46 -43
  120. metadata +122 -66
  121. data/COPYRIGHT +0 -4
  122. data/lib/Rakefile.rb +0 -42
  123. data/lib/activetopicmaps.rb +0 -278
  124. data/lib/rtm/backend/active_record.rb +0 -58
  125. data/lib/rtm/backend/active_record/001_initial_schema.rb +0 -116
  126. data/lib/rtm/backend/active_record/association_and_role.rb +0 -33
  127. data/lib/rtm/backend/active_record/locators.rb +0 -55
  128. data/lib/rtm/backend/active_record/name_variant_occurrence.rb +0 -45
  129. data/lib/rtm/backend/active_record/quaaxtm2rtm.rb +0 -113
  130. data/lib/rtm/backend/active_record/quaaxtm2rtmviews.rb +0 -134
  131. data/lib/rtm/backend/active_record/set_wrapper.rb +0 -98
  132. data/lib/rtm/backend/active_record/tm_construct.rb +0 -62
  133. data/lib/rtm/backend/active_record/tm_delegator.rb +0 -345
  134. data/lib/rtm/backend/active_record/tm_set_delegator.rb +0 -195
  135. data/lib/rtm/backend/active_record/tmdm.rb +0 -298
  136. data/lib/rtm/backend/active_record/topic.rb +0 -87
  137. data/lib/rtm/backend/active_record/topic_map.rb +0 -314
  138. data/lib/rtm/backend/active_record/traverse_associations.rb +0 -87
  139. data/lib/rtm/base.rb +0 -92
  140. data/lib/rtm/connect.rb +0 -92
  141. data/lib/rtm/core_ext.rb +0 -6
  142. data/lib/rtm/io/from_xtm2.rb +0 -263
  143. data/lib/rtm/merging/merging.rb +0 -307
  144. data/lib/rtm/sugar/topic/identifier_direct.rb +0 -11
  145. data/lib/rtm/sugar/topic/predefined_associations.rb +0 -42
  146. data/lib/run_main_project.rb +0 -16
@@ -0,0 +1,648 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ require File.dirname(__FILE__) + '/../../../spec_helper'
5
+
6
+ module RTM::TopicMap
7
+ describe self do
8
+ before(:each) do
9
+ @tm = get_used_tm_sys_tm
10
+ @tm.should be_a_kind_of RTM::TopicMap
11
+ end
12
+ after(:each) do
13
+ @tm.close
14
+ end
15
+
16
+ describe "#topics" do
17
+ before(:each) do
18
+ @a,@b,@c,@d,@e,@f = @tm.get!(["a","b","c","d","e","f"])
19
+ @a.add_type(@b)
20
+ @d.add_type(@f)
21
+ @e.add_type(@f)
22
+ end
23
+ it "should give back all topics in the topic map when called without type" do
24
+ @tm.topics.size.should == 6
25
+ @tm.topics.should include(@a,@b,@c,@d,@e,@f)
26
+ end
27
+ it "should give back all topics that are instances of the specified type" do
28
+ @tm.topics(@b).size.should == 1
29
+ @tm.topics("b").should include(@a)
30
+ ###
31
+ @tm.topics(@f).size.should == 2
32
+ @tm.topics("f").should include(@d,@e)
33
+ ###
34
+ @tm.topics(@c).should be_empty
35
+ @tm.topics("c").should be_empty
36
+ ###
37
+ @tm.topics("not_existing").should be_empty
38
+ end
39
+ end
40
+
41
+ describe "#construct_by_id" do
42
+ it "should give back the topic map if the id of the topic map is given" do
43
+ pending if implementation_for_spec == :tinytim
44
+ @tm.construct_by_id(@tm.id).should_not be_nil
45
+ @tm.construct_by_id(@tm.id).should == @tm
46
+ end
47
+ end
48
+
49
+ describe "#add_prefix" do
50
+ it "should raise an error if the identifier or reference are not Strings" do
51
+ lambda{@tm.add_prefix(1,"www.test.de")}.should raise_error
52
+ lambda{@tm.add_prefix("a",2)}.should raise_error
53
+ end
54
+ it "should be allowed to set a prefix" do
55
+ @tm.prefixes.should be_empty
56
+ @tm.add_prefix("a","www.qnametest.com")
57
+ @tm.prefixes.size.should == 1
58
+ @tm.prefixes["a"].should == "www.qnametest.com"
59
+ end
60
+ it "should replace the reference if prefix already exists" do
61
+ @tm.add_prefix("a","www.qnametest.com")
62
+ @tm.prefixes["a"].should == "www.qnametest.com"
63
+ @tm.add_prefix("a","www.test.de")
64
+ @tm.prefixes["a"].should == "www.test.de"
65
+ end
66
+ it "should give back the prefixes-Hash" do
67
+ @tm.add_prefix("a","www.qnametest.com").should == @tm.prefixes
68
+ @tm.add_prefix("g","www.qnametest2.com").should == @tm.prefixes
69
+ end
70
+ # it "should warn if identifier equals sl, si or ii" do
71
+ # lambda{@tm.add_prefix("sl","test")}.should ?
72
+ # lambda{@tm.add_prefix("si","test")}.should ?
73
+ # lambda{@tm.add_prefix("ii","test")}.should ?
74
+ # end
75
+ end
76
+
77
+ describe "#delete_prefix" do
78
+ before(:each) do
79
+ @tm.add_prefix("a","www.qnametest.com/a/")
80
+ @tm.add_prefix("b","www.qnametest.com/b/")
81
+ @tm.add_prefix("c","www.qnametest.com/c/")
82
+ end
83
+ it "should delete the right prefix" do
84
+ @tm.prefixes.length.should == 3
85
+ @tm.delete_prefix("a").size.should == 2
86
+ @tm.find_prefix(:identifier => "a").should be_empty
87
+ @tm.find_prefix(:identifier => "b").should_not be_empty
88
+ @tm.find_prefix(:identifier => "c").should_not be_empty
89
+ end
90
+ it "should delete the right prefix if the reference is given" do
91
+ @tm.prefixes.length.should == 3
92
+ @tm.delete_prefix("a","www.qnametest.com/a/").size.should == 2
93
+ @tm.find_prefix(:identifier => "a").should be_empty
94
+ @tm.find_prefix(:identifier => "b").should_not be_empty
95
+ @tm.find_prefix(:identifier => "c").should_not be_empty
96
+ end
97
+ it "should delete nothing if identifier does not match" do
98
+ @tm.prefixes.length.should == 3
99
+ @tm.delete_prefix("x").size.should == 3
100
+ @tm.find_prefix(:identifier => "a").should_not be_empty
101
+ @tm.find_prefix(:identifier => "b").should_not be_empty
102
+ @tm.find_prefix(:identifier => "c").should_not be_empty
103
+ end
104
+ it "should delete nothing if reference does not match" do
105
+ @tm.prefixes.length.should == 3
106
+ @tm.delete_prefix("a","x").size.should == 3
107
+ @tm.find_prefix(:identifier => "a").should_not be_empty
108
+ @tm.find_prefix(:identifier => "b").should_not be_empty
109
+ @tm.find_prefix(:identifier => "c").should_not be_empty
110
+ end
111
+ it "should be the alias for del_prefix" do
112
+ @tm.method(:del_prefix).should == @tm.method(:delete_prefix)
113
+ end
114
+ end
115
+
116
+ describe "#find_prefix" do
117
+
118
+ end
119
+
120
+ describe "#create_topic_by" do
121
+ it "should allow creating a new topic by subject identifier" do
122
+ identifier = "subject:identifier"
123
+ topics = @tm.create_topic_by([identifier])
124
+ topics.should be_a_kind_of Array
125
+ topics.length.should == 1
126
+ topic = topics.first
127
+ topic.should be_a_kind_of RTM::Topic
128
+ topic.getSubjectIdentifiers.size.should == 1
129
+ topic.getSubjectIdentifiers.map{|i| i.value }.should include(identifier)
130
+ end
131
+ it "should allow creating a new topic by item identifier with ^-prefix" do
132
+ identifier = "item:identifier"
133
+ topic = @tm.create_topic_by("^" + identifier)
134
+ topic.should be_a_kind_of RTM::Topic
135
+ topic.getItemIdentifiers.size.should == 1
136
+ topic.getItemIdentifiers.map{|i| i.value }.should include(identifier)
137
+ end
138
+ it "should allow creating a new topic by subject locator with =-prefix" do
139
+ identifier = "subject:locator"
140
+ topic = @tm.create_topic_by("=" + identifier)
141
+ topic.should be_a_kind_of RTM::Topic
142
+ topic.getSubjectLocators.size.should == 1
143
+ topic.getSubjectLocators.map{|i| i.value }.should include(identifier)
144
+ end
145
+ it "should allow creating a new topic by subject identifier with si:-prefix" do
146
+ identifier = "subject:identifier"
147
+ topic = @tm.create_topic_by("si:" + identifier)
148
+ topic.should be_a_kind_of RTM::Topic
149
+ topic.getSubjectIdentifiers.size.should == 1
150
+ topic.getSubjectIdentifiers.map{|i| i.value }.should include(identifier)
151
+ end
152
+ it "should allow creating a new topic by item identifier with ii:-prefix" do
153
+ identifier = "item:identifier"
154
+ topic = @tm.create_topic_by("ii:" + identifier)
155
+ topic.should be_a_kind_of RTM::Topic
156
+ topic.getItemIdentifiers.size.should == 1
157
+ topic.getItemIdentifiers.map{|i| i.value }.should include(identifier)
158
+ end
159
+ it "should allow creating new topics by an Array of identifiers" do
160
+ identifier = ["subject:identifier",
161
+ "^item:identifier",
162
+ "subject:locator",
163
+ "si:subject:identifier",
164
+ "ii:item:identifier"
165
+ ]
166
+ identifier.should be_a_kind_of Array
167
+ topic_array = @tm.create_topic_by(identifier)
168
+ topic_array.should be_a_kind_of Array
169
+ topic_array.size.should == identifier.length
170
+ topic_array.each{|t| t.should be_a_kind_of RTM::Topic}
171
+ end
172
+ end
173
+
174
+ describe "#get" do
175
+ before(:each) do
176
+ @topic1 = @tm.create_topic_by_subject_identifier("si")
177
+ @tm.create_topic_by_subject_identifier("si-test")
178
+ @topic2 = @tm.create_topic_by_subject_locator("sl")
179
+ @tm.create_topic_by_subject_locator("sl-test")
180
+ @topic3 = @tm.create_topic_by_item_identifier("ii")
181
+ @tm.create_topic_by_item_identifier("ii-test")
182
+ end
183
+ it "should be tested with Topics" do
184
+ @topic1.should be_a_kind_of RTM::Topic
185
+ @topic2.should be_a_kind_of RTM::Topic
186
+ @topic3.should be_a_kind_of RTM::Topic
187
+ end
188
+ it "should give back nil if argument is nil" do
189
+ @tm.get(nil).should be_nil
190
+ end
191
+ it "should give back nil if argument is an empty String" do
192
+ @tm.get("").should be_nil
193
+ end
194
+ it "should give back nil if argument equals 'si:'" do
195
+ @tm.get("si:").should be_nil
196
+ end
197
+ it "should give back nil if argument equals '='" do
198
+ @tm.get("=").should be_nil
199
+ end
200
+ it "should give back nil if argument equals 'sl:'" do
201
+ @tm.get("sl:").should be_nil
202
+ end
203
+ it "should give back nil if argument equals '^'" do
204
+ @tm.get("^").should be_nil
205
+ end
206
+ it "should give back nil if argument equals 'ii:'" do
207
+ @tm.get("ii:").should be_nil
208
+ end
209
+ it "should give back a Topic if argument is a Topic" do
210
+ @tm.get(@topic1).should == @topic1
211
+ @tm.get(@topic2).should == @topic2
212
+ @tm.get(@topic3).should == @topic3
213
+ end
214
+ it "should give back a Topic if argument is a Locator and Topic has the Locator as subject identifier" do
215
+ @tm.get(@tm.create_locator("si")).should == @topic1
216
+ end
217
+ it "should give back a Topic if argument is a Locator and Topic has the Locator as item identifier" do
218
+ @tm.get(@tm.create_locator("ii")).should == @topic3
219
+ end
220
+ it "should give back nil if argument is a Locator and Topic has the Locator as subject locator" do
221
+ @tm.get(@tm.create_locator("sl")).should be_nil
222
+ end
223
+ it "should give back a Topic if argument is a String (absolute) and Topic has String as subject identifier" do
224
+ @tm.get("http://www.topicmapslab.de/si").should == @topic1
225
+ @tm.get("si:http://www.topicmapslab.de/si").should == @topic1
226
+ end
227
+ it "should give back a Topic if argument is a String (absolute) and Topic has String as subject identifier" do
228
+ @tm.get("sl:http://www.topicmapslab.de/sl").should == @topic2
229
+ @tm.get("=http://www.topicmapslab.de/sl").should == @topic2
230
+ end
231
+ it "should give back a Topic if argument is a String (absolute) and Topic has String as subject identifier" do
232
+ @tm.get("ii:http://www.topicmapslab.de/ii").should == @topic3
233
+ @tm.get("^http://www.topicmapslab.de/ii").should == @topic3
234
+ end
235
+ it "should give back a Topic if argument is a String (relative) and Topic has String as subject identifier" do
236
+ @tm.get("si").should == @topic1
237
+ @tm.get("si:si").should == @topic1
238
+ end
239
+ it "should give back a Topic if argument is a String (relative) and Topic has String as subject identifier" do
240
+ @tm.get("sl:sl").should == @topic2
241
+ @tm.get("=sl").should == @topic2
242
+ end
243
+ it "should give back a Topic if argument is a String (relative) and Topic has String as subject identifier" do
244
+ @tm.get("ii:ii").should == @topic3
245
+ @tm.get("^ii").should == @topic3
246
+ end
247
+ it "should give back an empty Array if argument equals '[]'" do
248
+ @tm.get([]).should == []
249
+ end
250
+ it "should give back nil if there is no Topic which has the argument (Locator) as identifier" do
251
+ @tm.get(@tm.create_locator("something")).should be_nil
252
+ end
253
+ it "should give back nil if there is no Topic which has the argument (String, si) as identifier" do
254
+ @tm.get("something").should be_nil
255
+ @tm.get("http://www.topicmapslab.de/something").should be_nil
256
+ @tm.get("si:something").should be_nil
257
+ @tm.get("si:http://www.topicmapslab.de/something").should be_nil
258
+ end
259
+ it "should give back nil if there is no Topic which has the argument (String, sl) as identifier" do
260
+ @tm.get("sl:something").should be_nil
261
+ @tm.get("sl:http://www.topicmapslab.de/something").should be_nil
262
+ @tm.get("=something").should be_nil
263
+ @tm.get("=http://www.topicmapslab.de/something").should be_nil
264
+ end
265
+ it "should give back nil if there is no Topic which has the argument (String, ii) as identifier" do
266
+ @tm.get("ii:something").should be_nil
267
+ @tm.get("ii:http://www.topicmapslab.de/something").should be_nil
268
+ @tm.get("^something").should be_nil
269
+ @tm.get("^http://www.topicmapslab.de/something").should be_nil
270
+ end
271
+ it "should give back an Array of Topics and nils if argument is Array of identifiers and nils" do
272
+ array = ["si","","=sl","",nil,"something","^ii",@tm.create_locator("blub")]
273
+ @tm.get(array).size.should == array.size
274
+ @tm.get(array).should == array.map{|i| @tm.get(i)}
275
+ end
276
+ it "should handle identifier which are qnames (get)" do
277
+ @tm.add_prefix("x","http://www.test.de/x/")
278
+ @tm.add_prefix("y","http://www.test.de/y/")
279
+ topic = @tm.create_topic_by_subject_identifier("http://www.test.de/x/something")
280
+ @tm.get("x:something").should == topic
281
+ topic2 = @tm.create_topic_by_item_identifier("http://www.test.de/y/something")
282
+ @tm.get("ii:y:something").should == topic2
283
+ end
284
+ end
285
+
286
+ describe "#get!" do
287
+ before(:each) do
288
+ @tm.create_topic_by_subject_identifier("dummy_si")
289
+ @tm.create_topic_by_subject_locator("dummy_sl")
290
+ @tm.create_topic_by_item_identifier("dummy_ii")
291
+ end
292
+ it "should give back nil if the argument is nil" do
293
+ @tm.get!(nil).should be_nil
294
+ end
295
+ it "should give back an empty Array if the argument equals []" do
296
+ @tm.get!([]).should == []
297
+ end
298
+ it "should give back the argument if argument is a Topic" do
299
+ topic = @tm.create_topic
300
+ topic.should be_a_kind_of RTM::Topic
301
+ @tm.get!(topic).should == topic
302
+ end
303
+ it "should give back a Topic if argument is a Locator and the Topic defined by the Locator (si) already exists" do
304
+ locator = @tm.create_locator("http://www.uni-leipzig.de")
305
+ locator.should be_a_kind_of RTM::Locator
306
+ topic = @tm.create_topic_by_subject_identifier(locator)
307
+ topic.should be_a_kind_of RTM::Topic
308
+ @tm.get!(locator).should == topic
309
+ end
310
+ it "should give back a Topic if argument is a Locator and the Topic defined by the Locator (ii) already exists" do
311
+ locator = @tm.create_locator("http://www.uni-leipzig.de")
312
+ locator.should be_a_kind_of RTM::Locator
313
+ topic = @tm.create_topic_by_item_identifier(locator)
314
+ topic.should be_a_kind_of RTM::Topic
315
+ @tm.get!(locator).should == topic
316
+ end
317
+ it "should give back a Topic if argument is a String(absolute IRI,si) and the Topic defined by the String already exists" do
318
+ string = "http://www.uni-leipzig.de/"
319
+ topic = @tm.create_topic_by_subject_identifier(@tm.create_locator(string))
320
+ @tm.get!(string).should == topic
321
+ @tm.get!("si:" + string).should == topic
322
+ end
323
+ it "should give back a Topic if argument is a String(absolute IRI,sl) and the Topic defined by the String already exists" do
324
+ string = "http://www.uni-leipzig.de/"
325
+ topic = @tm.create_topic_by_subject_locator(@tm.create_locator(string))
326
+ @tm.get!("sl:" + string).should == topic
327
+ @tm.get!("=" + string).should == topic
328
+ end
329
+ it "should give back a Topic if argument is a String(absolute IRI,ii) and the Topic defined by the String already exists" do
330
+ string = "http://www.uni-leipzig.de/"
331
+ topic = @tm.create_topic_by_item_identifier(@tm.create_locator(string))
332
+ @tm.get!("ii:" + string).should == topic
333
+ @tm.get!("^" + string).should == topic
334
+ end
335
+ it "should give back a Topic if argument is a String(relative IRI,si) and the Topic defined by the String already exists" do
336
+ string = "get-test"
337
+ topic = @tm.create_topic_by_subject_identifier(@tm.create_locator(string))
338
+ @tm.get!(string).should == topic
339
+ @tm.get!("si:" + string).should == topic
340
+ end
341
+ it "should give back a Topic if argument is a String(relative IRI,sl) and the Topic defined by the String already exists" do
342
+ string = "get-test"
343
+ topic = @tm.create_topic_by_subject_locator(@tm.create_locator(string))
344
+ @tm.get!("sl:" + string).should == topic
345
+ @tm.get!("=" + string).should == topic
346
+ end
347
+ it "should give back a Topic if argument is a String(relative IRI,ii) and the Topic defined by the String already exists" do
348
+ string = "get-test"
349
+ topic = @tm.create_topic_by_item_identifier(@tm.create_locator(string))
350
+ @tm.get!("ii:" + string).should == topic
351
+ @tm.get!("^" + string).should == topic
352
+ end
353
+ it "should create a Topic and give back this Topic if argument is a String (si) and no Topic has this String as subject identifier" do
354
+ string = "get-test"
355
+ topic = @tm.get!(string)
356
+ topic.should be_a_kind_of RTM::Topic
357
+ topic.item.should be_nil
358
+ topic.locators.should be_empty
359
+ topic.indicators.size.should == 1
360
+ topic.indicators.first.should == ("http://www.topicmapslab.de/" + string)
361
+ end
362
+ it "should create a Topic and give back this Topic if argument is a String (si, starting with 'si:') and no Topic has this String as subject identifier" do
363
+ string = "get-test"
364
+ topic = @tm.get!("si:" + string)
365
+ topic.should be_a_kind_of RTM::Topic
366
+ topic.item.should be_nil
367
+ topic.locators.should be_empty
368
+ topic.indicators.size.should == 1
369
+ topic.indicators.first.should == ("http://www.topicmapslab.de/" + string)
370
+ end
371
+ it "should give back a Topic if argument is a String (si) and and a Topic which has this String as item identifier already exists" do
372
+ string = "get-test"
373
+ topic1 = @tm.create_topic_by_subject_locator(@tm.create_locator(string))
374
+ topic2 = @tm.create_topic_by_item_identifier(@tm.create_locator(string))
375
+ @tm.get!(string).should == topic2
376
+ topic2.item.should == ("http://www.topicmapslab.de/" + string)
377
+ topic2.indicators.size.should == 1
378
+ topic2.indicators.first.should == ("http://www.topicmapslab.de/" + string)
379
+ topic2.locators.should be_empty
380
+ end
381
+ it "should give back a Topic if argument is a String (si, starting with 'si:') and and a Topic which has this String as item identifier already exists" do
382
+ string = "get-test"
383
+ topic1 = @tm.create_topic_by_subject_locator(@tm.create_locator(string))
384
+ topic2 = @tm.create_topic_by_item_identifier(@tm.create_locator(string))
385
+ @tm.get!("si:" + string).should == topic2
386
+ topic2.item.should == ("http://www.topicmapslab.de/" + string)
387
+ topic2.indicators.size.should == 1
388
+ topic2.indicators.first.should == ("http://www.topicmapslab.de/" + string)
389
+ topic2.locators.should be_empty
390
+ end
391
+ it "should create a Topic and give back this Topic if argument is a String (sl, starting with 'sl:') and no Topic has this String as subject locator" do
392
+ string = "get-test"
393
+ topic = @tm.get!("sl:" + string)
394
+ topic.should be_a_kind_of RTM::Topic
395
+ topic.item.should be_nil
396
+ topic.locators.size.should == 1
397
+ topic.locators.first.should == ("http://www.topicmapslab.de/" + string)
398
+ topic.indicators.should be_empty
399
+ end
400
+ it "should create a Topic and give back this Topic if argument is a String (sl, starting with '=') and no Topic has this String as subject locator" do
401
+ string = "get-test"
402
+ topic = @tm.get!("=" + string)
403
+ topic.should be_a_kind_of RTM::Topic
404
+ topic.item.should be_nil
405
+ topic.locators.size.should == 1
406
+ topic.locators.first.should == ("http://www.topicmapslab.de/" + string)
407
+ topic.indicators.should be_empty
408
+ end
409
+ it "should create a Topic and give back this Topic if argument is a String (ii, starting with 'ii:') and no Topic has this String as subject locator" do
410
+ string = "get-test"
411
+ topic = @tm.get!("ii:" + string)
412
+ topic.should be_a_kind_of RTM::Topic
413
+ topic.item.should == ("http://www.topicmapslab.de/" + string)
414
+ topic.locators.should be_empty
415
+ topic.indicators.should be_empty
416
+ topic.indicators.should be_empty
417
+ end
418
+ it "should create a Topic and give back this Topic if argument is a String (ii, starting with '^') and no Topic has this String as subject locator" do
419
+ string = "get-test"
420
+ topic = @tm.get!("^" + string)
421
+ topic.should be_a_kind_of RTM::Topic
422
+ topic.item.should == ("http://www.topicmapslab.de/" + string)
423
+ topic.locators.should be_empty
424
+ topic.indicators.should be_empty
425
+ end
426
+ it "should give back a Topic if argument is a String (ii, starting with 'ii:') and and a Topic which has this String as subject identifier already exists" do
427
+ string = "get-test"
428
+ topic1 = @tm.create_topic_by_subject_locator(@tm.create_locator(string))
429
+ topic2 = @tm.create_topic_by_subject_identifier(@tm.create_locator(string))
430
+ @tm.get!("ii:" + string).should == topic2
431
+ topic2.item.should == ("http://www.topicmapslab.de/" + string)
432
+ topic2.indicators.size.should == 1
433
+ topic2.indicators.first.should == ("http://www.topicmapslab.de/" + string)
434
+ topic2.locators.should be_empty
435
+ end
436
+ it "should give back a Topic if argument is a String (ii, starting with '^') and and a Topic which has this String as subject identifier already exists" do
437
+ string = "get-test"
438
+ topic1 = @tm.create_topic_by_subject_locator(@tm.create_locator(string))
439
+ topic2 = @tm.create_topic_by_subject_identifier(@tm.create_locator(string))
440
+ @tm.get!("^" + string).should == topic2
441
+ topic2.item.should == ("http://www.topicmapslab.de/" + string)
442
+ topic2.indicators.size.should == 1
443
+ topic2.indicators.first.should == ("http://www.topicmapslab.de/" + string)
444
+ topic2.locators.should be_empty
445
+ end
446
+ it "should create a Topic (with si) if argument is a Locator and no Topic has this Locator as si or ii" do
447
+ locator = @tm.create_locator("si")
448
+ @tm.create_topic_by_subject_locator(locator)
449
+ topic = @tm.get!(locator)
450
+ topic.locators.should be_empty
451
+ topic.item.should be_nil
452
+ topic.indicators.size.should == 1
453
+ topic.indicators.first.should == ("http://www.topicmapslab.de/" + "si")
454
+ end
455
+ it "should give back a Topic (with si) if argument is a Locator and a Topic has this Locator as ii" do
456
+ locator = @tm.create_locator("si")
457
+ topic = @tm.create_topic_by_item_identifier(locator)
458
+ @tm.get!(locator).should == topic
459
+ topic.locators.should be_empty
460
+ topic.item.should == ("http://www.topicmapslab.de/" + "si")
461
+ topic.indicators.should be_empty
462
+ end
463
+ it "should allow to create/get several Topics wheras some already exist and others not" do
464
+ array = ["dummy_si",@tm.create_locator("something"),"sl:Hans"]
465
+ @tm.get!(array).size.should == array.size
466
+ #TODO
467
+ #@tm.get!("")
468
+ @tm.get!(array).should == array.map{|i| @tm.get!(i)}
469
+ end
470
+ it "should handle identifier which are qnames (get!)" do
471
+ @tm.add_prefix("x","http://www.test.de/x/")
472
+ @tm.add_prefix("y","http://www.test.de/y/")
473
+ topic = @tm.get!("x:something")
474
+ topic.indicators.should include "http://www.test.de/x/something"
475
+ topic2 = @tm.get!("sl:y:something")
476
+ topic2.locators.should include "http://www.test.de/y/something"
477
+ end
478
+ end
479
+
480
+ describe "#create_locator" do
481
+ it "should handle identifier which are qnames (create_locator)" do
482
+ identifier = "x"
483
+ reference = "http://www.test.de/"
484
+ @tm.add_prefix(identifier, reference)
485
+ topic = @tm.create_topic_by(identifier + ":" + "something")
486
+ topic.should be_a_kind_of RTM::Topic
487
+ topic.indicators.should include(reference + "something")
488
+ end
489
+ it "should use the base_iri to create absolute IRIS" do
490
+ @tm.create_locator("xxx").value.should == (@tm.base_iri + "xxx")
491
+ end
492
+ it "should use the base_iri + # to create absolute IRIs if base_iri does not end with a /"
493
+ it "should only create Locators out of absolute IRIs"
494
+ end
495
+
496
+ describe "#occurrence_types" do
497
+ it "should allow to crate a topic " do
498
+ @tm.get!("foo:bar")["myoccurene"] = "hallo"
499
+ @tm.get!("foo:bar")["myoccurenex"] = "hallo"
500
+ end
501
+ end
502
+
503
+ describe "#name_types" do
504
+ it "should give the org::tmapi::index::TypeInstanceIndex.getNameTypes" do
505
+ @tm.name_types.should == @tm.type_instance_index.getNameTypes
506
+ end
507
+ end
508
+
509
+ describe "#instances" do
510
+ before(:each) do
511
+ @t1, @t2, @t3, @t4, @t5, @t6 = @tm.get!(["t1","t2", "t3", "t4", "t5", "t6"])
512
+ end
513
+ it "should give back all instances in the topic map when called without type without duplicates" do
514
+ @t1.add_types(@t2, @t3)
515
+ @t4.add_type(@t5)
516
+ @t6.add_types(@t1, @t4)
517
+ @tm.instances.size.should == 3
518
+ @tm.instances.should include(@t1, @t4, @t6)
519
+ end
520
+ it "should give back all instances of the specified type" do
521
+ @a,@b,@c,@d,@e,@f = @tm.get!(["a","b","c","d","e","f"])
522
+ @a.add_type(@b)
523
+ @d.add_type(@f)
524
+ @e.add_type(@f)
525
+ @tm.instances(@b).size.should == 1
526
+ @tm.instances("b").should include(@a)
527
+ ###
528
+ @tm.instances(@f).size.should == 2
529
+ @tm.instances("f").should include(@d,@e)
530
+ ###
531
+ @tm.instances(@c).should be_empty
532
+ @tm.instances("c").should be_empty
533
+ ###
534
+ @tm.instances("not_existing").should be_empty
535
+ end
536
+ end
537
+
538
+ describe "#children" do
539
+ it "should give back an Array of all Associations and Topics contained in the TopicMap" do
540
+ topic1 = @tm.create_topic_by("topic1")
541
+ topic2 = @tm.create_topic_by("topic2")
542
+ assoc_type1 = @tm.create_topic_by("asso1")
543
+ assoc_type2 = @tm.create_topic_by("asso2")
544
+ assoc1 = @tm.create_association(assoc_type1)
545
+ assoc2 = @tm.create_association(assoc_type2)
546
+ topic1.should be_a_kind_of RTM::Topic
547
+ topic2.should be_a_kind_of RTM::Topic
548
+ assoc1.should be_a_kind_of RTM::Association
549
+ assoc2.should be_a_kind_of RTM::Association
550
+ @tm.children.size.should == 6
551
+ @tm.children.should include(topic1)
552
+ @tm.children.should include(topic2)
553
+ @tm.children.should include(assoc_type1)
554
+ @tm.children.should include(assoc_type2)
555
+ @tm.children.should include(assoc1)
556
+ @tm.children.should include(assoc2)
557
+ end
558
+ end
559
+
560
+ describe "#create_association" do
561
+ it "should create an association (in the unconstrained scope) with given type if type is a String" do
562
+ assoc = @tm.create_association("assoc_type")
563
+ assoc.should be_a_kind_of RTM::Association
564
+ assoc.type.should == @tm.get("assoc_type")
565
+ assoc.scope.should be_empty
566
+ end
567
+ it "should create an association (in the unconstrained scope) with given type if type is a Locator" do
568
+ locator = @tm.create_locator("assoc_type")
569
+ assoc = @tm.create_association(locator)
570
+ assoc.should be_a_kind_of RTM::Association
571
+ assoc.type.should == @tm.get("assoc_type")
572
+ assoc.scope.should be_empty
573
+ end
574
+ it "should create an association (in the unconstrained scope) with given type if type is a Topic" do
575
+ assoc_type = @tm.get!("assoc_type")
576
+ assoc = @tm.create_association(assoc_type)
577
+ assoc.should be_a_kind_of RTM::Association
578
+ assoc.type.should == assoc_type
579
+ assoc.scope.should be_empty
580
+ end
581
+ it "should raise an error if if type is not a Topic or Topic-Reference" do
582
+ lambda{@tm.create_association(["type"])}.should raise_error
583
+ lambda{@tm.create_association(1)}.should raise_error
584
+ end
585
+ it "should create an association with given type and scope = empty Array" do
586
+ assoc = @tm.create_association("assoc_type",[])
587
+ assoc.should be_a_kind_of RTM::Association
588
+ assoc.type.should == @tm.get("assoc_type")
589
+ assoc.scope.should be_empty
590
+ end
591
+ it "should create an association with given type and scope = Array of Topic/Topic-References" do
592
+ locator = @tm.create_locator("theme3")
593
+ theme = @tm.get!("theme2")
594
+ assoc = @tm.create_association("assoc_type",["theme1",theme,locator])
595
+ assoc.should be_a_kind_of RTM::Association
596
+ assoc.type.should == @tm.get("assoc_type")
597
+ assoc.should have(3).scope
598
+ assoc.scope.should include @tm.get("theme1"), @tm.get(locator),theme
599
+ end
600
+ it "should create an association with given type and roles" do
601
+ assoc = @tm.create_association("Country-Capital","Capital" => "Berlin", "Country" => "Germany")
602
+ assoc.should be_a_kind_of RTM::Association
603
+ assoc.should have(2).roles
604
+ assoc.type.should == @tm.get("Country-Capital")
605
+ assoc.roles.map{|r| r.type}.should include @tm.get("Capital"), @tm.get("Country")
606
+ assoc.roles.map{|r| r.player}.should include @tm.get("Berlin"), @tm.get("Germany")
607
+ end
608
+ it "should create an association with given type, scope and roles" do
609
+ assoc = @tm.create_association("Country-Capital",["2008"],"Capital" => "Berlin", "Country" => "Germany")
610
+ assoc.should be_a_kind_of RTM::Association
611
+ assoc.should have(2).roles
612
+ assoc.type.should == @tm.get("Country-Capital")
613
+ assoc.should have(1).scope
614
+ assoc.scope.should include @tm.get("2008")
615
+ assoc.roles.map{|r| r.type}.should include @tm.get("Capital"), @tm.get("Country")
616
+ assoc.roles.map{|r| r.player}.should include @tm.get("Berlin"), @tm.get("Germany")
617
+ end
618
+ it "should raise an error if scope is not an Array" do
619
+ lambda{@tm.create_association("assoc_type","scope")}.should raise_error
620
+ lambda{@tm.create_association("assoc_type","scope","roletype" => "player")}.should raise_error
621
+ end
622
+ it "should raise an error if roles are not in a Hash" do
623
+ lambda{@tm.create_association("assoc_type","role")}.should raise_error
624
+ lambda{@@tm.create_association("assoc_type",["theme1", "theme2"],"role")}.should raise_error
625
+ end
626
+ it "should create an association with given type and roles with same roletype" do
627
+ assoc = @tm.create_association("Neighbouring_Countries","Neighbouring_Country" => ["Germany", "France"])
628
+ assoc.should be_a_kind_of RTM::Association
629
+ assoc.should have(2).roles
630
+ assoc.type.should == @tm.get("Neighbouring_Countries")
631
+ assoc.roles.map{|r| r.type}.should include @tm.get("Neighbouring_Country")
632
+ assoc.roles.map{|r| r.player}.should include @tm.get("France"), @tm.get("Germany")
633
+ end
634
+ end
635
+ end # of describe self
636
+
637
+ describe self do
638
+ describe "#remove" do
639
+ it "should remove this TopicMap from its container" do
640
+ @tm = get_used_tm_sys_tm
641
+ @tm.remove
642
+ pending if implementation_for_spec == :sesametm
643
+ lambda{@tm.close}.should raise_error
644
+ end
645
+ end
646
+ end # of describe self
647
+
648
+ end #of module