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.
- data/DISCLAIMER +10 -33
- data/LICENSE +201 -0
- data/README +32 -3
- data/lib/rtm.rb +126 -74
- data/lib/rtm/axes.rb +298 -0
- data/lib/rtm/axes/association.rb +76 -0
- data/lib/rtm/axes/associations.rb +96 -0
- data/lib/rtm/axes/assocs_names_occs.rb +56 -0
- data/lib/rtm/axes/characteristic.rb +68 -0
- data/lib/rtm/axes/characteristics.rb +93 -0
- data/lib/rtm/axes/string.rb +76 -0
- data/lib/rtm/axes/strings.rb +87 -0
- data/lib/rtm/axes/topic.rb +233 -0
- data/lib/rtm/axes/topics.rb +280 -0
- data/lib/rtm/{backward_compatibility.rb → deprecated/index_property_set.rb} +3 -0
- data/lib/rtm/engine.rb +101 -0
- data/lib/rtm/extensions.rb +65 -5
- data/lib/rtm/{locator_helpers.rb → helpers/locator.rb} +15 -4
- data/lib/rtm/{helpers.rb → helpers/no_output.rb} +3 -0
- data/lib/rtm/helpers/uri.rb +13 -0
- data/lib/rtm/io.rb +19 -0
- data/lib/rtm/io/from_xtm2_libxml.rb +2 -1
- data/lib/rtm/io/tmapix_from.rb +155 -0
- data/lib/rtm/io/tmapix_to.rb +223 -0
- data/lib/rtm/io/to_hash.rb +154 -0
- data/lib/rtm/io/to_jtm.rb +53 -103
- data/lib/rtm/io/to_rdf.rb +45 -0
- data/lib/rtm/io/to_string.rb +21 -8
- data/lib/rtm/io/to_xtm1.rb +6 -4
- data/lib/rtm/io/to_xtm2.rb +10 -8
- data/lib/rtm/io/to_yaml.rb +59 -100
- data/lib/rtm/navigation.rb +23 -0
- data/lib/rtm/navigation/association/players.rb +25 -0
- data/lib/rtm/navigation/name/atomify.rb +19 -0
- data/lib/rtm/navigation/name/characteristics.rb +33 -0
- data/lib/rtm/navigation/occurrence/atomify.rb +19 -0
- data/lib/rtm/navigation/occurrence/characteristics.rb +33 -0
- data/lib/rtm/navigation/topic/characteristics.rb +33 -0
- data/lib/rtm/navigation/topic/indicators.rb +31 -0
- data/lib/rtm/navigation/topic/items.rb +31 -0
- data/lib/rtm/navigation/topic/locators.rb +31 -0
- data/lib/rtm/navigation/topic/players.rb +27 -0
- data/lib/rtm/navigation/topic/supertypes.rb +166 -0
- data/lib/rtm/navigation/topic/traverse.rb +51 -0
- data/lib/rtm/navigation/topic/types.rb +109 -0
- data/lib/rtm/psi.rb +39 -2
- data/lib/rtm/sugar.rb +47 -0
- data/lib/rtm/sugar/association/hash_access.rb +46 -0
- data/lib/rtm/sugar/occurrence/dynamic_value.rb +58 -0
- data/lib/rtm/sugar/occurrence/external.rb +53 -0
- data/lib/rtm/sugar/reifiable/reifier.rb +21 -0
- data/lib/rtm/sugar/role/counterparts.rb +139 -46
- data/lib/rtm/sugar/topic/best_name.rb +74 -0
- data/lib/rtm/sugar/topic/characteristics.rb +126 -12
- data/lib/rtm/sugar/topic/counterparts.rb +145 -10
- data/lib/rtm/sugar/topic/hash_access.rb +140 -30
- data/lib/rtm/sugar/topic/scoped.rb +114 -0
- data/lib/rtm/sugar/topic/topic_ref.rb +86 -0
- data/lib/rtm/sugar/topic/typed.rb +207 -0
- data/lib/rtm/sugar/topic_map/query_cache.rb +66 -0
- data/lib/rtm/sugar/topic_map/themes.rb +53 -0
- data/lib/rtm/sugar/typed/types.rb +38 -0
- data/lib/rtm/validation.rb +7 -4
- data/lib/rtm/version.rb +30 -0
- data/spec/helpers/spec_exampleexamplegroup.rb +14 -0
- data/spec/rtm/axes/association_spec.rb +88 -0
- data/spec/rtm/axes/associations_spec.rb +60 -0
- data/spec/rtm/axes/assocs_names_occs_spec.rb +9 -0
- data/spec/rtm/axes/characteristic_spec.rb +90 -0
- data/spec/rtm/axes/characteristics_spec.rb +85 -0
- data/spec/rtm/axes/string_spec.rb +145 -0
- data/spec/rtm/axes/strings_spec.rb +168 -0
- data/spec/rtm/axes/topic_spec.rb +124 -0
- data/spec/rtm/axes/topics_spec.rb +103 -0
- data/spec/rtm/base_spec.rb +32 -0
- data/spec/rtm/io/tmapix_from_spec.rb +76 -0
- data/spec/rtm/io/tmapix_to_spec.rb +159 -0
- data/spec/rtm/io/to_hash_spec.rb +90 -0
- data/spec/rtm/io/to_rdf_spec.rb +37 -0
- data/spec/rtm/io/to_string_spec.rb +122 -0
- data/spec/rtm/io/to_yaml_spec.rb +89 -0
- data/spec/rtm/navigation/association/players_spec.rb +58 -0
- data/spec/rtm/navigation/association_spec.rb +52 -0
- data/spec/rtm/navigation/name/atomify_spec.rb +27 -0
- data/spec/rtm/navigation/name/characteristics_spec.rb +34 -0
- data/spec/rtm/navigation/name_spec.rb +52 -0
- data/spec/rtm/navigation/occurrence/atomify_spec.rb +27 -0
- data/spec/rtm/navigation/occurrence/characteristics_spec.rb +34 -0
- data/spec/rtm/navigation/occurrence_spec.rb +52 -0
- data/spec/rtm/navigation/string_spec.rb +51 -0
- data/spec/rtm/navigation/topic/characteristics_spec.rb +55 -0
- data/spec/rtm/navigation/topic/indicators_spec.rb +43 -0
- data/spec/rtm/navigation/topic/items_spec.rb +44 -0
- data/spec/rtm/navigation/topic/locators_spec.rb +44 -0
- data/spec/rtm/navigation/topic/players_spec.rb +48 -0
- data/spec/rtm/navigation/topic/scope_spec.rb +41 -0
- data/spec/rtm/navigation/topic/supertypes_spec.rb +376 -0
- data/spec/rtm/navigation/topic/traverse_spec.rb +64 -0
- data/spec/rtm/navigation/topic/types_spec.rb +195 -0
- data/spec/rtm/navigation/topic_spec.rb +153 -0
- data/spec/rtm/sugar/association/hash_access_spec.rb +55 -0
- data/spec/rtm/sugar/occurrence/dynamic_value_spec.rb +171 -0
- data/spec/rtm/sugar/occurrence/external_spec.rb +129 -0
- data/spec/rtm/sugar/reifiable/reifier_spec.rb +41 -0
- data/spec/rtm/sugar/role/counterparts_spec.rb +193 -0
- data/spec/rtm/sugar/topic/best_name_spec.rb +25 -0
- data/spec/rtm/sugar/topic/characteristics_spec.rb +333 -0
- data/spec/rtm/sugar/topic/counterparts_spec.rb +224 -0
- data/spec/rtm/sugar/topic/hash_access_spec.rb +234 -0
- data/spec/rtm/sugar/topic/scoped_spec.rb +195 -0
- data/spec/rtm/sugar/topic/topic_ref_spec.rb +44 -0
- data/spec/rtm/sugar/topic/typed_spec.rb +217 -0
- data/spec/rtm/sugar/topic_map/themes_spec.rb +67 -0
- data/spec/rtm/sugar/typed/types_spec.rb +24 -0
- data/spec/rtm/tmapi/core/association_spec.rb +169 -0
- data/spec/rtm/tmapi/core/construct_spec.rb +25 -0
- data/spec/rtm/tmapi/core/datatype_aware_spec.rb +236 -0
- data/spec/rtm/tmapi/core/name_spec.rb +270 -0
- data/spec/rtm/tmapi/core/occurrence_spec.rb +53 -0
- data/spec/rtm/tmapi/core/reifiable_spec.rb +168 -0
- data/spec/rtm/tmapi/core/role_spec.rb +73 -0
- data/spec/rtm/tmapi/core/scoped_spec.rb +441 -0
- data/spec/rtm/tmapi/core/topic_map_spec.rb +716 -0
- data/spec/rtm/tmapi/core/topic_spec.rb +1468 -0
- data/spec/rtm/tmapi/core/typed_spec.rb +112 -0
- data/spec/rtm/tmapi/core/variant_spec.rb +52 -0
- data/spec/rtm/tmapi/ext/java_util_set_spec.rb +34 -0
- data/spec/rtm/tmapi_spec.rb +44 -0
- data/spec/rtm/utils/sparql_spec.rb +26 -0
- data/spec/rtm_spec.rb +93 -0
- data/spec/spec_helper.rb +28 -0
- data/test/javalibs/junit-4.5.jar +0 -0
- data/test/javalibs/tmapi-2.0-tests.jar +0 -0
- data/test/tmapi_tests.rb +25 -0
- metadata +169 -65
- data/COPYRIGHT +0 -4
- data/lib/Rakefile.rb +0 -42
- data/lib/activetopicmaps.rb +0 -278
- data/lib/rtm/backend/active_record.rb +0 -58
- data/lib/rtm/backend/active_record/001_initial_schema.rb +0 -116
- data/lib/rtm/backend/active_record/association_and_role.rb +0 -33
- data/lib/rtm/backend/active_record/locators.rb +0 -55
- data/lib/rtm/backend/active_record/name_variant_occurrence.rb +0 -45
- data/lib/rtm/backend/active_record/quaaxtm2rtm.rb +0 -113
- data/lib/rtm/backend/active_record/quaaxtm2rtmviews.rb +0 -134
- data/lib/rtm/backend/active_record/set_wrapper.rb +0 -98
- data/lib/rtm/backend/active_record/tm_construct.rb +0 -62
- data/lib/rtm/backend/active_record/tm_delegator.rb +0 -345
- data/lib/rtm/backend/active_record/tm_set_delegator.rb +0 -195
- data/lib/rtm/backend/active_record/tmdm.rb +0 -298
- data/lib/rtm/backend/active_record/topic.rb +0 -87
- data/lib/rtm/backend/active_record/topic_map.rb +0 -314
- data/lib/rtm/backend/active_record/traverse_associations.rb +0 -87
- data/lib/rtm/base.rb +0 -92
- data/lib/rtm/connect.rb +0 -92
- data/lib/rtm/core_ext.rb +0 -6
- data/lib/rtm/io/from_xtm2.rb +0 -263
- data/lib/rtm/merging/merging.rb +0 -307
- data/lib/rtm/pimp_my_api.rb +0 -28
- data/lib/rtm/sugar/topic/identifier_direct.rb +0 -11
- data/lib/rtm/sugar/topic/predefined_associations.rb +0 -42
- data/lib/run_main_project.rb +0 -16
- data/test/base_test.rb +0 -162
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
|
2
|
+
# License: Apache License, Version 2.0
|
|
3
|
+
|
|
4
|
+
module RTM::Axes
|
|
5
|
+
module Topics
|
|
6
|
+
|
|
7
|
+
def self.extended(k)
|
|
8
|
+
k.extend ArrayProxy
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def result
|
|
12
|
+
self.map{|i| i.construct}
|
|
13
|
+
end
|
|
14
|
+
alias :tmapi :result
|
|
15
|
+
|
|
16
|
+
# ---- characteristics-axis ----------------------------------------------#
|
|
17
|
+
|
|
18
|
+
# Returns all Names and Occurrences of these Topics.
|
|
19
|
+
# If an identifier is given, only those Names and Occurrences are returned,
|
|
20
|
+
# whose type or supertypes include the identifier.
|
|
21
|
+
#
|
|
22
|
+
# Identifier may be a topic reference.
|
|
23
|
+
#
|
|
24
|
+
# The result may be empty.
|
|
25
|
+
#
|
|
26
|
+
# :call-seq:
|
|
27
|
+
# characteristics -> Array of Names and Occurrences
|
|
28
|
+
# characteristics(identifier) -> Array of Names and Occurrences
|
|
29
|
+
#
|
|
30
|
+
def characteristics(type=:any)
|
|
31
|
+
_res = self.inject([]){|all,containee| all << containee.send(:characteristics,type)}.flatten
|
|
32
|
+
### NO UNIQUE NEEDED
|
|
33
|
+
_res = _res.extend(Characteristics)
|
|
34
|
+
_res
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# ---- indicators-axis ---------------------------------------------------#
|
|
38
|
+
|
|
39
|
+
# Returns all indicators (subject identifiers) of these Topics.
|
|
40
|
+
#
|
|
41
|
+
# The result may be empty.
|
|
42
|
+
#
|
|
43
|
+
# :call-seq:
|
|
44
|
+
# indicators -> Array of Strings
|
|
45
|
+
#
|
|
46
|
+
def indicators
|
|
47
|
+
#self = Array of TopicProxies
|
|
48
|
+
#containee: RTM::Axes::Topic
|
|
49
|
+
#send -> Array of Strings
|
|
50
|
+
self.inject([]){|all,containee| all << containee.send(:indicators)}.flatten
|
|
51
|
+
### NO UNIQUE NEEDED
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# ---- item-axis ---------------------------------------------------------#
|
|
55
|
+
|
|
56
|
+
# Returns one item identifier for each of these Topics, only if
|
|
57
|
+
# if the Topic has an item identifier.
|
|
58
|
+
#
|
|
59
|
+
# The result may be an empty Array.
|
|
60
|
+
#
|
|
61
|
+
# :call-seq:
|
|
62
|
+
# item -> Array of Strings
|
|
63
|
+
#
|
|
64
|
+
def item
|
|
65
|
+
#self = Array of TopicProxies
|
|
66
|
+
#containee: RTM::Axes::Topic
|
|
67
|
+
#send -> Array of (String or nil)s
|
|
68
|
+
_res = self.inject([]){|all,containee| all << containee.send(:item)}.flatten
|
|
69
|
+
_res = _res.select{|i| i}
|
|
70
|
+
### NO UNIQUE NEEDED
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# ---- locators-axis -----------------------------------------------------#
|
|
74
|
+
|
|
75
|
+
# Returns all subject locators of these Topics.
|
|
76
|
+
#
|
|
77
|
+
# The result may be empty.
|
|
78
|
+
#
|
|
79
|
+
# :call-seq:
|
|
80
|
+
# locators -> Array of Strings
|
|
81
|
+
#
|
|
82
|
+
def locators
|
|
83
|
+
self.inject([]){|all,containee| all << containee.send(:locators)}.flatten
|
|
84
|
+
### NO UNIQUE NEEDED
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# ---- players-axis ------------------------------------------------------#
|
|
88
|
+
|
|
89
|
+
# Returns all Associations in which these Topics play a Role.
|
|
90
|
+
#
|
|
91
|
+
# The optional
|
|
92
|
+
# identifier specifies the type of the Roles to be considered.
|
|
93
|
+
# The identifier may be a topic reference.
|
|
94
|
+
#
|
|
95
|
+
# Multiple instances of the same Association are possible.
|
|
96
|
+
# The result may be empty.
|
|
97
|
+
#
|
|
98
|
+
# :call-seq:
|
|
99
|
+
# reverse_players -> Array of Associations
|
|
100
|
+
# reverse_players(identifier) -> Array of Associations
|
|
101
|
+
#
|
|
102
|
+
def reverse_players(type=:any)
|
|
103
|
+
_res = self.inject([]){|all,containee| all << containee.send(:reverse_players,type)}.flatten
|
|
104
|
+
### NO UNIQUE ###
|
|
105
|
+
_res = _res.extend(Associations)
|
|
106
|
+
_res
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# ---- reifier-axis ------------------------------------------------------#
|
|
110
|
+
|
|
111
|
+
# Returns the Constructs which are reified by one of these Topics
|
|
112
|
+
# only if such Constructs exist.
|
|
113
|
+
#
|
|
114
|
+
# :call-seq:
|
|
115
|
+
# reifier -> Array of Associations, Names and Occurrences
|
|
116
|
+
#
|
|
117
|
+
def reifier
|
|
118
|
+
_res = self.inject([]){|all,containee| all << containee.send(:reifier)}.flatten
|
|
119
|
+
_res = _res.select{|i| i} #reject nil
|
|
120
|
+
### NO UNIQUE NEEDED
|
|
121
|
+
_res = _res.extend(AssocsNamesOccs)
|
|
122
|
+
_res
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# ---- roles-axis --------------------------------------------------------#
|
|
126
|
+
|
|
127
|
+
# Returns all Associations that have Roles that have one of
|
|
128
|
+
# these Topics as Roletype. Multiple instances of the same
|
|
129
|
+
# Association are possible.
|
|
130
|
+
#
|
|
131
|
+
# The result may be empty.
|
|
132
|
+
#
|
|
133
|
+
# :call-seq:
|
|
134
|
+
# reverse_roles -> Array of Associations
|
|
135
|
+
#
|
|
136
|
+
def reverse_roles
|
|
137
|
+
_res = self.inject([]){|all,containee| all << containee.send(:reverse_roles)}.flatten
|
|
138
|
+
### NO UNIQUE ###
|
|
139
|
+
_res = _res.extend(Associations)
|
|
140
|
+
_res
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# ---- scope-axis --------------------------------------------------------#
|
|
144
|
+
|
|
145
|
+
# Returns all Associations, Names and Occurrences that include at least one of these
|
|
146
|
+
# Topics (themes) in their scope.
|
|
147
|
+
#
|
|
148
|
+
# The result may be empty.
|
|
149
|
+
#
|
|
150
|
+
# :call-seq:
|
|
151
|
+
# reverse_scope -> Array of Names, Associations and Occurrences
|
|
152
|
+
#
|
|
153
|
+
def reverse_scope
|
|
154
|
+
_res = self.inject([]){|all,containee| all << containee.send(:reverse_scope)}.flatten
|
|
155
|
+
### FLAG UNIQUE ###
|
|
156
|
+
_res = _res.map{|i| i.construct}.uniq.map{|i| i.axes}
|
|
157
|
+
### ###
|
|
158
|
+
_res = _res.extend(AssocsNamesOccs)
|
|
159
|
+
_res
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# ---- supertypes-axis ---------------------------------------------------#
|
|
163
|
+
|
|
164
|
+
# Returns all supertypes of all of these Topics. The result includes
|
|
165
|
+
# all direct supertypes
|
|
166
|
+
# and the supertypes of these direct supertypes.
|
|
167
|
+
#
|
|
168
|
+
# The result may be an empty Array.
|
|
169
|
+
#
|
|
170
|
+
# :call-seq:
|
|
171
|
+
# supertypes -> Array of Topics
|
|
172
|
+
#
|
|
173
|
+
def supertypes
|
|
174
|
+
_res = self.define_helper(:supertypes)
|
|
175
|
+
#_res = self.inject([]){|all,containee| all << containee.send(:supertypes)}.flatten
|
|
176
|
+
### FLAG UNIQUE ###
|
|
177
|
+
_res = _res.map{|i| i.construct}.uniq.map{|i| i.axes}
|
|
178
|
+
### ###
|
|
179
|
+
_res = _res.extend(Topics)
|
|
180
|
+
_res
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# Returns all subtypes of all of these Topics. The result includes the direct subtypes
|
|
184
|
+
# and the subtypes of these direct subtypes.
|
|
185
|
+
#
|
|
186
|
+
# The result may be an empty Array.
|
|
187
|
+
#
|
|
188
|
+
# :call-seq:
|
|
189
|
+
# subtypes -> Array of Topics
|
|
190
|
+
#
|
|
191
|
+
def subtypes
|
|
192
|
+
_res = self.inject([]){|all,containee| all << containee.send(:subtypes)}.flatten
|
|
193
|
+
### FLAG UNIQUE ###
|
|
194
|
+
_res = _res.map{|i| i.construct}.uniq.map{|i| i.axes}
|
|
195
|
+
### ###
|
|
196
|
+
_res = _res.extend(Topics)
|
|
197
|
+
_res
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
alias reverse_subtypes supertypes
|
|
201
|
+
alias reverse_supertypes subtypes
|
|
202
|
+
|
|
203
|
+
# ---- traverse-axis ---------------------------------------------------#
|
|
204
|
+
|
|
205
|
+
# First computes all Associations where these Topics play a Role.
|
|
206
|
+
# There, the optional identifier filters the Associations for their type.
|
|
207
|
+
#
|
|
208
|
+
# Returns all Players of all Roles in these Associations.
|
|
209
|
+
# Each Topic is deducted ones from the returned Array.
|
|
210
|
+
# The result may be empty.
|
|
211
|
+
#
|
|
212
|
+
# The identifier may be a topic reference.
|
|
213
|
+
#
|
|
214
|
+
# :call-seq:
|
|
215
|
+
# traverse(identifier) -> Array of Topics
|
|
216
|
+
#
|
|
217
|
+
def traverse(type=:any)
|
|
218
|
+
_res = self.inject([]){|all,containee| all << containee.send(:traverse,type)}.flatten
|
|
219
|
+
### NO UNIQUE ###
|
|
220
|
+
_res = _res.extend(Topics)
|
|
221
|
+
_res
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
# Always returns an empty Array
|
|
225
|
+
#
|
|
226
|
+
# :call-seq:
|
|
227
|
+
# reverse_traverse -> Array of Topics
|
|
228
|
+
#
|
|
229
|
+
def reverse_traverse
|
|
230
|
+
_res = [] #HARDCODED
|
|
231
|
+
_res.extend(Topics)
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
# ---- types-axis --------------------------------------------------------#
|
|
235
|
+
|
|
236
|
+
# Returns the Topics these Topics are instances of. Calls
|
|
237
|
+
# the TMAPI getTypes method.
|
|
238
|
+
#
|
|
239
|
+
# The result may be empty.
|
|
240
|
+
#
|
|
241
|
+
# :call-seq:
|
|
242
|
+
# types -> Array of Topics
|
|
243
|
+
#
|
|
244
|
+
def types
|
|
245
|
+
#self = Array of TopicProxies
|
|
246
|
+
#containee: RTM::Axes::Topic
|
|
247
|
+
#send -> Array of TopicProxies
|
|
248
|
+
#uniq -> Topics in Array, call unique on Array
|
|
249
|
+
#convert to TopicProxies again
|
|
250
|
+
#extend result-Array
|
|
251
|
+
_res = self.inject([]){|all,containee| all << containee.send(:types)}.flatten
|
|
252
|
+
### FLAG UNIQUE ###
|
|
253
|
+
_res = _res.map{|i| i.construct}.uniq.map{|i| i.axes}
|
|
254
|
+
### ###
|
|
255
|
+
_res.extend(Topics)
|
|
256
|
+
_res
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
# Returns the Topics which are instances of these Topics.
|
|
260
|
+
# Uses the TMAPI TypeInstanceIndex.
|
|
261
|
+
#
|
|
262
|
+
# The result may be empty.
|
|
263
|
+
#
|
|
264
|
+
# :call-seq:
|
|
265
|
+
# instances -> Array of Topics
|
|
266
|
+
#
|
|
267
|
+
def instances
|
|
268
|
+
_res = self.inject([]){|all,containee| all << containee.send(:instances)}.flatten
|
|
269
|
+
### FLAG UNIQUE ###
|
|
270
|
+
_res = _res.map{|i| i.construct}.uniq.map{|i| i.axes}
|
|
271
|
+
### ###
|
|
272
|
+
_res.extend(Topics)
|
|
273
|
+
_res
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
alias reverse_types instances
|
|
277
|
+
alias reverse_instances types
|
|
278
|
+
|
|
279
|
+
end
|
|
280
|
+
end
|
data/lib/rtm/engine.rb
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
module RTM
|
|
2
|
+
class Engine
|
|
3
|
+
include RTM::TopicMapSystem
|
|
4
|
+
|
|
5
|
+
def self.abstract?
|
|
6
|
+
self == Engine
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.inherited(subclass)
|
|
10
|
+
Engine.add(subclass) # this MUST be Engine and not self! Otherwise every intermediate class in the inheritance chain will have it's own list
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.add(engine)
|
|
14
|
+
@engines ||= []
|
|
15
|
+
@engines << engine
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.identifier(i=nil)
|
|
19
|
+
if i
|
|
20
|
+
# setter / declaration
|
|
21
|
+
@identifier = i
|
|
22
|
+
else
|
|
23
|
+
# getter
|
|
24
|
+
@identifier
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.all
|
|
29
|
+
@engines ||= []
|
|
30
|
+
@engines.reject!{|e| e.abstract?} # this needs to be done here because in the inherited hook the method is not yet available.
|
|
31
|
+
@engines
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.list
|
|
35
|
+
all.map{|e| e.identifier}
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.[](identifier)
|
|
39
|
+
all.find {|e| e.identifier == identifier}
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.load(engine_name)
|
|
43
|
+
if Object.const_defined?("Gem") && rtmgem = Gem.loaded_specs["rtm"]
|
|
44
|
+
require "rtm/#{engine_name}"
|
|
45
|
+
else
|
|
46
|
+
engine_path = File.expand_path(File.join(File.dirname(__FILE__), "../../../rtm-#{engine_name}/lib"))
|
|
47
|
+
if File.directory?(engine_path)
|
|
48
|
+
$LOAD_PATH.unshift engine_path
|
|
49
|
+
require "rtm/#{engine_name}"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
self[engine_name]
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def self.load!(engine_name=nil)
|
|
56
|
+
engine_name = self.detect unless engine_name
|
|
57
|
+
unless list.include?(engine_name)
|
|
58
|
+
warn("Requested engine '#{engine_name}' not loaded. Trying to autoload it.")
|
|
59
|
+
engine = load(engine_name)
|
|
60
|
+
if list.include?(engine_name)
|
|
61
|
+
warn("Autoloading '#{engine_name}' was successful")
|
|
62
|
+
else
|
|
63
|
+
raise "Autoloading '#{engine_name}' failed. Make sure rtm-#{engine_name} exists and is installed or require it manually."
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
engine || load(engine_name)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def self.detect(preferred=nil)
|
|
70
|
+
if preferred # return the users preference, if given
|
|
71
|
+
implementation = preferred
|
|
72
|
+
elsif engine_name = ENV['RTM_IMPLEMENTATION'] # inspect system environment
|
|
73
|
+
implementation = engine_name.to_sym
|
|
74
|
+
elsif engine_name = ENV['RTM_ENGINE'] # inspect system environment (alternative)
|
|
75
|
+
implementation = engine_name.to_sym
|
|
76
|
+
elsif implementation = self.list.first # check if one is already loaded
|
|
77
|
+
warn("No engine implementation was specified for RTM.connect. Using the first already loaded engine (#{implementation.inspect}).")
|
|
78
|
+
else
|
|
79
|
+
implementation = self.default # use hardcoded default
|
|
80
|
+
warn("No engine implementation was specified for RTM.connect. Choosing default (#{implementation.inspect}).")
|
|
81
|
+
implementation
|
|
82
|
+
end
|
|
83
|
+
implementation
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def self.default
|
|
87
|
+
if RUBY_PLATFORM =~ /java/
|
|
88
|
+
:ontopia
|
|
89
|
+
else
|
|
90
|
+
:activerecord
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
attr_reader :connections
|
|
95
|
+
|
|
96
|
+
def initialize(params={})
|
|
97
|
+
@params = params
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
end
|
|
101
|
+
end
|
data/lib/rtm/extensions.rb
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
|
2
|
+
# License: Apache License, Version 2.0
|
|
3
|
+
|
|
1
4
|
module RTM
|
|
2
|
-
# Register a module as extension.
|
|
5
|
+
# Register a module as extension to RTM.
|
|
3
6
|
#
|
|
4
7
|
# Example:
|
|
5
8
|
# module MyExtension
|
|
@@ -11,9 +14,66 @@ module RTM
|
|
|
11
14
|
# RTM.register_extension(self)
|
|
12
15
|
# end
|
|
13
16
|
#
|
|
14
|
-
def self.register_extension(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
def self.register_extension(module_with_modules)
|
|
18
|
+
# puts "[RTMEXT] registering extension #{module_with_modules}"
|
|
19
|
+
module_with_modules.constants.each do |sub_module|
|
|
20
|
+
self.const_get(sub_module).register_extension(module_with_modules.const_get(sub_module)) if self.const_defined?(sub_module)
|
|
17
21
|
end
|
|
18
22
|
end
|
|
19
|
-
|
|
23
|
+
|
|
24
|
+
# Extend a module or class with this method to make it a receiver for RTM extensions.
|
|
25
|
+
# E.g. MyModule.extend(Extendable) or MyClass.extend(Extendable).
|
|
26
|
+
#
|
|
27
|
+
# A extension can then be registered using
|
|
28
|
+
# MyModule.register_extension(MyExtension)
|
|
29
|
+
#
|
|
30
|
+
# The module will then keep track of all modules or classes it's included in.
|
|
31
|
+
# These modules and classes are called implementations here.
|
|
32
|
+
# If an extension is added later, the implementations will also be updated which would not be the case if normal includes were used.
|
|
33
|
+
module Extendable
|
|
34
|
+
# Register a module as an extension to an Entity in RTM.
|
|
35
|
+
# An entity may be e.g. RTM::TopicMap, RTM::Topic or any Module which was extended with RTM::Extendable
|
|
36
|
+
#
|
|
37
|
+
# Besides normal ruby inclusion of the module, this module keeps track of its implementations which are also updated in this method.
|
|
38
|
+
def register_extension(mod)
|
|
39
|
+
include mod
|
|
40
|
+
return unless @implementations
|
|
41
|
+
@implementations.each do |impl|
|
|
42
|
+
next if impl.ancestors.include?(mod)
|
|
43
|
+
impl.send(:include, mod)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# A standard Ruby hook to be notified about inclusions of this module.
|
|
48
|
+
# This normally eliminates the need to register a module as implementa
|
|
49
|
+
def included(klass)
|
|
50
|
+
# super
|
|
51
|
+
# puts "[RTMEXT] including #{self} into #{klass} in #{caller(1).first}"
|
|
52
|
+
register_implementation(klass)
|
|
53
|
+
klass.class_eval do
|
|
54
|
+
def self.included(klass2)
|
|
55
|
+
# puts "[RTMIMPLEXT] #{self} was included into #{klass2} in #{caller(1).first}"
|
|
56
|
+
# self.ancestors.select {|anc| anc.respond_to?(:register_implementation)}.each{|anc| anc.register_implementation(klass2) }
|
|
57
|
+
self.ancestors.find {|anc| anc.respond_to?(:register_implementation)}.register_implementation(klass2)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Register an implementation to this module.
|
|
63
|
+
# Registred implementations will be updated if later any extensions are added.
|
|
64
|
+
# This method should normally be called from the included hook.
|
|
65
|
+
# Due to Ruby's restrictions on calling protected methods from other modules extending the very same module Extendable,
|
|
66
|
+
# this method must be public.
|
|
67
|
+
def register_implementation(klass)
|
|
68
|
+
# super if self.class.superclass.respond_to?(:register_implementation)
|
|
69
|
+
@implementations ||= []
|
|
70
|
+
@implementations << klass
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
[
|
|
74
|
+
TopicMapSystem, Construct, Reifiable,
|
|
75
|
+
DatatypeAware, Scoped, Typed,
|
|
76
|
+
TopicMap, Topic, Name, Occurrence, Variant, Association, Role,
|
|
77
|
+
Locator, ItemIdentifier, SubjectIdentifier, SubjectLocator
|
|
78
|
+
].each{|mod| mod.extend(Extendable)}
|
|
79
|
+
end
|