rtm-javatmapi 0.2.0
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 +13 -0
- data/LICENSE +201 -0
- data/README +4 -0
- data/lib/rtm/javatmapi.rb +189 -0
- data/lib/rtm/javatmapi/aliases.rb +43 -0
- data/lib/rtm/javatmapi/base.rb +30 -0
- data/lib/rtm/javatmapi/core.rb +16 -0
- data/lib/rtm/javatmapi/core/association.rb +71 -0
- data/lib/rtm/javatmapi/core/construct.rb +68 -0
- data/lib/rtm/javatmapi/core/locator.rb +24 -0
- data/lib/rtm/javatmapi/core/name.rb +101 -0
- data/lib/rtm/javatmapi/core/occurrence.rb +56 -0
- data/lib/rtm/javatmapi/core/reifiable.rb +48 -0
- data/lib/rtm/javatmapi/core/role.rb +49 -0
- data/lib/rtm/javatmapi/core/scoped.rb +99 -0
- data/lib/rtm/javatmapi/core/topic.rb +454 -0
- data/lib/rtm/javatmapi/core/topic_map.rb +632 -0
- data/lib/rtm/javatmapi/core/topic_map_system.rb +6 -0
- data/lib/rtm/javatmapi/core/typed.rb +31 -0
- data/lib/rtm/javatmapi/core/variant.rb +19 -0
- data/lib/rtm/javatmapi/ext.rb +4 -0
- data/lib/rtm/javatmapi/ext/java_util_set.rb +10 -0
- data/lib/rtm/javatmapi/inclusion.rb +46 -0
- data/lib/rtm/javatmapi/java_implementations.rb +40 -0
- data/lib/rtm/javatmapi/javalibs/asm-2.2.3.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/asm-commons-2.2.3.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/ctm-writer-1.0.0a.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/jing.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/json_simple.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/log4j-1.2.14.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/ocutil-2.4.2.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/openrdf-sesame-2.2.1-onejar.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/poi-3.2-FINAL.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/poi-3.5-beta6-20090622.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/poi-contrib-3.5-beta6-20090622.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/poi-ooxml-3.5-beta6-20090622.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/poi-scratchpad-3.2-FINAL.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/poi-scratchpad-3.5-beta6-20090622.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/semagia-mio-0.9.5.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/semagia-mio-ctm-0.9.3-working-draft-2009-02-18.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/semagia-mio-jtm-0.9.4.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/semagia-mio-ltm-0.9.5.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/semagia-mio-snello-0.9.3.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/semagia-mio-tmxml-0.9.5.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/semagia-mio-xtm-0.9.5.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/slf4j-api-1.5.8.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/slf4j-log4j12-1.5.8.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/tinytim-mio-2.0.0a5.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/tmapi-2.0a2.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/tmapix-io-0.3.0-snapshot-200910281502.jar +0 -0
- data/lib/rtm/javatmapi/javalibs/trove-2.0.4.jar +0 -0
- data/lib/rtm/javatmapi/superiseable.rb +74 -0
- metadata +118 -0
@@ -0,0 +1,632 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
module Java::OrgTmapiCore::TopicMap
|
5
|
+
|
6
|
+
URI_PATTERN = ":"
|
7
|
+
|
8
|
+
extend Superiseable
|
9
|
+
#include RTM::TopicMap
|
10
|
+
|
11
|
+
attr_accessor :prefixes #hash
|
12
|
+
|
13
|
+
attr_accessor :base_iri
|
14
|
+
|
15
|
+
alias :base_locator :base_iri
|
16
|
+
|
17
|
+
# Adds the identifier (key) and reference (value) to the prefixes-Hash and
|
18
|
+
# returns all prefixes. Qnames consisting of "identifier:localpart"
|
19
|
+
# will be converted to "referencelocalpart".
|
20
|
+
#
|
21
|
+
# The identifier and reference must be Strings.
|
22
|
+
#
|
23
|
+
# Example:
|
24
|
+
# add_prefix("tml","http://www.topicmapslab.de/")
|
25
|
+
#
|
26
|
+
# :call-seq:
|
27
|
+
# add_prefix(identifier,reference) -> Hash
|
28
|
+
#
|
29
|
+
def add_prefix(identifier,reference)
|
30
|
+
unless identifier.is_a?(String) && reference.is_a?(String)
|
31
|
+
raise("add_prefix: identifier and reference must be Strings")
|
32
|
+
end
|
33
|
+
#if (identifier == "sl") || (identifier == "si") || (identifier == "ii")
|
34
|
+
# warn("prefixes: identifier is either sl, si or ii")
|
35
|
+
#end
|
36
|
+
prefixes[identifier]= reference
|
37
|
+
prefixes
|
38
|
+
end
|
39
|
+
|
40
|
+
# Deletes a prefix (given the identifier) from the prefixes-Hash and
|
41
|
+
# returnes the remaining prefixes.
|
42
|
+
#
|
43
|
+
# If reference is given, it must match the value of the identifier (key)
|
44
|
+
# in the prefixes-Hash -
|
45
|
+
# if not, the prefix is not deleted.
|
46
|
+
#
|
47
|
+
# The result may be empty.
|
48
|
+
#
|
49
|
+
# :call-seq:
|
50
|
+
# delete_prefix(identifier) -> Hash
|
51
|
+
# delete_prefix(identifier,reference) -> Hash
|
52
|
+
#
|
53
|
+
def delete_prefix(identifier,reference = :any)
|
54
|
+
#warn("delete_prefix: identifier not found") unless prefixes.has_key?(identifier)
|
55
|
+
#warn("delete_prefix: reference does not match") unless reference == :any || reference == prefixes[identifier]
|
56
|
+
if reference == :any
|
57
|
+
prefixes.delete(identifier)
|
58
|
+
else
|
59
|
+
prefixes.delete_if{|k,v| k == identifier && v == reference}
|
60
|
+
end
|
61
|
+
prefixes
|
62
|
+
end
|
63
|
+
alias :del_prefix :delete_prefix
|
64
|
+
|
65
|
+
# Returns the prefixes that match the given the
|
66
|
+
# identifier and/or reference.
|
67
|
+
#
|
68
|
+
# :call-seq:
|
69
|
+
# find_prefix -> Hash
|
70
|
+
# find_prefix({:identifier => String}) -> Hash
|
71
|
+
# find_prefix({:reference => String}) -> Hash
|
72
|
+
# find_prefix({:identifier => String, :reference => String}) -> Hash
|
73
|
+
#
|
74
|
+
def find_prefix(filter = {})
|
75
|
+
#TODO Specs
|
76
|
+
identifier = filter[:identifier]
|
77
|
+
reference = filter[:reference]
|
78
|
+
if identifier && reference
|
79
|
+
return prefixes.select{|k,v| k == identifier && v == reference}
|
80
|
+
end
|
81
|
+
if identifier
|
82
|
+
return prefixes.select{|k,v| k == identifier}
|
83
|
+
elsif reference
|
84
|
+
return prefixes.select{|k,v| v == reference}
|
85
|
+
else
|
86
|
+
prefixes
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
def show_prefixes
|
92
|
+
#TODO to be implemented?
|
93
|
+
prefixes
|
94
|
+
end
|
95
|
+
public
|
96
|
+
|
97
|
+
superised
|
98
|
+
# Returns nil.
|
99
|
+
#
|
100
|
+
# :call-seq:
|
101
|
+
# parent -> nil
|
102
|
+
#
|
103
|
+
def parent
|
104
|
+
getParent
|
105
|
+
end
|
106
|
+
alias :reverse_children :parent
|
107
|
+
|
108
|
+
# Returns all Associations and Topics contained in this TopicMap.
|
109
|
+
#
|
110
|
+
# :call-seq:
|
111
|
+
# children -> Array of Associations and/or Topics
|
112
|
+
#
|
113
|
+
def children
|
114
|
+
getAssociations.to_a + getTopics.to_a
|
115
|
+
end
|
116
|
+
alias :reverse_parent :children
|
117
|
+
|
118
|
+
superised
|
119
|
+
# Creates an Association in this TopicMap.
|
120
|
+
#
|
121
|
+
# Type specifies the Association type.
|
122
|
+
#
|
123
|
+
# If given, scope specifies the association scope;
|
124
|
+
# else the Association is in the unconstrained scope.
|
125
|
+
# Scope must be an Array of identifiers.
|
126
|
+
#
|
127
|
+
# The last argument - a roles-Hash - is optional. If given,
|
128
|
+
# all specified roles will be created additionally. A role is
|
129
|
+
# specified by the role type: the key in the Hash and
|
130
|
+
# the role player: the corresponding value in the Hash.
|
131
|
+
#
|
132
|
+
# Each identifier (type, scope-identifier, roletype-identifier and
|
133
|
+
# player-identifier) may be a Topic or Topic-Reference.
|
134
|
+
#
|
135
|
+
# :call-seq:
|
136
|
+
# create_association(type) -> Association
|
137
|
+
# create_association(type, scope-Array) -> Association
|
138
|
+
# create_association(type, roletype-identifier => player-identifier, ...) -> Association
|
139
|
+
# create_association(type, scope-Array, roletype-identifier => player-identifier, ...) -> Association
|
140
|
+
#
|
141
|
+
def create_association(type, *args)
|
142
|
+
roles = {}
|
143
|
+
if args.size == 0
|
144
|
+
# no args -> no scope and no roles given
|
145
|
+
scope = :ucs
|
146
|
+
elsif args.size == 1
|
147
|
+
# args may be an array (scope) or hash (roles)
|
148
|
+
argument = args[0]
|
149
|
+
if argument.is_a?(Array)
|
150
|
+
scope = argument
|
151
|
+
elsif argument.is_a?(Hash)
|
152
|
+
scope = :ucs
|
153
|
+
roles = argument
|
154
|
+
else
|
155
|
+
raise("create_association: arguments after type may be an Array or Hash")
|
156
|
+
end
|
157
|
+
else
|
158
|
+
# several arguments after type
|
159
|
+
argument1 = args[0]
|
160
|
+
argument2 = args[1]
|
161
|
+
if argument1.is_a?(Array)
|
162
|
+
scope = argument1
|
163
|
+
roles = argument2
|
164
|
+
elsif argument1.is_a?(Hash)
|
165
|
+
scope = :ucs
|
166
|
+
roles = argument1
|
167
|
+
else
|
168
|
+
raise("create_association: arguments after type may be an Array or Hash")
|
169
|
+
end
|
170
|
+
end
|
171
|
+
raise("create_association: type must be a Topic or Topic-Reference") unless type.is_a?(Java::OrgTmapiCore::Topic) || type.is_a?(String) || type.is_a?(Java::OrgTmapiCore::Locator)
|
172
|
+
if scope == :ucs
|
173
|
+
assoc = createAssociation(get!(type),[].to_java(org.tmapi.core.Topic))
|
174
|
+
else
|
175
|
+
raise("create_association: scope must be an Array") unless scope.is_a?(Array)
|
176
|
+
assoc = scope.empty? ? createAssociation(get!(type),[].to_java(org.tmapi.core.Topic)) : createAssociation(get!(type),get!(scope))
|
177
|
+
end
|
178
|
+
raise("create_association: roles must be a Hash") unless roles.is_a?(Hash)
|
179
|
+
roles.each do |k,v|
|
180
|
+
if v.is_a?(Array)
|
181
|
+
v.each{|player| assoc.create_role(k,player)}
|
182
|
+
else
|
183
|
+
assoc.create_role(k,v)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
yield assoc if block_given?
|
187
|
+
return assoc
|
188
|
+
end
|
189
|
+
|
190
|
+
# Calls TMAPI TopicMap.getIndex which
|
191
|
+
# returns the index for the TypeInstanceIndex.
|
192
|
+
#
|
193
|
+
# :call-seq:
|
194
|
+
# type_instance_index -> TypeInstanceIndex
|
195
|
+
#
|
196
|
+
def type_instance_index
|
197
|
+
# Equals _index(:TypeInstanceIndex), which doesn't work yet
|
198
|
+
getIndex(org.tmapi.index.TypeInstanceIndex.java_class)
|
199
|
+
end
|
200
|
+
|
201
|
+
# Calls TMAPI TopicMap.getIndex which
|
202
|
+
# returns the index for the LiteralIndex.
|
203
|
+
#
|
204
|
+
# :call-seq:
|
205
|
+
# literal_index -> LiteralIndex
|
206
|
+
#
|
207
|
+
def literal_index
|
208
|
+
# Equals _index(:LiteralIndex), which doesn't work yet
|
209
|
+
getIndex(org.tmapi.index.LiteralIndex.java_class)
|
210
|
+
end
|
211
|
+
|
212
|
+
# Calls TMAPI TopicMap.getIndex which
|
213
|
+
# returns the index for the ScopedIndex.
|
214
|
+
#
|
215
|
+
# :call-seq:
|
216
|
+
# scoped_index -> ScopedIndex
|
217
|
+
#
|
218
|
+
def scoped_index
|
219
|
+
# Equals _index(:ScopedIndex), which doesn't work yet
|
220
|
+
getIndex(org.tmapi.index.ScopedIndex.java_class)
|
221
|
+
end
|
222
|
+
|
223
|
+
# Returns all topics in the topic map that are used as instance
|
224
|
+
# in an "type-instance"-relationship.
|
225
|
+
#
|
226
|
+
# The optional argument specifies the type the instances should have.
|
227
|
+
# Type may be a topic reference. This method equals topics(type).
|
228
|
+
#
|
229
|
+
# The result may be empty.
|
230
|
+
#
|
231
|
+
# :call-seq:
|
232
|
+
# instances -> Array of Topics
|
233
|
+
# instances(type) -> Array of Topics
|
234
|
+
#
|
235
|
+
def instances(type = :any)
|
236
|
+
return types.map{|t| t.instances.to_a}.flatten.uniq if type == :any
|
237
|
+
type = topic_map.get(type) unless type.is_a?(RTM::Topic)
|
238
|
+
return type ? type_instance_index.getTopics(type).to_a : Array.new
|
239
|
+
end
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
# Returns all topics in the topic map that are used as type
|
244
|
+
# in an "type-instance"-relationship.
|
245
|
+
#
|
246
|
+
# :call-seq:
|
247
|
+
# types -> Set of Topics
|
248
|
+
#
|
249
|
+
def types
|
250
|
+
type_instance_index.getTopicTypes
|
251
|
+
end
|
252
|
+
|
253
|
+
# Returns all topics in this topic map that are used
|
254
|
+
# as types of associations.
|
255
|
+
#
|
256
|
+
# :call-seq:
|
257
|
+
# association_types -> Set of Topics
|
258
|
+
#
|
259
|
+
def association_types
|
260
|
+
type_instance_index.getAssociationTypes
|
261
|
+
end
|
262
|
+
|
263
|
+
# Returns the all Topics in this TopicMap that are used
|
264
|
+
# as types of Roles.
|
265
|
+
#
|
266
|
+
# :call-seq:
|
267
|
+
# role_types -> Set of Topics
|
268
|
+
#
|
269
|
+
def role_types
|
270
|
+
type_instance_index.getRoleTypes
|
271
|
+
end
|
272
|
+
|
273
|
+
# Returns all Topics in this TopicMap that are used
|
274
|
+
# as types of Names.
|
275
|
+
#
|
276
|
+
# :call-seq:
|
277
|
+
# name_types -> Set of Topics
|
278
|
+
#
|
279
|
+
def name_types
|
280
|
+
type_instance_index.getNameTypes
|
281
|
+
end
|
282
|
+
|
283
|
+
# Returns all Topics in this TopicMap that are used
|
284
|
+
# as types of Occurrences.
|
285
|
+
#
|
286
|
+
# :call-seq:
|
287
|
+
# occurrence_types -> Set of Topics
|
288
|
+
#
|
289
|
+
def occurrence_types
|
290
|
+
type_instance_index.getOccurrenceTypes
|
291
|
+
end
|
292
|
+
|
293
|
+
superised
|
294
|
+
# Returns all topics contained in this topic map.
|
295
|
+
#
|
296
|
+
# The optional argument specifies the type of the topics should have,
|
297
|
+
# i.e. all instances of the specified type are returned. Type may be a
|
298
|
+
# topic reference. This method equals instances (type).
|
299
|
+
#
|
300
|
+
# The return value may be empty.
|
301
|
+
#
|
302
|
+
# :call_spec:
|
303
|
+
# topics -> Set of Topics
|
304
|
+
# topics(type) -> Array of Topics
|
305
|
+
#
|
306
|
+
def topics(type = :any)
|
307
|
+
return getTopics if type == :any
|
308
|
+
return instances(type)
|
309
|
+
end
|
310
|
+
|
311
|
+
superised
|
312
|
+
# Returns a Locator representing the identifier.
|
313
|
+
# Identifier may be a String (IRI).
|
314
|
+
#
|
315
|
+
# :call-seq:
|
316
|
+
# create_locator(identifier) -> Locator
|
317
|
+
#
|
318
|
+
def create_locator(identifier)
|
319
|
+
return identifier if identifier.is_a?(Java::OrgTmapiCore::Locator)
|
320
|
+
identifier = check_for_qname(identifier) unless prefixes.empty?
|
321
|
+
identifier = proper_base_iri + identifier if identifier.is_a?(String) && !identifier.include?(URI_PATTERN)
|
322
|
+
createLocator(identifier)
|
323
|
+
end
|
324
|
+
|
325
|
+
superised
|
326
|
+
# Assumes identifier is an item identifier (Locator or String)
|
327
|
+
# or an Array of item identifiers (Locators and/or Strings)
|
328
|
+
# and returns a Construct or an Array of Constructs
|
329
|
+
# by its/their item identifier/s.
|
330
|
+
#
|
331
|
+
# :call-seq:
|
332
|
+
# get_construct_by_item_identifier(identifier) -> Construct
|
333
|
+
# get_construct_by_item_identifier(identifier-Array) -> Array of Constructs
|
334
|
+
#
|
335
|
+
def get_construct_by_item_identifier(identifier)
|
336
|
+
identifier = create_locator(identifier) if identifier.is_a?(String)
|
337
|
+
return getConstructByItemIdentifier(identifier) if identifier.is_a?(Java::OrgTmapiCore::Locator)
|
338
|
+
return identifier.map{|i| get_topic_by_subject_locator(i)} if identifier.is_a?(Array)
|
339
|
+
return nil
|
340
|
+
end
|
341
|
+
|
342
|
+
superised
|
343
|
+
# Assumes identifier is a subject identifier (Locator or String)
|
344
|
+
# or an Array of subject identifiers (Locators and/or Strings)
|
345
|
+
# and returns a Topic or an Array of Topics
|
346
|
+
# by its/their subject identifier/s.
|
347
|
+
#
|
348
|
+
# :call-seq:
|
349
|
+
# get_topic_by_subject_identifier(identifier) -> Topic
|
350
|
+
# get_topic_by_subject_identifier(identifier-Array) -> Array of Topics
|
351
|
+
#
|
352
|
+
def get_topic_by_subject_identifier(identifier)
|
353
|
+
identifier = create_locator(identifier) if identifier.is_a?(String)
|
354
|
+
return getTopicBySubjectIdentifier(identifier) if identifier.is_a?(Java::OrgTmapiCore::Locator)
|
355
|
+
return identifier.map{|i| get_topic_by_subject_locator(i)} if identifier.is_a?(Array)
|
356
|
+
return nil
|
357
|
+
end
|
358
|
+
|
359
|
+
superised
|
360
|
+
# Assumes identifier is a subject locator (Locator or String)
|
361
|
+
# or an Array of subject locators (Locators and/or Strings)
|
362
|
+
# and returns a Topic or an Array of Topics
|
363
|
+
# by its/their subject locator/s.
|
364
|
+
#
|
365
|
+
# :call-seq:
|
366
|
+
# get_topic_by_subject_locator(identifier) -> Topic
|
367
|
+
# get_topic_by_subject_locator(identifier-Array) -> Array of Topics
|
368
|
+
#
|
369
|
+
def get_topic_by_subject_locator(identifier)
|
370
|
+
identifier = create_locator(identifier) if identifier.is_a?(String)
|
371
|
+
return getTopicBySubjectLocator(identifier) if identifier.is_a?(Java::OrgTmapiCore::Locator)
|
372
|
+
return identifier.map{|i| get_topic_by_subject_locator(i)} if identifier.is_a?(Array)
|
373
|
+
return nil
|
374
|
+
end
|
375
|
+
|
376
|
+
superised
|
377
|
+
# Assumes identifier is a subject identifier (Locator or String)
|
378
|
+
# or an Array of subject identifiers (Locators and/or Strings).
|
379
|
+
# Either returns an existing Topic (or Array of Topics) or creates a/
|
380
|
+
# new Topic instance/s with the specified subject identifier/s.
|
381
|
+
#
|
382
|
+
# :call-seq:
|
383
|
+
# create_topic_by_subject_identifier(identifier) -> Topic
|
384
|
+
# create_topic_by_subject_identifier(identifier-Array) -> Array of Topics
|
385
|
+
#
|
386
|
+
# If a topic with the specified subject identifier exists in the topic map,
|
387
|
+
# that topic is returned. If a topic with an item identifier equals to the
|
388
|
+
# specified subject identifier exists, the specified subject identifier is
|
389
|
+
# added to that topic and the topic is returned. If neither a topic with
|
390
|
+
# the specified subject identifier nor with an item identifier equals to
|
391
|
+
# the subject identifier exists, a topic with the subject identifier is
|
392
|
+
# created.
|
393
|
+
def create_topic_by_subject_identifier(identifier)
|
394
|
+
get_stuff(identifier){|x| createTopicBySubjectIdentifier(x)}
|
395
|
+
end
|
396
|
+
|
397
|
+
superised
|
398
|
+
# Assumes identifier is a subject locator (Locator or String)
|
399
|
+
# or an Array of subject locators (Locators and/or Strings).
|
400
|
+
# Either returns an existing Topic (or Array of Topics) or creates a/
|
401
|
+
# new Topic instance/s with the specified subject locators/s.
|
402
|
+
#
|
403
|
+
# :call-seq:
|
404
|
+
# create_topic_by_subject_locator(identifier) -> Topic
|
405
|
+
# create_topic_by_subject_locator(identifier-Array) -> Array of Topics
|
406
|
+
#
|
407
|
+
def create_topic_by_subject_locator(identifier)
|
408
|
+
get_stuff(identifier){|x| createTopicBySubjectLocator(x)}
|
409
|
+
end
|
410
|
+
|
411
|
+
superised
|
412
|
+
# Assumes identifier is a item identifier (Locator or String)
|
413
|
+
# or an Array of item identifiers (Locators and/or Strings).
|
414
|
+
# Either returns an existing Topic (or Array of Topics) or creates a/
|
415
|
+
# new Topic instance/s with the specified item identifier/s.
|
416
|
+
#
|
417
|
+
# :call-seq:
|
418
|
+
# create_topic_by_item_identifier(identifier) -> Topic
|
419
|
+
# create_topic_by_item_identifier(identifier-Array) -> Array of Topics
|
420
|
+
#
|
421
|
+
# If a topic with the specified item identifier exists in the topic map,
|
422
|
+
# that topic is returned. If a topic with a subject identifier equals to
|
423
|
+
# the specified item identifier exists, the specified item identifier is
|
424
|
+
# added to that topic and the topic is returned. If neither a topic with
|
425
|
+
# the specified item identifier nor with a subject identifier equals to
|
426
|
+
# the subject identifier exists, a topic with the item identifier is created.
|
427
|
+
def create_topic_by_item_identifier(identifier)
|
428
|
+
get_stuff(identifier){|x| createTopicByItemIdentifier(x)}
|
429
|
+
end
|
430
|
+
|
431
|
+
# Assumes identifier is an IRI (Locator or String) or an Array of IRIs.
|
432
|
+
# Returns an existing or created Topic or an Array of Topics according
|
433
|
+
# to the nature of the IRI.
|
434
|
+
#
|
435
|
+
# :call-seq:
|
436
|
+
# create_topic_by(identifier) -> Topic
|
437
|
+
# create_topic_by(identifier-Array) -> Array of Topics
|
438
|
+
#
|
439
|
+
def create_topic_by(identifier)
|
440
|
+
case identifier
|
441
|
+
when Java::OrgTmapiCore::Locator
|
442
|
+
return create_topic_by_subject_identifier(identifier)
|
443
|
+
when String
|
444
|
+
reroute_for_create(identifier)
|
445
|
+
when Array
|
446
|
+
return identifier.map{|i| create_topic_by(i)}
|
447
|
+
else
|
448
|
+
return nil
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
452
|
+
# If identifier is a Topic, returns this Topic.
|
453
|
+
#
|
454
|
+
# If identifier is a Locator, returns the Topic specified by the Locator (as item
|
455
|
+
# identifier or subject identifier).
|
456
|
+
#
|
457
|
+
# If identifier is a String, returnes the Topic which has this
|
458
|
+
# String as subject identifier (by default or if the String starts with "si:")
|
459
|
+
# or as subject locator (if the String starts with a "=" or "sl:")
|
460
|
+
# or as item identifier (if the String starts with a "^" or "ii:").
|
461
|
+
#
|
462
|
+
# Returns an Array of Topics if an Array of identifiers is given according to the
|
463
|
+
# rules above.
|
464
|
+
#
|
465
|
+
# Given one identifier, if no Topic is found, returns nil.
|
466
|
+
#
|
467
|
+
# Given an Array of identifiers, if no Topics are found, returnes an empty Array.
|
468
|
+
#
|
469
|
+
# :call-seq:
|
470
|
+
# get(identifier) -> Topic or nil
|
471
|
+
# get(identifier-Array) -> Array of Topics or empty Array
|
472
|
+
#
|
473
|
+
def get(identifier)
|
474
|
+
case identifier
|
475
|
+
when nil
|
476
|
+
return nil
|
477
|
+
when Java::OrgTmapiCore::Topic
|
478
|
+
return identifier
|
479
|
+
when Java::OrgTmapiCore::Locator
|
480
|
+
return get_construct_by_item_identifier(identifier) if get_construct_by_item_identifier(identifier).is_a?(Java::OrgTmapiCore::Topic)
|
481
|
+
return get_topic_by_subject_identifier(identifier) if get_topic_by_subject_identifier(identifier)
|
482
|
+
#return get_topic_by_subject_locator(identifier) if get_topic_by_subject_locator(identifier) #not allowed because Topics with equals si and ii are merged but sl not
|
483
|
+
return nil
|
484
|
+
when String
|
485
|
+
reroute_for_get(identifier)
|
486
|
+
when Array
|
487
|
+
# in: multi array -> out: multi array
|
488
|
+
return identifier.map{|i| get(i)}
|
489
|
+
#when Hash
|
490
|
+
#TODO: use case for getting Topics if argument is a hash
|
491
|
+
else
|
492
|
+
raise("get(#{identifier.inspect}): arguments do not match")
|
493
|
+
end
|
494
|
+
end
|
495
|
+
|
496
|
+
# Calls get(identifier) and returns the Topic or Array of Topics according
|
497
|
+
# to the nature of the identifier (Topic/Topic-References or
|
498
|
+
# Array of those types).
|
499
|
+
#
|
500
|
+
# Calls create_topic_by(identifier) if a Topic specified by identifier does
|
501
|
+
# not exist in the TopicMap. Returns the created and/our found Topic/s.
|
502
|
+
#
|
503
|
+
# If identifier is a String, returnes/creates the Topic which has this
|
504
|
+
# String as subject identifier (by default or if the String starts with "si:")
|
505
|
+
# or as subject locator (if the String starts with a "=" or "sl:")
|
506
|
+
# or as item identifier (if the String starts with a "^" or "ii:").
|
507
|
+
#
|
508
|
+
# :call-seq:
|
509
|
+
# get!(identifier) -> Topic
|
510
|
+
# get!(identifier-Array) -> Array of Topics
|
511
|
+
#
|
512
|
+
def get!(identifier)
|
513
|
+
return nil unless identifier
|
514
|
+
if identifier.is_a?(Array)
|
515
|
+
return identifier.map{|i| get!(i)}
|
516
|
+
end
|
517
|
+
found = get(identifier)
|
518
|
+
return found ? found : create_topic_by(identifier)
|
519
|
+
end
|
520
|
+
|
521
|
+
def construct_by_id(id)
|
522
|
+
getConstructById(id)
|
523
|
+
end
|
524
|
+
|
525
|
+
private
|
526
|
+
|
527
|
+
# If the identifier is a qname (= "prefix_identifier" + ":" + "localpart"),
|
528
|
+
# substitutes the prefix_identifier with the reference
|
529
|
+
# (=> "reference" + "localpart") if the prefix_identifier is
|
530
|
+
# found in the prefixes-Hash.
|
531
|
+
#
|
532
|
+
# Returnes the enhanced identifier if successfull.
|
533
|
+
# Returns the original identifier if no substitution
|
534
|
+
# occured.
|
535
|
+
#
|
536
|
+
# :call-seq:
|
537
|
+
# check_for_qname(identifier) -> String
|
538
|
+
#
|
539
|
+
def check_for_qname(identifier)
|
540
|
+
sections = identifier.split(":")
|
541
|
+
key = sections[0]
|
542
|
+
if (sections.size > 1) && (prefixes.has_key?(key))
|
543
|
+
identifier = identifier.sub(key + ":", prefixes[key])
|
544
|
+
# TODO check NOW if identifier is a valid URI ? or may the identifier still be relative?
|
545
|
+
end
|
546
|
+
return identifier
|
547
|
+
end
|
548
|
+
|
549
|
+
# Calls TMAPI TopicMap.getIndex which
|
550
|
+
# returns the specified index for the
|
551
|
+
# indexInterface i.
|
552
|
+
#
|
553
|
+
# :call-seq:
|
554
|
+
# _index(i) -> extended index
|
555
|
+
#
|
556
|
+
# doesn't work;
|
557
|
+
# JRuby doesn't seem to like "send" there;
|
558
|
+
# solution: use getIndex directly
|
559
|
+
def _index(i)
|
560
|
+
getIndex(org.tmapi.index.send(i).java_class)
|
561
|
+
end
|
562
|
+
|
563
|
+
# If identifier is not a String or Locator -> assumes it is an Array.
|
564
|
+
# If Array entries are not locators -> create_locator(entry).
|
565
|
+
# Calls yield on each Array entry and returns Array.
|
566
|
+
#
|
567
|
+
# If identifier is not a Locator -> assumes it is a String and
|
568
|
+
# calls create_locator(idenifier).
|
569
|
+
# Executes yield on locator and returns the result.
|
570
|
+
def get_stuff(identifier)
|
571
|
+
unless (identifier.is_a?(String)) || (identifier.is_a?(Java::OrgTmapiCore::Locator))
|
572
|
+
identifier_in_use = identifier.map{|x|(x.is_a? Java::OrgTmapiCore::Locator)? x : create_locator(x)}
|
573
|
+
return identifier_in_use.map{|y| yield y}
|
574
|
+
else
|
575
|
+
unless identifier.is_a? Java::OrgTmapiCore::Locator
|
576
|
+
identifier = create_locator(identifier)
|
577
|
+
end
|
578
|
+
return (yield identifier)
|
579
|
+
end
|
580
|
+
end
|
581
|
+
|
582
|
+
# Identifies the identifier as item identifier, subject locator or
|
583
|
+
# subject identifier and calls create_topic_by_.. accordingly. Creates
|
584
|
+
# new topic if topic does not exist yet. Returns the topic.
|
585
|
+
#
|
586
|
+
# :call-seq:
|
587
|
+
# reroute_for_create(identifier) -> Topic
|
588
|
+
#
|
589
|
+
def reroute_for_create(identifier)
|
590
|
+
case identifier
|
591
|
+
when /^(\^|ii:)\s*(.*)/ #identifiers starts with ^ or ii:
|
592
|
+
create_topic_by_item_identifier(create_locator($2))
|
593
|
+
when /^(=|sl:)\s*(.*)/ #identifier starts with = or sl:
|
594
|
+
create_topic_by_subject_locator(create_locator($2))
|
595
|
+
when /^(si:)\s*(.*)/ #identifier starts with si:
|
596
|
+
create_topic_by_subject_identifier(create_locator($2))
|
597
|
+
else #identifier does not start with a special character
|
598
|
+
create_topic_by_subject_identifier(create_locator(identifier.lstrip))#lstrip: leading whitespace chars removed
|
599
|
+
end
|
600
|
+
end
|
601
|
+
|
602
|
+
# Identifies the identifier as item identifier, subject locator or
|
603
|
+
# subject identifier and calls get_construct/topic_by_.. accordingly.
|
604
|
+
# Returns the topic.
|
605
|
+
#
|
606
|
+
# :call-seq:
|
607
|
+
# reroute_for_get(identifier) -> Topic
|
608
|
+
#
|
609
|
+
def reroute_for_get(identifier)
|
610
|
+
case identifier
|
611
|
+
when /^(si:|sl:|ii:|=|^)$/
|
612
|
+
return nil
|
613
|
+
when /^(\^|ii:)\s*(.*)/ #identifiers starts with ^ or ii:
|
614
|
+
get_construct_by_item_identifier(create_locator($2))
|
615
|
+
when /^(=|sl:)\s*(.+)/ #identifier starts with = or sl:
|
616
|
+
get_topic_by_subject_locator(create_locator($2))
|
617
|
+
when /^(si:)\s*(.+)/ #identifier starts with si:
|
618
|
+
get_topic_by_subject_identifier(create_locator($2))
|
619
|
+
else #identifier does not start with a special character
|
620
|
+
get_topic_by_subject_identifier(create_locator(identifier.lstrip)) #lstrip: leading whitespace chars removed
|
621
|
+
end
|
622
|
+
end
|
623
|
+
|
624
|
+
def proper_base_iri
|
625
|
+
if base_iri[-1] == '/'[-1]
|
626
|
+
return base_iri
|
627
|
+
else
|
628
|
+
return base_iri + '#'
|
629
|
+
end
|
630
|
+
end
|
631
|
+
|
632
|
+
end
|