rtm 0.1.6 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. data/DISCLAIMER +10 -33
  2. data/LICENSE +201 -0
  3. data/README +32 -3
  4. data/lib/rtm.rb +126 -74
  5. data/lib/rtm/axes.rb +298 -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 +101 -0
  17. data/lib/rtm/extensions.rb +65 -5
  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 +19 -0
  22. data/lib/rtm/io/from_xtm2_libxml.rb +2 -1
  23. data/lib/rtm/io/tmapix_from.rb +155 -0
  24. data/lib/rtm/io/tmapix_to.rb +223 -0
  25. data/lib/rtm/io/to_hash.rb +154 -0
  26. data/lib/rtm/io/to_jtm.rb +53 -103
  27. data/lib/rtm/io/to_rdf.rb +45 -0
  28. data/lib/rtm/io/to_string.rb +21 -8
  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 +59 -100
  32. data/lib/rtm/navigation.rb +23 -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 +166 -0
  44. data/lib/rtm/navigation/topic/traverse.rb +51 -0
  45. data/lib/rtm/navigation/topic/types.rb +109 -0
  46. data/lib/rtm/psi.rb +39 -2
  47. data/lib/rtm/sugar.rb +47 -0
  48. data/lib/rtm/sugar/association/hash_access.rb +46 -0
  49. data/lib/rtm/sugar/occurrence/dynamic_value.rb +58 -0
  50. data/lib/rtm/sugar/occurrence/external.rb +53 -0
  51. data/lib/rtm/sugar/reifiable/reifier.rb +21 -0
  52. data/lib/rtm/sugar/role/counterparts.rb +139 -46
  53. data/lib/rtm/sugar/topic/best_name.rb +74 -0
  54. data/lib/rtm/sugar/topic/characteristics.rb +126 -12
  55. data/lib/rtm/sugar/topic/counterparts.rb +145 -10
  56. data/lib/rtm/sugar/topic/hash_access.rb +140 -30
  57. data/lib/rtm/sugar/topic/scoped.rb +114 -0
  58. data/lib/rtm/sugar/topic/topic_ref.rb +86 -0
  59. data/lib/rtm/sugar/topic/typed.rb +207 -0
  60. data/lib/rtm/sugar/topic_map/query_cache.rb +66 -0
  61. data/lib/rtm/sugar/topic_map/themes.rb +53 -0
  62. data/lib/rtm/sugar/typed/types.rb +38 -0
  63. data/lib/rtm/validation.rb +7 -4
  64. data/lib/rtm/version.rb +30 -0
  65. data/spec/helpers/spec_exampleexamplegroup.rb +14 -0
  66. data/spec/rtm/axes/association_spec.rb +88 -0
  67. data/spec/rtm/axes/associations_spec.rb +60 -0
  68. data/spec/rtm/axes/assocs_names_occs_spec.rb +9 -0
  69. data/spec/rtm/axes/characteristic_spec.rb +90 -0
  70. data/spec/rtm/axes/characteristics_spec.rb +85 -0
  71. data/spec/rtm/axes/string_spec.rb +145 -0
  72. data/spec/rtm/axes/strings_spec.rb +168 -0
  73. data/spec/rtm/axes/topic_spec.rb +124 -0
  74. data/spec/rtm/axes/topics_spec.rb +103 -0
  75. data/spec/rtm/base_spec.rb +32 -0
  76. data/spec/rtm/io/tmapix_from_spec.rb +76 -0
  77. data/spec/rtm/io/tmapix_to_spec.rb +159 -0
  78. data/spec/rtm/io/to_hash_spec.rb +90 -0
  79. data/spec/rtm/io/to_rdf_spec.rb +37 -0
  80. data/spec/rtm/io/to_string_spec.rb +122 -0
  81. data/spec/rtm/io/to_yaml_spec.rb +89 -0
  82. data/spec/rtm/navigation/association/players_spec.rb +58 -0
  83. data/spec/rtm/navigation/association_spec.rb +52 -0
  84. data/spec/rtm/navigation/name/atomify_spec.rb +27 -0
  85. data/spec/rtm/navigation/name/characteristics_spec.rb +34 -0
  86. data/spec/rtm/navigation/name_spec.rb +52 -0
  87. data/spec/rtm/navigation/occurrence/atomify_spec.rb +27 -0
  88. data/spec/rtm/navigation/occurrence/characteristics_spec.rb +34 -0
  89. data/spec/rtm/navigation/occurrence_spec.rb +52 -0
  90. data/spec/rtm/navigation/string_spec.rb +51 -0
  91. data/spec/rtm/navigation/topic/characteristics_spec.rb +55 -0
  92. data/spec/rtm/navigation/topic/indicators_spec.rb +43 -0
  93. data/spec/rtm/navigation/topic/items_spec.rb +44 -0
  94. data/spec/rtm/navigation/topic/locators_spec.rb +44 -0
  95. data/spec/rtm/navigation/topic/players_spec.rb +48 -0
  96. data/spec/rtm/navigation/topic/scope_spec.rb +41 -0
  97. data/spec/rtm/navigation/topic/supertypes_spec.rb +376 -0
  98. data/spec/rtm/navigation/topic/traverse_spec.rb +64 -0
  99. data/spec/rtm/navigation/topic/types_spec.rb +195 -0
  100. data/spec/rtm/navigation/topic_spec.rb +153 -0
  101. data/spec/rtm/sugar/association/hash_access_spec.rb +55 -0
  102. data/spec/rtm/sugar/occurrence/dynamic_value_spec.rb +171 -0
  103. data/spec/rtm/sugar/occurrence/external_spec.rb +129 -0
  104. data/spec/rtm/sugar/reifiable/reifier_spec.rb +41 -0
  105. data/spec/rtm/sugar/role/counterparts_spec.rb +193 -0
  106. data/spec/rtm/sugar/topic/best_name_spec.rb +25 -0
  107. data/spec/rtm/sugar/topic/characteristics_spec.rb +333 -0
  108. data/spec/rtm/sugar/topic/counterparts_spec.rb +224 -0
  109. data/spec/rtm/sugar/topic/hash_access_spec.rb +234 -0
  110. data/spec/rtm/sugar/topic/scoped_spec.rb +195 -0
  111. data/spec/rtm/sugar/topic/topic_ref_spec.rb +44 -0
  112. data/spec/rtm/sugar/topic/typed_spec.rb +217 -0
  113. data/spec/rtm/sugar/topic_map/themes_spec.rb +67 -0
  114. data/spec/rtm/sugar/typed/types_spec.rb +24 -0
  115. data/spec/rtm/tmapi/core/association_spec.rb +169 -0
  116. data/spec/rtm/tmapi/core/construct_spec.rb +25 -0
  117. data/spec/rtm/tmapi/core/datatype_aware_spec.rb +236 -0
  118. data/spec/rtm/tmapi/core/name_spec.rb +270 -0
  119. data/spec/rtm/tmapi/core/occurrence_spec.rb +53 -0
  120. data/spec/rtm/tmapi/core/reifiable_spec.rb +168 -0
  121. data/spec/rtm/tmapi/core/role_spec.rb +73 -0
  122. data/spec/rtm/tmapi/core/scoped_spec.rb +441 -0
  123. data/spec/rtm/tmapi/core/topic_map_spec.rb +716 -0
  124. data/spec/rtm/tmapi/core/topic_spec.rb +1468 -0
  125. data/spec/rtm/tmapi/core/typed_spec.rb +112 -0
  126. data/spec/rtm/tmapi/core/variant_spec.rb +52 -0
  127. data/spec/rtm/tmapi/ext/java_util_set_spec.rb +34 -0
  128. data/spec/rtm/tmapi_spec.rb +44 -0
  129. data/spec/rtm/utils/sparql_spec.rb +26 -0
  130. data/spec/rtm_spec.rb +93 -0
  131. data/spec/spec_helper.rb +28 -0
  132. data/test/javalibs/junit-4.5.jar +0 -0
  133. data/test/javalibs/tmapi-2.0-tests.jar +0 -0
  134. data/test/tmapi_tests.rb +25 -0
  135. metadata +169 -65
  136. data/COPYRIGHT +0 -4
  137. data/lib/Rakefile.rb +0 -42
  138. data/lib/activetopicmaps.rb +0 -278
  139. data/lib/rtm/backend/active_record.rb +0 -58
  140. data/lib/rtm/backend/active_record/001_initial_schema.rb +0 -116
  141. data/lib/rtm/backend/active_record/association_and_role.rb +0 -33
  142. data/lib/rtm/backend/active_record/locators.rb +0 -55
  143. data/lib/rtm/backend/active_record/name_variant_occurrence.rb +0 -45
  144. data/lib/rtm/backend/active_record/quaaxtm2rtm.rb +0 -113
  145. data/lib/rtm/backend/active_record/quaaxtm2rtmviews.rb +0 -134
  146. data/lib/rtm/backend/active_record/set_wrapper.rb +0 -98
  147. data/lib/rtm/backend/active_record/tm_construct.rb +0 -62
  148. data/lib/rtm/backend/active_record/tm_delegator.rb +0 -345
  149. data/lib/rtm/backend/active_record/tm_set_delegator.rb +0 -195
  150. data/lib/rtm/backend/active_record/tmdm.rb +0 -298
  151. data/lib/rtm/backend/active_record/topic.rb +0 -87
  152. data/lib/rtm/backend/active_record/topic_map.rb +0 -314
  153. data/lib/rtm/backend/active_record/traverse_associations.rb +0 -87
  154. data/lib/rtm/base.rb +0 -92
  155. data/lib/rtm/connect.rb +0 -92
  156. data/lib/rtm/core_ext.rb +0 -6
  157. data/lib/rtm/io/from_xtm2.rb +0 -263
  158. data/lib/rtm/merging/merging.rb +0 -307
  159. data/lib/rtm/pimp_my_api.rb +0 -28
  160. data/lib/rtm/sugar/topic/identifier_direct.rb +0 -11
  161. data/lib/rtm/sugar/topic/predefined_associations.rb +0 -42
  162. data/lib/run_main_project.rb +0 -16
  163. data/test/base_test.rb +0 -162
@@ -0,0 +1,716 @@
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.example.org")}.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.example.org")
57
+ @tm.prefixes.size.should == 1
58
+ @tm.prefixes["a"].should == "www.example.org"
59
+ end
60
+ it "should replace the reference if prefix already exists" do
61
+ @tm.add_prefix("a","www.example.com")
62
+ @tm.prefixes["a"].should == "www.example.com"
63
+ @tm.add_prefix("a","www.example.org")
64
+ @tm.prefixes["a"].should == "www.example.org"
65
+ end
66
+ it "should give back the prefixes-Hash" do
67
+ @tm.add_prefix("a","www.example.com").should == @tm.prefixes
68
+ @tm.add_prefix("g","www.example.org").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.example.org/a/")
80
+ @tm.add_prefix("b","www.example.org/b/")
81
+ @tm.add_prefix("c","www.example.org/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.example.org/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 give back a Multiarray of Topics and nils if argument is a Multiarray of identifiers and nils" do
277
+ array = [["si","","=sl","",nil,"something"],"^ii",@tm.create_locator("blub")]
278
+ @tm.get(array).size.should == array.size
279
+ @tm.get(array)[0].should == @tm.get(["si","","=sl","",nil,"something"])
280
+ @tm.get(array)[1].should == @tm.get("^ii")
281
+ @tm.get(array)[2].should == @tm.get(@tm.create_locator("blub"))
282
+ end
283
+ it "should handle identifier which are qnames (get)" do
284
+ @tm.add_prefix("x","http://www.example.org/x/")
285
+ @tm.add_prefix("y","http://www.example.org/y/")
286
+ topic = @tm.create_topic_by_subject_identifier("http://www.example.org/x/something")
287
+ @tm.get("x:something").should == topic
288
+ topic2 = @tm.create_topic_by_item_identifier("http://www.example.org/y/something")
289
+ @tm.get("ii:y:something").should == topic2
290
+ end
291
+ end
292
+
293
+ describe "#get!" do
294
+ before(:each) do
295
+ @tm.create_topic_by_subject_identifier("dummy_si")
296
+ @tm.create_topic_by_subject_locator("dummy_sl")
297
+ @tm.create_topic_by_item_identifier("dummy_ii")
298
+ end
299
+ it "should give back nil if the argument is nil" do
300
+ @tm.get!(nil).should be_nil
301
+ end
302
+ it "should give back an empty Array if the argument equals []" do
303
+ @tm.get!([]).should == []
304
+ end
305
+ it "should give back the argument if argument is a Topic" do
306
+ topic = @tm.create_topic
307
+ topic.should be_a_kind_of RTM::Topic
308
+ @tm.get!(topic).should == topic
309
+ end
310
+ it "should give back a Topic if argument is a Locator and the Topic defined by the Locator (si) already exists" do
311
+ locator = @tm.create_locator("http://www.example.org/uni-leipzig")
312
+ locator.should be_a_kind_of RTM::Locator
313
+ topic = @tm.create_topic_by_subject_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 Locator and the Topic defined by the Locator (ii) already exists" do
318
+ locator = @tm.create_locator("http://www.example.org/uni-leipzig")
319
+ locator.should be_a_kind_of RTM::Locator
320
+ topic = @tm.create_topic_by_item_identifier(locator)
321
+ topic.should be_a_kind_of RTM::Topic
322
+ @tm.get!(locator).should == topic
323
+ end
324
+ it "should give back a Topic if argument is a String(absolute IRI,si) and the Topic defined by the String already exists" do
325
+ string = "http://www.example.org/uni-leipzig"
326
+ topic = @tm.create_topic_by_subject_identifier(@tm.create_locator(string))
327
+ @tm.get!(string).should == topic
328
+ @tm.get!("si:" + string).should == topic
329
+ end
330
+ it "should give back a Topic if argument is a String(absolute IRI,sl) and the Topic defined by the String already exists" do
331
+ string = "http://www.example.org/uni-leipzig"
332
+ topic = @tm.create_topic_by_subject_locator(@tm.create_locator(string))
333
+ @tm.get!("sl:" + string).should == topic
334
+ @tm.get!("=" + string).should == topic
335
+ end
336
+ it "should give back a Topic if argument is a String(absolute IRI,ii) and the Topic defined by the String already exists" do
337
+ string = "http://www.example.org/uni-leipzig"
338
+ topic = @tm.create_topic_by_item_identifier(@tm.create_locator(string))
339
+ @tm.get!("ii:" + string).should == topic
340
+ @tm.get!("^" + string).should == topic
341
+ end
342
+ it "should give back a Topic if argument is a String(relative IRI,si) and the Topic defined by the String already exists" do
343
+ string = "get-test"
344
+ topic = @tm.create_topic_by_subject_identifier(@tm.create_locator(string))
345
+ @tm.get!(string).should == topic
346
+ @tm.get!("si:" + string).should == topic
347
+ end
348
+ it "should give back a Topic if argument is a String(relative IRI,sl) and the Topic defined by the String already exists" do
349
+ string = "get-test"
350
+ topic = @tm.create_topic_by_subject_locator(@tm.create_locator(string))
351
+ @tm.get!("sl:" + string).should == topic
352
+ @tm.get!("=" + string).should == topic
353
+ end
354
+ it "should give back a Topic if argument is a String(relative IRI,ii) and the Topic defined by the String already exists" do
355
+ string = "get-test"
356
+ topic = @tm.create_topic_by_item_identifier(@tm.create_locator(string))
357
+ @tm.get!("ii:" + string).should == topic
358
+ @tm.get!("^" + string).should == topic
359
+ end
360
+ 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
361
+ string = "get-test"
362
+ topic = @tm.get!(string)
363
+ topic.should be_a_kind_of RTM::Topic
364
+ topic.item.should be_nil
365
+ topic.locators.should be_empty
366
+ topic.indicators.size.should == 1
367
+ topic.indicators.first.should == ("http://www.topicmapslab.de/" + string)
368
+ end
369
+ 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
370
+ string = "get-test"
371
+ topic = @tm.get!("si:" + string)
372
+ topic.should be_a_kind_of RTM::Topic
373
+ topic.item.should be_nil
374
+ topic.locators.should be_empty
375
+ topic.indicators.size.should == 1
376
+ topic.indicators.first.should == ("http://www.topicmapslab.de/" + string)
377
+ end
378
+ 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
379
+ string = "get-test"
380
+ topic1 = @tm.create_topic_by_subject_locator(@tm.create_locator(string))
381
+ topic2 = @tm.create_topic_by_item_identifier(@tm.create_locator(string))
382
+ @tm.get!(string).should == topic2
383
+ topic2.item.should == ("http://www.topicmapslab.de/" + string)
384
+ topic2.indicators.size.should == 1
385
+ topic2.indicators.first.should == ("http://www.topicmapslab.de/" + string)
386
+ topic2.locators.should be_empty
387
+ end
388
+ 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
389
+ string = "get-test"
390
+ topic1 = @tm.create_topic_by_subject_locator(@tm.create_locator(string))
391
+ topic2 = @tm.create_topic_by_item_identifier(@tm.create_locator(string))
392
+ @tm.get!("si:" + string).should == topic2
393
+ topic2.item.should == ("http://www.topicmapslab.de/" + string)
394
+ topic2.indicators.size.should == 1
395
+ topic2.indicators.first.should == ("http://www.topicmapslab.de/" + string)
396
+ topic2.locators.should be_empty
397
+ end
398
+ 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
399
+ string = "get-test"
400
+ topic = @tm.get!("sl:" + string)
401
+ topic.should be_a_kind_of RTM::Topic
402
+ topic.item.should be_nil
403
+ topic.locators.size.should == 1
404
+ topic.locators.first.should == ("http://www.topicmapslab.de/" + string)
405
+ topic.indicators.should be_empty
406
+ end
407
+ 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
408
+ string = "get-test"
409
+ topic = @tm.get!("=" + string)
410
+ topic.should be_a_kind_of RTM::Topic
411
+ topic.item.should be_nil
412
+ topic.locators.size.should == 1
413
+ topic.locators.first.should == ("http://www.topicmapslab.de/" + string)
414
+ topic.indicators.should be_empty
415
+ end
416
+ 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
417
+ string = "get-test"
418
+ topic = @tm.get!("ii:" + string)
419
+ topic.should be_a_kind_of RTM::Topic
420
+ topic.item.should == ("http://www.topicmapslab.de/" + string)
421
+ topic.locators.should be_empty
422
+ topic.indicators.should be_empty
423
+ topic.indicators.should be_empty
424
+ end
425
+ 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
426
+ string = "get-test"
427
+ topic = @tm.get!("^" + string)
428
+ topic.should be_a_kind_of RTM::Topic
429
+ topic.item.should == ("http://www.topicmapslab.de/" + string)
430
+ topic.locators.should be_empty
431
+ topic.indicators.should be_empty
432
+ end
433
+ 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
434
+ string = "get-test"
435
+ topic1 = @tm.create_topic_by_subject_locator(@tm.create_locator(string))
436
+ topic2 = @tm.create_topic_by_subject_identifier(@tm.create_locator(string))
437
+ @tm.get!("ii:" + string).should == topic2
438
+ topic2.item.should == ("http://www.topicmapslab.de/" + string)
439
+ topic2.indicators.size.should == 1
440
+ topic2.indicators.first.should == ("http://www.topicmapslab.de/" + string)
441
+ topic2.locators.should be_empty
442
+ end
443
+ 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
444
+ string = "get-test"
445
+ topic1 = @tm.create_topic_by_subject_locator(@tm.create_locator(string))
446
+ topic2 = @tm.create_topic_by_subject_identifier(@tm.create_locator(string))
447
+ @tm.get!("^" + string).should == topic2
448
+ topic2.item.should == ("http://www.topicmapslab.de/" + string)
449
+ topic2.indicators.size.should == 1
450
+ topic2.indicators.first.should == ("http://www.topicmapslab.de/" + string)
451
+ topic2.locators.should be_empty
452
+ end
453
+ it "should create a Topic (with si) if argument is a Locator and no Topic has this Locator as si or ii" do
454
+ locator = @tm.create_locator("si")
455
+ @tm.create_topic_by_subject_locator(locator)
456
+ topic = @tm.get!(locator)
457
+ topic.locators.should be_empty
458
+ topic.item.should be_nil
459
+ topic.indicators.size.should == 1
460
+ topic.indicators.first.should == ("http://www.topicmapslab.de/" + "si")
461
+ end
462
+ it "should give back a Topic (with si) if argument is a Locator and a Topic has this Locator as ii" do
463
+ locator = @tm.create_locator("si")
464
+ topic = @tm.create_topic_by_item_identifier(locator)
465
+ @tm.get!(locator).should == topic
466
+ topic.locators.should be_empty
467
+ topic.item.should == ("http://www.topicmapslab.de/" + "si")
468
+ topic.indicators.should be_empty
469
+ end
470
+ it "should allow to create/get several Topics wheras some already exist and others not" do
471
+ array = ["dummy_si",@tm.create_locator("something"),"sl:Hans"]
472
+ @tm.get!(array).size.should == array.size
473
+ @tm.get!(array).should == array.map{|i| @tm.get!(i)}
474
+ end
475
+ it "should give back a Multiarray of Topics if argument is a Multiarray of identifiers and nils" do
476
+ array = [["si","","=sl","",nil,"something"],"^ii",@tm.create_locator("blub")]
477
+ @tm.get!(array).size.should == array.size
478
+ @tm.get!(array)[0].should == @tm.get!(["si","","=sl","",nil,"something"])
479
+ @tm.get!(array)[1].should == @tm.get!("^ii")
480
+ @tm.get!(array)[2].should == @tm.get!(@tm.create_locator("blub"))
481
+ end
482
+ it "should handle identifier which are qnames" do
483
+ @tm.add_prefix("x","http://www.example.org/x/")
484
+ @tm.add_prefix("y","http://www.example.org/y/")
485
+ topic = @tm.get!("x:something")
486
+ topic.indicators.should include("http://www.example.org/x/something")
487
+ topic2 = @tm.get!("sl:y:something")
488
+ topic2.locators.should include("http://www.example.org/y/something")
489
+ end
490
+ end
491
+
492
+ describe "#create_locator" do
493
+ it "should handle identifier which are qnames (create_locator)" do
494
+ identifier = "x"
495
+ reference = "http://www.example.org/"
496
+ @tm.add_prefix(identifier, reference)
497
+ topic = @tm.create_topic_by(identifier + ":" + "something")
498
+ topic.should be_a_kind_of RTM::Topic
499
+ topic.indicators.should include(reference + "something")
500
+ end
501
+ it "should use the base_iri to create absolute IRIS" do
502
+ @tm.create_locator("xxx").value.should == (@tm.base_iri + "xxx")
503
+ end
504
+ it "should use the base_iri + # to create absolute IRIs if base_iri does not end with a /"
505
+ it "should only create Locators out of absolute IRIs"
506
+ end
507
+
508
+ describe "#occurrence_types" do
509
+ it "should allow to crate a topic " do
510
+ @tm.get!("foo:bar")["myoccurene"] = "hallo"
511
+ @tm.get!("foo:bar")["myoccurenex"] = "hallo"
512
+ end
513
+ end
514
+
515
+ describe "#name_types" do
516
+ it "should give the org::tmapi::index::TypeInstanceIndex.getNameTypes" do
517
+ @tm.name_types.should == @tm.type_instance_index.getNameTypes
518
+ end
519
+ end
520
+
521
+ describe "#instances" do
522
+ before(:each) do
523
+ @t1, @t2, @t3, @t4, @t5, @t6 = @tm.get!(["t1","t2", "t3", "t4", "t5", "t6"])
524
+ end
525
+ it "should give back all instances in the topic map when called without type without duplicates" do
526
+ @t1.add_types(@t2, @t3)
527
+ @t4.add_type(@t5)
528
+ @t6.add_types(@t1, @t4)
529
+ @tm.instances.size.should == 3
530
+ @tm.instances.should include(@t1, @t4, @t6)
531
+ end
532
+ it "should give back all instances of the specified type" do
533
+ @a,@b,@c,@d,@e,@f = @tm.get!(["a","b","c","d","e","f"])
534
+ @a.add_type(@b)
535
+ @d.add_type(@f)
536
+ @e.add_type(@f)
537
+ @tm.instances(@b).size.should == 1
538
+ @tm.instances("b").should include(@a)
539
+ ###
540
+ @tm.instances(@f).size.should == 2
541
+ @tm.instances("f").should include(@d,@e)
542
+ ###
543
+ @tm.instances(@c).should be_empty
544
+ @tm.instances("c").should be_empty
545
+ ###
546
+ @tm.instances("not_existing").should be_empty
547
+ end
548
+ end
549
+
550
+ describe "#children" do
551
+ it "should give back an Array of all Associations and Topics contained in the TopicMap" do
552
+ topic1 = @tm.create_topic_by("topic1")
553
+ topic2 = @tm.create_topic_by("topic2")
554
+ assoc_type1 = @tm.create_topic_by("asso1")
555
+ assoc_type2 = @tm.create_topic_by("asso2")
556
+ assoc1 = @tm.create_association(assoc_type1)
557
+ assoc2 = @tm.create_association(assoc_type2)
558
+ topic1.should be_a_kind_of RTM::Topic
559
+ topic2.should be_a_kind_of RTM::Topic
560
+ assoc1.should be_a_kind_of RTM::Association
561
+ assoc2.should be_a_kind_of RTM::Association
562
+ @tm.children.size.should == 6
563
+ @tm.children.should include(topic1)
564
+ @tm.children.should include(topic2)
565
+ @tm.children.should include(assoc_type1)
566
+ @tm.children.should include(assoc_type2)
567
+ @tm.children.should include(assoc1)
568
+ @tm.children.should include(assoc2)
569
+ end
570
+ end
571
+
572
+ describe "#create_association" do
573
+ it "should create an association (in the unconstrained scope) with given type if type is a String" do
574
+ assoc = @tm.create_association("assoc_type")
575
+ assoc.should be_a_kind_of RTM::Association
576
+ assoc.type.should == @tm.get("assoc_type")
577
+ assoc.scope.should be_empty
578
+ end
579
+ it "should create an association (in the unconstrained scope) with given type if type is a Locator" do
580
+ locator = @tm.create_locator("assoc_type")
581
+ assoc = @tm.create_association(locator)
582
+ assoc.should be_a_kind_of RTM::Association
583
+ assoc.type.should == @tm.get("assoc_type")
584
+ assoc.scope.should be_empty
585
+ end
586
+ it "should create an association (in the unconstrained scope) with given type if type is a Topic" do
587
+ assoc_type = @tm.get!("assoc_type")
588
+ assoc = @tm.create_association(assoc_type)
589
+ assoc.should be_a_kind_of RTM::Association
590
+ assoc.type.should == assoc_type
591
+ assoc.scope.should be_empty
592
+ end
593
+ it "should raise an error if if type is not a Topic or Topic-Reference" do
594
+ lambda{@tm.create_association(["type"])}.should raise_error
595
+ lambda{@tm.create_association(1)}.should raise_error
596
+ end
597
+ it "should create an association with given type and scope = empty Array" do
598
+ assoc = @tm.create_association("assoc_type",[])
599
+ assoc.should be_a_kind_of RTM::Association
600
+ assoc.type.should == @tm.get("assoc_type")
601
+ assoc.scope.should be_empty
602
+ end
603
+ it "should create an association with given type and scope = Array of Topic/Topic-References" do
604
+ locator = @tm.create_locator("theme3")
605
+ theme = @tm.get!("theme2")
606
+ assoc = @tm.create_association("assoc_type",["theme1",theme,locator])
607
+ assoc.should be_a_kind_of RTM::Association
608
+ assoc.type.should == @tm.get("assoc_type")
609
+ assoc.should have(3).scope
610
+ assoc.scope.should include @tm.get("theme1"), @tm.get(locator),theme
611
+ end
612
+ it "should create an association with given type and roles" do
613
+ assoc = @tm.create_association("Country-Capital","Capital" => "Berlin", "Country" => "Germany")
614
+ assoc.should be_a_kind_of RTM::Association
615
+ assoc.should have(2).roles
616
+ assoc.type.should == @tm.get("Country-Capital")
617
+ assoc.roles.map{|r| r.type}.should include @tm.get("Capital"), @tm.get("Country")
618
+ assoc.roles.map{|r| r.player}.should include @tm.get("Berlin"), @tm.get("Germany")
619
+ end
620
+ it "should create an association with given type, scope and roles" do
621
+ assoc = @tm.create_association("Country-Capital",["2008"],"Capital" => "Berlin", "Country" => "Germany")
622
+ assoc.should be_a_kind_of RTM::Association
623
+ assoc.should have(2).roles
624
+ assoc.type.should == @tm.get("Country-Capital")
625
+ assoc.should have(1).scope
626
+ assoc.scope.should include @tm.get("2008")
627
+ assoc.roles.map{|r| r.type}.should include @tm.get("Capital"), @tm.get("Country")
628
+ assoc.roles.map{|r| r.player}.should include @tm.get("Berlin"), @tm.get("Germany")
629
+ end
630
+ it "should raise an error if scope is not an Array" do
631
+ lambda{@tm.create_association("assoc_type","scope")}.should raise_error
632
+ lambda{@tm.create_association("assoc_type","scope","roletype" => "player")}.should raise_error
633
+ end
634
+ it "should raise an error if roles are not in a Hash" do
635
+ lambda{@tm.create_association("assoc_type","role")}.should raise_error
636
+ lambda{@@tm.create_association("assoc_type",["theme1", "theme2"],"role")}.should raise_error
637
+ end
638
+ it "should create an association with given type and roles with same roletype" do
639
+ assoc = @tm.create_association("Neighbouring_Countries","Neighbouring_Country" => ["Germany", "France"])
640
+ assoc.should be_a_kind_of RTM::Association
641
+ assoc.should have(2).roles
642
+ assoc.type.should == @tm.get("Neighbouring_Countries")
643
+ assoc.roles.map{|r| r.type}.should include @tm.get("Neighbouring_Country")
644
+ assoc.roles.map{|r| r.player}.should include @tm.get("France"), @tm.get("Germany")
645
+ end
646
+ end
647
+
648
+ describe "#associations" do
649
+ before(:each) do
650
+ @assoc1 = @tm.create_association("at1")
651
+ @assoc2 = @tm.create_association("at2", "rt21" => "rp21")
652
+ @assoc3 = @tm.create_association("at3", "rt31" => "rp31", "rt32" => "rp32")
653
+ @assoc4 = @tm.create_association("at3")
654
+ @no_assoc_type = @tm.get!("no_assoc_type")
655
+ end
656
+ it "should give back all associations" do
657
+ @tm.should have(4).associations
658
+ @tm.associations.should include(@assoc1, @assoc2, @assoc3, @assoc4)
659
+ end
660
+ it "should give back some associations if argument type (String) is given" do
661
+ @tm.associations("at1").size.should == 1
662
+ @tm.associations("at1").should include(@assoc1)
663
+ @tm.associations("at3").size.should == 2
664
+ @tm.associations("at3").should include(@assoc3, @assoc4)
665
+ @tm.associations("no_assoc_type").should be_empty
666
+ end
667
+ it "should give back some associations if argument type (Locator) is given" do
668
+ at2_loc = @tm.create_locator("at2")
669
+ at2_loc.should_not be_nil
670
+ at3_loc = @tm.create_locator("at3")
671
+ at3_loc.should_not be_nil
672
+ @tm.associations(at2_loc).size.should == 1
673
+ @tm.associations(at2_loc).should include(@assoc2)
674
+ @tm.associations(at3_loc).size.should == 2
675
+ @tm.associations(at3_loc).should include(@assoc3, @assoc4)
676
+ @tm.associations(@tm.create_locator("no_assoc_type")).should be_empty
677
+ end
678
+ it "should give back some associations if argument type (Topic) is given" do
679
+ at1 = @tm.get("at1")
680
+ at1.should_not be_nil
681
+ at3 = @tm.get("at3")
682
+ at3.should_not be_nil
683
+ @tm.associations(at1).size.should == 1
684
+ @tm.associations(at1).should include(@assoc1)
685
+ @tm.associations(at3).size.should == 2
686
+ @tm.associations(at3).should include(@assoc3, @assoc4)
687
+ @tm.associations(@no_assoc_type).should be_empty
688
+ end
689
+ it "should raise error if argument type is nil" do
690
+ lambda{@tm.associations(nil)}.should raise_error
691
+ end
692
+ it "should raise error if argument type is an array" do
693
+ lambda{@tm.associations(["a"])}.should raise_error
694
+ end
695
+ it "should give back no associations if argument type is a String but no Topic with this identifier exists" do
696
+ @tm.associations("not_existing").should be_empty
697
+ end
698
+ it "should give back no associations if argument type is a Locator but no Topic with this identifier exists" do
699
+ @tm.associations(@tm.create_locator("not_existing")).should be_empty
700
+ end
701
+ end
702
+
703
+ end # of describe self
704
+
705
+ describe self do
706
+ describe "#remove" do
707
+ it "should remove this TopicMap from its container" do
708
+ @tm = get_used_tm_sys_tm
709
+ @tm.remove
710
+ pending if implementation_for_spec == :sesametm
711
+ lambda{@tm.close}.should raise_error
712
+ end
713
+ end
714
+ end # of describe self
715
+
716
+ end #of module