rtm 0.1.6 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,307 +0,0 @@
1
- module RTM
2
- class MergeException < Exception; end
3
- class TopicMergeException < MergeException; end
4
- module Merging
5
- module ReWrap
6
- protected
7
- def merge_rewrap(other)
8
- # let the wrapper point to the new object
9
- old_getobj = other.__getobj__
10
- other.__setobj__(self.__getobj__) if self.respond_to?(:__getobj__) && other.respond_to?(:__setobj__)
11
- # and destroy the old one
12
- old_getobj.reload
13
- __getobj__.reload
14
- old_getobj.destroy
15
- end
16
- end
17
- module MergeItemIdentifiers
18
- protected
19
- def merge_item_identifiers(other)
20
- #self.item_identifiers.add_all other.item_identifiers
21
- RTM::AR::TMDM::ItemIdentifier.move_all(
22
- ["topic_map_construct_id", other.__getobj__.id, self.__getobj__.id],
23
- ["topic_map_construct_type", other.__getobj__.class.name, self.__getobj__.class.name]
24
- )
25
- end
26
- end
27
- module MergeReifiable
28
- include MergeItemIdentifiers
29
- include ReWrap
30
- protected
31
- def merge_reifiable(other)
32
- if other.reifier && self.reifier
33
- self.reifier.merge(other.reifier)
34
- elsif other.reifier
35
- self.reifier = other.reifier
36
- end
37
- end
38
- end
39
-
40
- module Association
41
- include Merging::MergeReifiable
42
-
43
- def merge(other)
44
- # The procedure for merging two association items A and B is given below.
45
-
46
- # 1. Create a new association item, C.
47
- # -> we will instead just modify a
48
-
49
- # 2. Set C's [type] property to the value of A's [type] property. B's value is equal to that of A and need not be taken into account.
50
- # 3. Set C's [scope] property to the value of A's [scope] property. B's value is equal to that of A and need not be taken into account.
51
- # 4. Set C's [roles] property to the value of A's [roles] property. B's value is equal to that of A and need not be taken into account.
52
- # -> nothing to do till here
53
-
54
- # 5. Set C's [reifier] property to the value of A's [reifier] property if it is not null, and to the value of B's [reifier] property if A's property is null. If both A and B have non-null values, the topic items shall be merged, and the topic item resulting from the merge set as the value of C's [reifier] property.
55
- self.merge_reifiable other
56
-
57
- # 6. Set C's [item identifiers] property to the union of the values of A's and B's [item identifiers] properties.
58
- self.merge_item_identifiers other
59
-
60
- # 7. Remove A and B from the [associations] property of the topic map item in their [parent] properties, and add C.
61
- #self.parent.associations.remove other
62
-
63
- # let the wrapper point to the new object
64
- #other.__setobj__(self.__getobj__) if self.respond_to?(:__getobj__) && other.respond_to?(:__setobj__)
65
- self.merge_rewrap other
66
-
67
- self
68
- end
69
- end
70
-
71
- module AssociationRole
72
- include Merging::MergeReifiable
73
-
74
- def merge(other)
75
- # The procedure for merging two association role items A and B is given below.
76
- # -> we will instead just modify a
77
-
78
- # 1. Create a new association role item, C.
79
- # 2. Set C's [player] property to the value of A's [player] property. B's value is equal to that of A and need not be taken into account.
80
- # 3. Set C's [type] property to the value of A's [type] property. B's value is equal to that of A and need not be taken into account.
81
- # -> nothing to do till here
82
-
83
- # 4. Set C's [item identifiers] property to the union of the values of A's and B's [item identifiers] properties.
84
- self.merge_item_identifiers other
85
-
86
- # 5. Set C's [reifier] property to the value of A's [reifier] property if it is not null,
87
- # and to the value of B's [reifier] property if A's property is null.
88
- # If both A and B have non-null values, the topic items shall be merged,
89
- # and the topic item resulting from the merge set as the value of C's [reifier] property.
90
- self.merge_reifiable other
91
-
92
- # 6. Remove A and B from the [roles] property of the association item in their [parent] properties, and add C.
93
- #self.parent.roles.remove other
94
-
95
- #puts "#{self.parent.object_id} and #{other.parent.object_id}"
96
-
97
- # let the wrapper point to the new object
98
- #other.__setobj__(self.__getobj__) if self.respond_to?(:__getobj__) && other.respond_to?(:__setobj__)
99
- self.merge_rewrap other
100
-
101
- self
102
- end
103
- end
104
-
105
- module Occurrence
106
- include Merging::MergeReifiable
107
-
108
- def merge(other)
109
- # 1. Create a new occurrence item, C.
110
- # -> we will instead just modify a
111
-
112
- # 2. Set C's [value] property to the value of A's [value] property. B's value is equal to that of A and need not be taken into account.
113
- # 3. Set C's [datatype] property to the value of A's [datatype] property. B's value is equal to that of A and need not be taken into account.
114
- # 4. Set C's [scope] property to the value of A's [scope] property. B's value is equal to that of A and need not be taken into account.
115
- # 5. Set C's [type] property to the value of A's [type] property. B's value is equal to that of A and need not be taken into account.
116
- # -> nothing to do till here
117
-
118
- # 6. Set C's [reifier] property to the value of A's [reifier] property if it is not null, and to the value of B's [reifier] property if A's property is null. If both A and B have non-null values, the topic items shall be merged, and the topic item resulting from the merge set as the value of C's [reifier] property.
119
- self.merge_reifiable other
120
-
121
- # 7. Set C's [item identifiers] property to the union of the values of A's and B's [item identifiers] properties.
122
- self.merge_item_identifiers other
123
-
124
- # 8. Remove A and B from the [occurrences] property of the topic item in their [parent] properties, and add C.
125
- #self.parent.occurrences.remove other
126
-
127
- # let the wrapper point to the new object
128
- #other.__setobj__(self.__getobj__) if self.respond_to?(:__getobj__) && other.respond_to?(:__setobj__)
129
- self.merge_rewrap other
130
-
131
- self
132
- end
133
- end
134
-
135
- module Topic
136
- include Merging::ReWrap
137
- include Merging::MergeItemIdentifiers
138
-
139
- def merge(other)
140
- return unless other
141
- # The procedure for merging two topic items A and B
142
- # -> we will instead just modify a
143
- # (whose [parent] properties shall contain the same topic map item) is given below.
144
- raise TopicMergeException, "Both topics must belong to the same topic map!" if self.parent.__getobj__ != other.parent.__getobj__
145
- # It is an error if A and B both have non-null values in their [reified] properties which are different.
146
- raise TopicMergeException, "The Topics must not reify different things." if self.reified && other.reified && self.reified.__getobj__ != other.reified.__getobj__
147
-
148
- # 1. Create a new topic item C.
149
- # 2. Replace A by C wherever it appears in one of the following properties
150
- # of an information item: [topics], [scope], [type], [player], and [reifier].
151
- # -> nothing to do here
152
-
153
- # 3. Repeat for B.
154
- # [topics]
155
- # done below, in rewrap
156
- # [scope]
157
- RTM::AR::TMDM::ScopedObjectsTopic.move_all(["topic_id", other.__getobj__.id, self.__getobj__.id])
158
- # [type]
159
- RTM::AR::TMDM::Association.move_all(["ttype_id", other.__getobj__.id, self.__getobj__.id])
160
- RTM::AR::TMDM::AssociationRole.move_all(["ttype_id", other.__getobj__.id, self.__getobj__.id])
161
- RTM::AR::TMDM::TopicName.move_all(["ttype_id", other.__getobj__.id, self.__getobj__.id])
162
- RTM::AR::TMDM::Occurrence.move_all(["ttype_id", other.__getobj__.id, self.__getobj__.id])
163
-
164
- # [player]
165
- RTM::AR::TMDM::AssociationRole.move_all(["topic_id", other.__getobj__.id, self.__getobj__.id])
166
-
167
- # [reifier]
168
- if other.reified
169
- self.reified = other.reified
170
- end
171
- # 4. Set C's [topic names] property to the union of the values of A and B's [topic names] properties.
172
- #self.names.add_all other.names
173
- count = RTM::AR::TMDM::TopicName.move_all(["topic_id", other.__getobj__.id, self.__getobj__.id])
174
- if count != 0 && count != names.size
175
- names.each_with_index do |n,i|
176
- (i+1).upto(names.size-1) do |j|
177
- if n == names[j]
178
- n.merge names[j]
179
- end
180
- end
181
- end
182
- end
183
-
184
- # 5. Set C's [occurrences] property to the union of the values of A and B's [occurrences] properties.
185
- #self.occurrences.add_all other.occurrences
186
- RTM::AR::TMDM::Occurrence.move_all(["topic_id", other.__getobj__.id, self.__getobj__.id])
187
- if count != 0 && count != occurrences.size
188
- occurrences.each_with_index do |o,i|
189
- (i+1).upto(occurrences.size-1) do |j|
190
- if o == occurrences[j]
191
- o.merge occurrences[j]
192
- end
193
- end
194
- end
195
- end
196
-
197
- # 6. Set C's [subject identifiers] property to the union of the values of A and B's [subject identifiers] properties.
198
- #self.subject_identifiers.add_all other.subject_identifiers
199
- RTM::AR::TMDM::SubjectIdentifier.move_all(["topic_id", other.__getobj__.id, self.__getobj__.id])
200
-
201
- # 7. Set C's [subject locators] property to the union of the values of A and B's [subject locators] properties.
202
- #self.subject_locators.add_all other.subject_locators
203
- RTM::AR::TMDM::SubjectLocator.move_all(["topic_id", other.__getobj__.id, self.__getobj__.id])
204
-
205
- # 8. Set C's [item identifiers] property to the union of the values of A and B's [item identifiers] properties.
206
- #self.item_identifiers.add_all other.item_identifiers
207
- #RTM::AR::TMDM::ItemIdentifier.update_all "topic_map_construct_id = #{self.__getobj__.id}, topic_map_construct_type = '#{self.__getobj__.class.name}'", "topic_map_construct_id = #{other.__getobj__.id} and topic_map_construct_type = '#{other.__getobj__.class.name}'"
208
- RTM::AR::TMDM::ItemIdentifier.move_all(
209
- ["topic_map_construct_id", other.__getobj__.id, self.__getobj__.id],
210
- ["topic_map_construct_type", other.__getobj__.class.name, self.__getobj__.class.name]
211
- )
212
-
213
- self.merge_rewrap other
214
-
215
- self
216
- end
217
- alias :merge_in :merge
218
- end
219
-
220
- module TopicMap
221
- include Merging::MergeReifiable
222
-
223
- def merge(other) # other:TopicMap
224
- self.topics.add_all other.topics
225
- self.associations.add_all other.associations
226
- self.merge_reifiable other
227
- self.merge_item_identifiers other
228
-
229
- self.merge_rewrap other
230
- self
231
- end
232
- alias :merge_in :merge
233
- end
234
-
235
- module TopicName
236
- def merge(other)
237
- # The procedure for merging two topic name items A and B is given below.
238
- # -> we will instead just modify a
239
-
240
- # 1. Create a new topic name item C.
241
- # 2. Set C's [value] property to the value of the [value] property of A. B's value is equal that of A and need not be taken into account.
242
- # 3. Set C's [type] property to the value of the [type] property of A. B's value is equal that of A and need not be taken into account.
243
- # 4. Set C's [scope] property to the value of the [scope] property of A. B's value is equal that of A and need not be taken into account.
244
- # -> nothing to do till here
245
-
246
- # 5. Set C's [variants] property to the union of the [variants] properties of A and B.
247
- #self.variants.add_all other.variants
248
- count = RTM::AR::TMDM::Variant.move_all(["topic_name_id", other.__getobj__.id, self.__getobj__.id])
249
- if count != 0 && count != variants.size
250
- variants.each_with_index do |v,i|
251
- (i+1).upto(variants.size-1) do |j|
252
- if v == variants[j]
253
- v.merge variants[j]
254
- end
255
- end
256
- end
257
- end
258
-
259
- # 6. Set C's [reifier] property to the value of A's [reifier] property if it is not null, and to the value of B's [reifier] property if A's property is null. If both A and B have non-null values, the topic items shall be merged, and the topic item resulting from the merge be set as the value of C's [reifier] property.
260
- self.merge_reifiable other
261
-
262
- # 7. Set C's [item identifiers] property to the union of the value of the [item identifiers] properties of A and B.
263
- self.merge_item_identifiers other
264
-
265
- # 8. Remove A and B from the [topic names] property of the topic item in their [parent] properties, and add C.
266
- #self.parent.names.remove other
267
-
268
- # let the wrapper point to the new object
269
- #other.__setobj__(self.__getobj__) if self.respond_to?(:__getobj__) && other.respond_to?(:__setobj__)
270
- self.merge_rewrap other
271
-
272
- self
273
- end
274
- end
275
-
276
- module Variant
277
- include Merging::MergeReifiable
278
-
279
- def merge(other)
280
- #The procedure for merging two variant items A and B is given below.
281
- # -> we will instead just modify a
282
-
283
- # 1. Create a new variant item, C.
284
- # 2. Set C's [value] property to the value of A's [value] property. B's value is equal to that of A and need not be taken into account.
285
- # 3. Set C's [datatype] property to the value of A's [datatype] property. B's value is equal to that of A and need not be taken into account.
286
- # 4. Set C's [scope] property to the value of A's [scope] property. B's value is equal to that of A and need not be taken into account.
287
- # -> nothing to do till here
288
-
289
- # 5. Set C's [reifier] property to the value of A's [reifier] property if it is not null, and to the value of B's [reifier] property if A's property is null. If both A and B have non-null values, the topic items shall be merged, and the topic item resulting from the merge set as the value of C's [reifier] property.
290
- self.merge_reifiable other
291
-
292
- # 6. Set C's [item identifiers] property to the union of the values of A's and B's [item identifiers] properties.
293
- self.merge_item_identifiers other
294
-
295
- # 7. Remove A and B from the [variants] property of the topic name item in their [parent] properties, and add C.
296
- #self.parent.variants.remove other
297
-
298
- # let the wrapper point to the new object
299
- #other.__setobj__(self.__getobj__) if self.respond_to?(:__getobj__) && other.respond_to?(:__setobj__)
300
- self.merge_rewrap other
301
-
302
- self
303
- end
304
- end
305
- RTM.register_extension( self )
306
- end
307
- end
@@ -1,28 +0,0 @@
1
- module RTM
2
- # Some useful or maybe not so useful stuff which I don't know how to put else.
3
- module PimpMyApi
4
- module Occurrence
5
-
6
- # Create an association out of this occurrence
7
- # Norwegian isa: Language
8
- # - name: "Norwegian"
9
- # - iso639: "no"
10
- # iso639: "no"
11
- # webpage: http://example.org
12
- # to
13
- # webpage( subject: Norwegian, occ: =http://www.example.org )
14
- def externalize
15
- a = parent.create_association
16
- a.create_role parent, RTM::PSI[:subject]
17
- a.create_role self.type, self.value # TODO what should be exactly done with value? prepend something? dependend on param?
18
- a
19
- end
20
- end
21
- def externalize!(*args)
22
- a = externalize(*args)
23
- remove
24
- a
25
- end
26
- RTM.register_extension( self )
27
- end
28
- end
@@ -1,11 +0,0 @@
1
- module RTM::Sugar
2
- module Topic
3
- module IdentifierDirect
4
- def identifiers
5
- subject_identifiers.map{|si| si.to_s} +
6
- subject_locators.map{|sl| "=#{sl.to_s}"} +
7
- item_identifiers.map{|ii| "^#{ii.to_s}"}
8
- end
9
- end
10
- end
11
- end
@@ -1,42 +0,0 @@
1
- module RTM::Sugar
2
- module Topic
3
- module PredefinedAssociations
4
- extend RTM::AR::TraverseAssociations
5
- # maybe these pairs could be declared each with a single statement and a reversible option
6
- define_association :types, :type => :Topic, :rule => {
7
- :transitive => false,
8
- :role_type => RTM::PSI[:instance],
9
- :association_type => RTM::PSI[:type_instance],
10
- :association_arity => 2,
11
- :other_role_type => RTM::PSI[:type],
12
- :infer_other => :supertypes,
13
- :add => :type,
14
- }
15
- define_association :instances, :type => :Topic, :rule => {
16
- :transitive => false,
17
- :role_type => RTM::PSI[:type],
18
- :association_type => RTM::PSI[:type_instance],
19
- :association_arity => 2,
20
- :other_role_type => RTM::PSI[:instance],
21
- :infer => :subtypes,
22
- :add => :instance,
23
- }
24
- define_association :supertypes, :type => :Topic, :rule => {
25
- :transitive => true,
26
- :role_type => RTM::PSI[:subtype],
27
- :association_type => RTM::PSI[:supertype_subtype],
28
- :association_arity => 2,
29
- :other_role_type => RTM::PSI[:supertype],
30
- :add => :supertype,
31
- }
32
- define_association :subtypes, :type => :Topic, :rule => {
33
- :transitive => true,
34
- :role_type => RTM::PSI[:supertype],
35
- :association_type => RTM::PSI[:supertype_subtype],
36
- :association_arity => 2,
37
- :other_role_type => RTM::PSI[:subtype],
38
- :add => :subtype,
39
- }
40
- end
41
- end
42
- end
@@ -1,16 +0,0 @@
1
- require 'rtm'
2
- RTM.connect
3
- puts "connected"
4
- tm = RTM.create "a:b"
5
- bla = tm.get!("bla")
6
- bla["-name"] = "test"
7
- n = bla["-name"].first
8
- puts n.inspect
9
-
10
- bla["-"] = "defaultname yeah!"
11
-
12
- puts tm.t.size
13
- dm = tm.get!("delete_me")
14
- puts tm.t.size
15
- dm.remove
16
- puts tm.t.size
@@ -1,162 +0,0 @@
1
- #
2
- # Some basic tests... feel free to add more :)
3
- #
4
-
5
-
6
- $:.unshift File.join(File.dirname(__FILE__),'..','lib')
7
-
8
- require 'test/unit'
9
- require 'rtm'
10
-
11
- class BaseTest < Test::Unit::TestCase
12
- # There are a bunch of global assertions in here so it cannot be parallelized
13
- # with other tests, that's why it is all in one. What can we do about that?
14
- def test_connect
15
- assert RTM.connect, "Connection to memory backend failed"
16
- assert_equal 0, RTM[].size, "There should be no topic maps in a newly created environment."
17
- base_locator = "http://rtm.rubyforge.org/tests/base_test"
18
- m = RTM.create base_locator
19
- assert_equal 1, RTM[].size, "After creation of a topic map, there should be one."
20
- assert_kind_of RTM::TopicMap, m, "RTM.create should create something which includes RTM::TopicMap"
21
- assert_equal base_locator, m.base_locator, "The base_locator should be initialized properly."
22
- assert m.respond_to?(:topics), "The topic map should respond to :topics"
23
- assert m.respond_to?(:associations), "The topic map should respond to :topics"
24
- assert_equal 0, m.topics.size, "A new topic map should have no topics."
25
- assert_equal 0, m.associations.size, "A new topic map should have no associations."
26
- assert m.reifier.nil?, "A new topic map should not be reified yet."
27
- assert_equal 0, m.item_identifiers.size, "A new topic map should "
28
-
29
- # assigning a reifier
30
- m.reifier = "a_topic_which_reifies_the_topic_map"
31
- assert_equal 1, m.topics.size, "A topic should have been created to reify the topic map."
32
- assert_kind_of RTM::Topic, m.reifier, "A reifier should be a Topic."
33
-
34
- assert_equal m, m.topics.first.reified, "The only topic out there should reify the map (not generally, but here)."
35
- assert_equal m.base_locator, m.topics.first.reified.base_locator, "The only topic out there should reify the map. Check base locator."
36
- assert_equal m.__getobj__, m.topics.first.reified.__getobj__, "The only topic out there should reify the map. Look inside."
37
-
38
- t = m.create_topic
39
- assert_equal 2, m.topics.size, "There should be 2 topics after creating the second one."
40
- assert_kind_of RTM::Topic, t, "The created topic should really be one."
41
- assert_kind_of RTM::TopicMap, m
42
- assert_equal m, t.parent, "The Topic Map should be the parent of our new topic."
43
- # The next tests may look a bit unneeded, but they at least also test the properties be available and initialized somehow.
44
- assert_equal 0, t.item_identifiers.size, "New topic has no item_identifiers."
45
- assert_equal 0, t.subject_identifiers.size, "New topic has no subject_identifiers."
46
- assert_equal 0, t.subject_locators.size, "New topic has no subject_locators."
47
- assert !t.valid?, "Without item identifiers nor subject identifiers the topic must not be valid."
48
- assert_equal 0, t.names.size, "New topic has no names."
49
- assert_equal 0, t.occurrences.size, "New topic has no occurrences."
50
- assert_equal 0, t.roles_played.size, "New topic plays no roles."
51
- assert_nil t.reified, "New topic does not reify a statement."
52
-
53
- n = t.create_name
54
- assert_equal 1, t.names.size, "The topic should have one name now."
55
- assert_kind_of RTM::TopicName, n
56
- assert_kind_of RTM::Topic, n.parent, "You won't believe but this should be a Topic and right now it not..."
57
- # TODO the following assertion does not work - it crashes pp... but why?
58
- #assert_equal t, n.parent, "The parent of the name should be the topic on which it was created."
59
- assert_equal 0, n.item_identifiers.size, "I wonder if someone will ever read that."
60
- assert_kind_of RTM::TopicName, n, "The topic name shoud be a TopicName... makes sence, he?"
61
- assert_equal 0, n.variants.size, "According to Lars Heuer and Robert Barta that should always be 0, not only now."
62
- assert_nil n.value, "We haven't set a value yet, where should it come from."
63
- assert_nil n.type, "I am really tired of writing this stuff."
64
- assert_equal 0, n.scope.size, "Should I really be more serious with this stuff?"
65
- assert_nil n.reifier, "No, I guess not... who could ever stand that."
66
-
67
- v = n.create_variant
68
- assert_equal 1, n.variants.size, "The topic should have one name now."
69
- assert_kind_of RTM::Variant, v
70
- assert_kind_of RTM::TopicName, v.parent, "You won't believe but this should be a Topic and right now it not..."
71
- # TODO the following assertion does not work - it crashes pp... but why?
72
- #assert_equal t, v.parent, "The parent of the name should be the topic on which it was created."
73
- assert_equal 0, v.item_identifiers.size, "I wonder if someone will ever read that."
74
- assert_kind_of RTM::Variant, v, "The variant should be a Variant... makes sence, he?"
75
- assert_nil v.value, "We haven't set a value yet, where should it come from."
76
- assert_nil v.datatype, "No datatype set, yet."
77
- assert_equal 0, v.scope.size, "Should I really be more serious with this stuff?"
78
- assert_nil v.reifier, "No, I guess not... who could ever stand that."
79
- assert !v.valid?
80
-
81
- o = t.create_occurrence
82
- assert_equal 1, t.occurrences.size, "The topic should have one name now."
83
- assert_kind_of RTM::Occurrence, o
84
- assert_kind_of RTM::Topic, o.parent, "You won't believe but this should be a Topic and right now it not..."
85
- # TODO the following assertion does not work - it crashes pp... but why?
86
- #assert_equal t, o.parent, "The parent of the name should be the topic on which it was created."
87
- assert_equal 0, o.item_identifiers.size, "I wonder if someone will ever read that."
88
- assert_kind_of RTM::Occurrence, o, "The occurrence shoud be a Occurrence... makes sence, he?"
89
- assert_nil o.value, "We haven't set a value yet, where should it come from."
90
- assert_nil o.type, "I am really tired of writing this stuff."
91
- assert_nil o.datatype
92
- assert_equal 0, n.scope.size, "Should I really be more serious with this stuff?"
93
- assert_nil n.reifier, "No, I guess not... who could ever stand that."
94
-
95
- a = m.create_association
96
- assert_nil a.type
97
- assert_equal 0, a.roles.size
98
- assert_kind_of RTM::Association, a
99
- assert_kind_of RTM::TopicMap, a.parent
100
- assert_equal m, a.parent
101
- assert_equal 0, a.scope.size
102
- assert !a.valid?
103
-
104
- r1 = a.create_role
105
- assert_nil r1.type
106
- assert_nil r1.player
107
- assert_kind_of RTM::AssociationRole, r1
108
- assert_kind_of RTM::Association, r1.parent
109
- assert_equal 1, a.roles.size
110
-
111
-
112
- t.item_identifiers << "nr1"
113
- assert_equal 1, t.item_identifiers.size
114
- fii = t.item_identifiers.first
115
- assert_equal "http://rtm.rubyforge.org/tests/base_test#nr1", fii.to_s
116
- assert_kind_of RTM::Locator, fii
117
- assert_kind_of RTM::ItemIdentifier, fii #needed?
118
- # TODO: invalidate cache/reload value somehow
119
- #assert_equal 1, m.item_identifiers.size, "If you see this, it is probably because TopicMap#item_identifiers.size is cached which is wrong in this case."
120
-
121
- t.subject_identifiers << "si1"
122
- fsi = t.subject_identifiers.first
123
- assert_equal "si1", fsi.to_s
124
- assert_kind_of RTM::Locator, fsi
125
- assert_kind_of RTM::SubjectIdentifier, fsi #needed?
126
-
127
- t.subject_locators << "sl1"
128
- fsl = t.subject_locators.first
129
- assert_equal "sl1", fsl.to_s
130
- assert_kind_of RTM::Locator, fsl
131
- assert_kind_of RTM::SubjectLocator, fsl #needed?
132
-
133
- # create roles with topics
134
- # some more stuff.
135
-
136
-
137
- # to be in associations_test later:
138
- tm = RTM.create "urn:/associations_test"
139
- a1 = tm.create_association "urn:/assoc_type_with_absolute_uri"
140
- assert_not_nil a1.type
141
- assert_equal a1.type, tm.get("urn:/assoc_type_with_absolute_uri")
142
-
143
- a2 = tm.create_association :type => "urn:/assoc_type_with_absolute_uri_using_hash"
144
- assert_not_nil a2.type
145
- assert_equal a2.type, tm.get("urn:/assoc_type_with_absolute_uri_using_hash")
146
-
147
- a3 = tm.create_association "relative_type"
148
- assert_not_nil a3.type
149
- assert_equal a3.type, tm.get("relative_type")
150
-
151
-
152
- end
153
- def test_sugar_hash_access
154
- RTM.connect
155
- tm = RTM.create "a:b"
156
- bla = tm.get!("bla")
157
- bla["-name"] = "test"
158
- n = bla["-name"].first
159
-
160
- end
161
-
162
- end