rtm 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +38 -3
- data/lib/rtm.rb +25 -47
- data/lib/rtm/axes.rb +7 -4
- data/lib/rtm/axes/association.rb +1 -1
- data/lib/rtm/axes/associations.rb +1 -1
- data/lib/rtm/axes/characteristic.rb +1 -1
- data/lib/rtm/axes/characteristics.rb +1 -1
- data/lib/rtm/axes/topic.rb +3 -3
- data/lib/rtm/axes/topics.rb +3 -3
- data/lib/rtm/engine.rb +48 -5
- data/lib/rtm/extensions.rb +58 -8
- data/lib/rtm/io.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 +79 -41
- data/lib/rtm/io/to_jtm.rb +1 -1
- data/lib/rtm/io/to_rdf.rb +20 -5
- data/lib/rtm/io/to_string.rb +13 -2
- data/lib/rtm/io/to_yaml.rb +39 -11
- data/lib/rtm/navigation.rb +1 -15
- data/lib/rtm/navigation/association/players.rb +1 -1
- data/lib/rtm/navigation/name/characteristics.rb +1 -1
- data/lib/rtm/navigation/occurrence/characteristics.rb +1 -1
- data/lib/rtm/navigation/topic/characteristics.rb +1 -1
- data/lib/rtm/navigation/topic/players.rb +1 -1
- data/lib/rtm/navigation/topic/supertypes.rb +21 -17
- data/lib/rtm/navigation/topic/traverse.rb +1 -1
- data/lib/rtm/navigation/topic/types.rb +6 -4
- data/lib/rtm/psi.rb +6 -0
- data/lib/rtm/sugar.rb +42 -29
- data/lib/rtm/sugar/association/hash_access.rb +3 -3
- data/lib/rtm/sugar/occurrence/dynamic_value.rb +39 -56
- 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 +12 -6
- data/lib/rtm/sugar/topic/best_name.rb +74 -0
- data/lib/rtm/sugar/topic/characteristics.rb +10 -10
- data/lib/rtm/sugar/topic/counterparts.rb +131 -119
- data/lib/rtm/sugar/topic/scoped.rb +102 -53
- data/lib/rtm/sugar/topic/topic_ref.rb +63 -12
- data/lib/rtm/sugar/topic/typed.rb +50 -2
- 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 +1 -1
- data/lib/rtm/validation.rb +2 -2
- data/lib/rtm/version.rb +18 -6
- data/spec/rtm/axes/string_spec.rb +7 -7
- data/spec/rtm/axes/strings_spec.rb +10 -10
- 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/sugar/occurrence/dynamic_value_spec.rb +156 -1
- 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 +174 -172
- data/spec/rtm/sugar/topic/best_name_spec.rb +25 -0
- data/spec/rtm/sugar/topic/characteristics_spec.rb +20 -5
- data/spec/rtm/sugar/topic/counterparts_spec.rb +41 -1
- data/spec/rtm/sugar/topic/hash_access_spec.rb +1 -1
- data/spec/rtm/sugar/topic/scoped_spec.rb +178 -114
- data/spec/rtm/sugar/topic/topic_ref_spec.rb +10 -10
- data/spec/rtm/sugar/topic/typed_spec.rb +196 -134
- data/spec/rtm/sugar/topic_map/themes_spec.rb +67 -0
- data/spec/rtm/sugar/typed/types_spec.rb +1 -1
- data/spec/rtm/tmapi/core/association_spec.rb +2 -2
- data/spec/rtm/tmapi/core/datatype_aware_spec.rb +236 -0
- data/spec/rtm/tmapi/core/name_spec.rb +186 -1
- data/spec/rtm/tmapi/core/occurrence_spec.rb +24 -67
- data/spec/rtm/tmapi/core/reifiable_spec.rb +2 -2
- data/spec/rtm/tmapi/core/scoped_spec.rb +40 -2
- data/spec/rtm/tmapi/core/topic_map_spec.rb +98 -30
- data/spec/rtm/tmapi/core/topic_spec.rb +558 -82
- data/spec/rtm/tmapi/core/variant_spec.rb +3 -3
- data/spec/rtm_spec.rb +0 -1
- data/spec/spec_helper.rb +7 -2
- 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 +66 -11
- data/lib/rtm/io/ontopia_io.rb +0 -25
- data/lib/rtm/io/tmapix.rb +0 -234
- data/lib/rtm/sugar/occurrence/externalize.rb +0 -31
- data/spec/rtm/io/tmapix_spec.rb +0 -85
- data/test/base_unit_test.rb +0 -161
- data/test/base_unit_test_tmapi.rb +0 -165
@@ -1,65 +1,114 @@
|
|
1
1
|
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
2
|
# License: Apache License, Version 2.0
|
3
3
|
|
4
|
-
module Sugar
|
5
|
-
module
|
6
|
-
module Scoped
|
4
|
+
module RTM::Sugar::Topic
|
5
|
+
module Scoped
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
7
|
+
# Returns the Associations, Names, Occurrences and Variants
|
8
|
+
# whose scope contains this Topic. Beware: The scope of a Variant includes
|
9
|
+
# the themes of the Name this Variant belongs to.
|
10
|
+
#
|
11
|
+
# :call-seq:
|
12
|
+
# scoped -> Array of Associations, Names, Occurrences and Variants
|
13
|
+
#
|
14
|
+
def scoped
|
15
|
+
_index = scoped_index
|
16
|
+
_index.get_associations(self).to_a + _index.get_names(self).to_a + _index.get_occurrences(self).to_a + _index.get_variants(self).to_a
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns the Associations whose scope contains this Topic.
|
20
|
+
#
|
21
|
+
# The result may be empty.
|
22
|
+
#
|
23
|
+
# :call-seq:
|
24
|
+
# scoped_associations -> Array of Associations
|
25
|
+
#
|
26
|
+
def scoped_associations
|
27
|
+
scoped_index.get_associations(self).to_a
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns the Names whose scope contains this Topic.
|
31
|
+
#
|
32
|
+
# The result may be empty.
|
33
|
+
#
|
34
|
+
# :call-seq:
|
35
|
+
# scoped_names -> Array of Names
|
36
|
+
#
|
37
|
+
def scoped_names
|
38
|
+
scoped_index.get_names(self).to_a
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns the Occurrences whose scope contains this Topic.
|
42
|
+
#
|
43
|
+
# :call-seq:
|
44
|
+
# scoped_occurrences -> Array of Occurrences
|
45
|
+
#
|
46
|
+
def scoped_occurrences
|
47
|
+
scoped_index.get_occurrences(self).to_a
|
48
|
+
end
|
19
49
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
50
|
+
# Returns the Variants whose scope (including the scope of the parent Name)
|
51
|
+
# contains this Topic.
|
52
|
+
#
|
53
|
+
# The result may be empty.
|
54
|
+
#
|
55
|
+
# :call-seq:
|
56
|
+
# scoped_variants -> Array of Variants
|
57
|
+
#
|
58
|
+
def scoped_variants
|
59
|
+
scoped_index.get_variants(self).to_a
|
60
|
+
end
|
30
61
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
topic_map.scoped_index.get_names(self).to_a
|
40
|
-
end
|
62
|
+
# States if this topic occurs as theme in the scope of a scoped Construct.
|
63
|
+
#
|
64
|
+
# :call-seq:
|
65
|
+
# used_as_theme? -> true or false
|
66
|
+
#
|
67
|
+
def used_as_theme?
|
68
|
+
used_as_name_theme? || used_as_occurrence_theme? || used_as_association_theme? || used_as_variant_theme?
|
69
|
+
end
|
41
70
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
71
|
+
# States if this topic occurs as theme in the scope of an Association.
|
72
|
+
#
|
73
|
+
# :call-seq:
|
74
|
+
# used_as_association_theme? -> true or false
|
75
|
+
#
|
76
|
+
def used_as_association_theme?
|
77
|
+
not self.scoped_associations.empty?
|
78
|
+
end
|
79
|
+
|
80
|
+
# States if this topic occurs as theme in the scope of a Name.
|
81
|
+
#
|
82
|
+
# :call-seq:
|
83
|
+
# used_as_name_theme? -> true or false
|
84
|
+
#
|
85
|
+
def used_as_name_theme?
|
86
|
+
not self.scoped_names.empty?
|
87
|
+
end
|
88
|
+
|
89
|
+
# States if this topic occurs as theme in the scope of an Occurrence.
|
90
|
+
#
|
91
|
+
# :call-seq:
|
92
|
+
# used_as_occurrence_theme? -> true or false
|
93
|
+
#
|
94
|
+
def used_as_occurrence_theme?
|
95
|
+
not self.scoped_occurrences.empty?
|
96
|
+
end
|
50
97
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
def scoped_variants
|
60
|
-
topic_map.scoped_index.get_variants(self).to_a
|
61
|
-
end
|
98
|
+
# States if this topic occurs as theme in the scope of a Variant.
|
99
|
+
#
|
100
|
+
# :call-seq:
|
101
|
+
# used_as_variant_theme? -> true or false
|
102
|
+
#
|
103
|
+
def used_as_variant_theme?
|
104
|
+
not self.scoped_variants.empty?
|
105
|
+
end
|
62
106
|
|
107
|
+
private
|
108
|
+
def scoped_index
|
109
|
+
@scoped_index ||= topic_map.scoped_index
|
63
110
|
end
|
111
|
+
|
64
112
|
end
|
65
113
|
end
|
114
|
+
|
@@ -1,32 +1,83 @@
|
|
1
1
|
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
2
|
# License: Apache License, Version 2.0
|
3
3
|
|
4
|
-
module Sugar
|
4
|
+
module RTM::Sugar
|
5
5
|
module Topic
|
6
6
|
module TopicRef
|
7
7
|
|
8
8
|
# Returns an Array including all identifiers of this Topic.
|
9
|
-
#
|
10
|
-
#
|
9
|
+
#
|
10
|
+
# This method takes a Hash as argument.
|
11
|
+
#
|
12
|
+
# The key :ouputstyle defines if the ctm style (value :ctm, this is
|
13
|
+
# the default), the YAML
|
14
|
+
# style (value :yaml) or no style (value :blank) is supported.
|
15
|
+
#
|
16
|
+
# In ctm style an item identifier starts with a "^",
|
17
|
+
# a subject locator starts with a "=" and
|
18
|
+
# a subject identifiers contains no prefix.
|
19
|
+
#
|
20
|
+
# In yaml style an item identifiers start with a "ii:",
|
21
|
+
# a subject locator starts with a "sl:" and
|
22
|
+
# a subject identifier start with a "si:".
|
11
23
|
#
|
12
24
|
# :call-seq:
|
13
|
-
#
|
25
|
+
# references -> Array of Strings
|
26
|
+
# references(params = {}) -> Array of Strings
|
14
27
|
#
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
28
|
+
def references(params = {})
|
29
|
+
default_hash = {:outputstyle => :ctm, :resolve_qnames => :false}
|
30
|
+
params = default_hash.merge(params) if params.is_a? Hash
|
31
|
+
|
32
|
+
case params[:outputstyle]
|
33
|
+
when :yaml
|
34
|
+
identifiers = subject_identifiers.map{|si| "si:#{si.reference}"} +
|
35
|
+
subject_locators.map{ |sl| "sl:#{sl.reference}"} +
|
36
|
+
item_identifiers.map{ |ii| "ii:#{ii.reference}"}
|
37
|
+
when :blank
|
38
|
+
identifiers = subject_identifiers.map{|si| si.reference} +
|
39
|
+
subject_locators.map{ |sl| sl.reference} +
|
40
|
+
item_identifiers.map{ |ii| ii.reference}
|
41
|
+
else #:ctm default
|
42
|
+
identifiers = subject_identifiers.map{|si| si.reference} +
|
43
|
+
subject_locators.map{ |sl| "=#{sl.reference}"} +
|
44
|
+
item_identifiers.map{ |ii| "^#{ii.reference}"}
|
45
|
+
end
|
46
|
+
return identifiers
|
20
47
|
end
|
21
48
|
|
49
|
+
# Returns one identifier of this topic. If several exist, the shortest one
|
50
|
+
# is returned.
|
51
|
+
#
|
52
|
+
# This method takes a Hash as argument.
|
53
|
+
#
|
54
|
+
# The key :ouputstyle defines if the ctm style (value :ctm, this is
|
55
|
+
# the default), the YAML
|
56
|
+
# style (value :yaml) or no style (value :blank) is supported.
|
57
|
+
#
|
58
|
+
# In ctm style an item identifier starts with a "^",
|
59
|
+
# a subject locator starts with a "=" and
|
60
|
+
# a subject identifiers contains no prefix.
|
61
|
+
#
|
62
|
+
# In yaml style an item identifiers start with a "ii:",
|
63
|
+
# a subject locator starts with a "sl:" and
|
64
|
+
# a subject identifier start with a "si:".
|
65
|
+
#
|
66
|
+
#
|
67
|
+
# :call-seq:
|
68
|
+
# reference -> String
|
69
|
+
# reference(params = {}) -> String
|
70
|
+
#
|
71
|
+
def reference(params = {})
|
72
|
+
return references(params).sort_by{|identifier| identifier.size}.reverse.first
|
73
|
+
end
|
22
74
|
|
23
75
|
# Returns all identifiers of this Topic as Array of Locators.
|
24
76
|
#
|
25
77
|
# :call-seq:
|
26
|
-
#
|
78
|
+
# references_as_locators -> Array of Locators
|
27
79
|
#
|
28
|
-
def
|
29
|
-
# TODO Spec
|
80
|
+
def references_as_locators
|
30
81
|
subject_identifiers.to_a + subject_locators.to_a + item_identifiers.to_a
|
31
82
|
end
|
32
83
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
2
|
# License: Apache License, Version 2.0
|
3
3
|
|
4
|
-
module Sugar
|
4
|
+
module RTM::Sugar
|
5
5
|
module Topic
|
6
6
|
module Typed
|
7
7
|
|
@@ -152,8 +152,56 @@ module Sugar
|
|
152
152
|
# topic_is_a?(type)
|
153
153
|
#
|
154
154
|
def topic_is_a?(type)
|
155
|
-
|
155
|
+
topic_map.cached self, :is_a?, type do
|
156
|
+
self.transitive_types.include?(topic_map.get(type))
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
# States if this topic is used as type of a typed Construct.
|
161
|
+
#
|
162
|
+
# :call-seq:
|
163
|
+
# used_as_type? -> true or false
|
164
|
+
#
|
165
|
+
def used_as_type?
|
166
|
+
used_as_name_type? || used_as_occurrence_type? || used_as_association_type? || used_as_role_type?
|
167
|
+
end
|
168
|
+
|
169
|
+
# States if this topic is used as type of an Association.
|
170
|
+
#
|
171
|
+
# :call-seq:
|
172
|
+
# used_as_association_type? -> true or false
|
173
|
+
#
|
174
|
+
def used_as_association_type?
|
175
|
+
not self.typed_associations.empty?
|
156
176
|
end
|
177
|
+
|
178
|
+
# States if this topic is used as type of a Name.
|
179
|
+
#
|
180
|
+
# :call-seq:
|
181
|
+
# used_as_name_type? -> true or false
|
182
|
+
#
|
183
|
+
def used_as_name_type?
|
184
|
+
not self.typed_names.empty?
|
185
|
+
end
|
186
|
+
|
187
|
+
# States if this topic is used as type of an Occurrence.
|
188
|
+
#
|
189
|
+
# :call-seq:
|
190
|
+
# used_as_occurrence_type -> true or false
|
191
|
+
#
|
192
|
+
def used_as_occurrence_type?
|
193
|
+
not self.typed_occurrences.empty?
|
194
|
+
end
|
195
|
+
|
196
|
+
# States if this topic is used as type of a Role.
|
197
|
+
#
|
198
|
+
# :call-seq:
|
199
|
+
# used_as_role_type? -> true or false
|
200
|
+
#
|
201
|
+
def used_as_role_type?
|
202
|
+
not self.typed_roles.empty?
|
203
|
+
end
|
204
|
+
|
157
205
|
end
|
158
206
|
end
|
159
207
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
module RTM::Sugar
|
5
|
+
module TopicMap
|
6
|
+
module QueryCache
|
7
|
+
|
8
|
+
# The query cache is disabled by default. Enables the query cache.
|
9
|
+
# Does not erase the cache if it was already enabled.
|
10
|
+
#
|
11
|
+
# :call-seq:
|
12
|
+
# enable_query_cache -> nil
|
13
|
+
#
|
14
|
+
def enable_query_cache
|
15
|
+
@query_cache ||= {}
|
16
|
+
return
|
17
|
+
end
|
18
|
+
|
19
|
+
# The query cache is disabled by default. Disables the query cache.
|
20
|
+
#
|
21
|
+
# :call-seq:
|
22
|
+
# disable_query_cache -> nil
|
23
|
+
#
|
24
|
+
def disable_query_cache
|
25
|
+
@query_cache = nil # FIXME: This method is unsafe in multithreaded environments: Setting "@query_cache = nil" while @query_cache is being accessed in method "cached" may cause exceptions to be raised.
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
# Erases the query cache. This needs to be invoked every time there
|
30
|
+
# is a write access to the topic map.
|
31
|
+
#
|
32
|
+
# :call-seq:
|
33
|
+
# reset_query_cache -> nil
|
34
|
+
#
|
35
|
+
def reset_query_cache
|
36
|
+
@query_cache = @query_cache? {} : nil
|
37
|
+
return
|
38
|
+
end
|
39
|
+
|
40
|
+
# If query caching is enabled, looks up the result of
|
41
|
+
# module_name.method_name(parameters) in the cache and if present,
|
42
|
+
# returns it. If
|
43
|
+
# the result has not yet been stored, executes module_name.method_name(parameters),
|
44
|
+
# stores the result and returns it.
|
45
|
+
#
|
46
|
+
# If query caching is disabled, executes module_name.method_name(parameters)
|
47
|
+
# and returns the result.
|
48
|
+
#
|
49
|
+
# :call-seq:
|
50
|
+
# cached(module_name, method_name, parameters) {method_body} -> result
|
51
|
+
#
|
52
|
+
def cached(*args)
|
53
|
+
if @query_cache # Maybe we can optimize this simple if statement away by making enable_query_cache extend the particular TopicMap instance's metaclass. But maybe then the cached version is slower.
|
54
|
+
result = @query_cache.fetch(args,:not_found) # :not_found if not cached, if result is nil, we want to cache nil as well.
|
55
|
+
if result==:not_found
|
56
|
+
result = yield
|
57
|
+
@query_cache[args] = result
|
58
|
+
end
|
59
|
+
return result
|
60
|
+
else
|
61
|
+
yield #execute without caching
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
|
4
|
+
|
5
|
+
module RTM::Sugar
|
6
|
+
module TopicMap
|
7
|
+
module Themes
|
8
|
+
|
9
|
+
# Returns all topics in the topic map used
|
10
|
+
# in the scope property of Associations.
|
11
|
+
#
|
12
|
+
# The result may be empty.
|
13
|
+
#
|
14
|
+
# :call-seq:
|
15
|
+
# association_themes -> Array of Topics
|
16
|
+
#
|
17
|
+
def association_themes
|
18
|
+
scoped_index.get_association_themes.to_a
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns all topics in the topic map used
|
22
|
+
# in the scope property of Names.
|
23
|
+
#
|
24
|
+
# :call-seq:
|
25
|
+
# name_themes -> Array of Topics
|
26
|
+
#
|
27
|
+
def name_themes
|
28
|
+
scoped_index.get_name_themes.to_a
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns all topics in the topic map used
|
32
|
+
# in the scope property of Occurrences.
|
33
|
+
#
|
34
|
+
# :call-seq:
|
35
|
+
# occurrence_themes -> Array of Topics
|
36
|
+
#
|
37
|
+
def occurrence_themes
|
38
|
+
scoped_index.get_occurrence_themes.to_a
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns all topics in the topic map used
|
42
|
+
# in the scope property of Variants.
|
43
|
+
#
|
44
|
+
# :call-seq:
|
45
|
+
# variant_themes -> Array of Topics
|
46
|
+
#
|
47
|
+
def variant_themes
|
48
|
+
scoped_index.get_variant_themes.to_a
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|