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
@@ -0,0 +1,114 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM::Sugar::Topic
5
+ module Scoped
6
+
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
49
+
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
61
+
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
70
+
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
97
+
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
106
+
107
+ private
108
+ def scoped_index
109
+ @scoped_index ||= topic_map.scoped_index
110
+ end
111
+
112
+ end
113
+ end
114
+
@@ -0,0 +1,86 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM::Sugar
5
+ module Topic
6
+ module TopicRef
7
+
8
+ # Returns an Array including all identifiers of this Topic.
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:".
23
+ #
24
+ # :call-seq:
25
+ # references -> Array of Strings
26
+ # references(params = {}) -> Array of Strings
27
+ #
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
47
+ end
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
74
+
75
+ # Returns all identifiers of this Topic as Array of Locators.
76
+ #
77
+ # :call-seq:
78
+ # references_as_locators -> Array of Locators
79
+ #
80
+ def references_as_locators
81
+ subject_identifiers.to_a + subject_locators.to_a + item_identifiers.to_a
82
+ end
83
+
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,207 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM::Sugar
5
+ module Topic
6
+ module Typed
7
+
8
+ # Returns the associations, names, occurrences and roles whose
9
+ # type equals this topic.
10
+ #
11
+ # The result may be empty.
12
+ #
13
+ # :call-seq:
14
+ # typed -> Array of Associations, Names, Occurrences and Roles
15
+ #
16
+ def typed
17
+ _index = topic_map.type_instance_index
18
+ _index.get_associations(self).to_a + _index.get_names(self).to_a + _index.get_occurrences(self).to_a + _index.get_roles(self).to_a
19
+ end
20
+
21
+ # Returns the associations, names, occurrences and roles whose
22
+ # type equals this topic or subtypes
23
+ # of this topic.
24
+ #
25
+ # The result may be empty.
26
+ #
27
+ # :call-seq:
28
+ # transitive_typed -> Array of Associations, Names, Occurrences and Roles
29
+ #
30
+ def transitive_typed
31
+ trans_typed = typed #may be empty
32
+ transitive_subtypes.each do |subtype|
33
+ trans_typed.concat(subtype.typed)
34
+ end
35
+ trans_typed = trans_typed.uniq #no duplicates outside of tmql mode
36
+ end
37
+
38
+ # Returns the associations whose type equals this topic.
39
+ #
40
+ # The result may be empty.
41
+ #
42
+ # :call-seq:
43
+ # typed_associations -> Array of Associations
44
+ #
45
+ def typed_associations
46
+ topic_map.type_instance_index.get_associations(self).to_a
47
+ end
48
+
49
+ # Returns the associations whose type equals this topic or subtypes
50
+ # of this topic.
51
+ #
52
+ # The result may be empty.
53
+ #
54
+ # :call-seq:
55
+ # transitive_typed_associations -> Array of Associations
56
+ #
57
+ def transitive_typed_associations
58
+ trans_types_assocs = typed_associations #may be empty
59
+ transitive_subtypes.each do |subtype|
60
+ trans_types_assocs.concat(subtype.typed_associations)
61
+ end
62
+ trans_types_assocs = trans_types_assocs.uniq #no duplicates outside of tmql mode
63
+ end
64
+
65
+ # Returns the names whose type equals this topic.
66
+ #
67
+ # The result may be empty.
68
+ #
69
+ # :call-seq:
70
+ # typed_names -> Array of Names
71
+ #
72
+ def typed_names
73
+ topic_map.type_instance_index.get_names(self).to_a
74
+ end
75
+
76
+ # Returns the names whose type equals this topic or subtypes
77
+ # of this topic.
78
+ #
79
+ # The result may be empty.
80
+ #
81
+ # :call-seq:
82
+ # transitive_typed_names -> Array of Associations
83
+ #
84
+ def transitive_typed_names
85
+ trans_types_names = typed_names #may be empty
86
+ transitive_subtypes.each do |subtype|
87
+ trans_types_names.concat(subtype.typed_names)
88
+ end
89
+ trans_types_names = trans_types_names.uniq #no duplicates outside of tmql mode
90
+ end
91
+
92
+ # Returns the occurrences whose type equals this topic.
93
+ #
94
+ # The result may be empty.
95
+ #
96
+ # :call-seq:
97
+ # typed_occurrences -> Array of Occurrences
98
+ #
99
+ def typed_occurrences
100
+ topic_map.type_instance_index.get_occurrences(self).to_a
101
+ end
102
+
103
+ # Returns the occurrences whose type equals this topic or subtypes
104
+ # of this topic.
105
+ #
106
+ # The result may be empty.
107
+ #
108
+ # :call-seq:
109
+ # transitive_typed_occurrences -> Array of Associations
110
+ #
111
+ def transitive_typed_occurrences
112
+ trans_types_occs = typed_occurrences #may be empty
113
+ transitive_subtypes.each do |subtype|
114
+ trans_types_occs.concat(subtype.typed_occurrences)
115
+ end
116
+ trans_types_occs = trans_types_occs.uniq #no duplicates outside of tmql mode
117
+ end
118
+
119
+ # Returns the roles whose type equals this topic.
120
+ #
121
+ # The result may be empty.
122
+ #
123
+ # :call-seq:
124
+ # typed_roles -> Array of Roles
125
+ #
126
+ def typed_roles
127
+ topic_map.type_instance_index.get_roles(self).to_a
128
+ end
129
+
130
+ # Returns the roles whose type equals this topic or subtypes
131
+ # of this topic.
132
+ #
133
+ # The result may be empty.
134
+ #
135
+ # :call-seq:
136
+ # transitive_typed_roles -> Array of Associations
137
+ #
138
+ def transitive_typed_roles
139
+ trans_types_roles = typed_roles #may be empty
140
+ transitive_subtypes.each do |subtype|
141
+ trans_types_roles.concat(subtype.typed_roles)
142
+ end
143
+ trans_types_roles = trans_types_roles.uniq #no duplicates outside of tmql mode
144
+ end
145
+
146
+ # Determines whether this topic is instance (directly or indirectly)
147
+ # of the argument type.
148
+ #
149
+ # Type may be a topic reference.
150
+ #
151
+ # :call-seq:
152
+ # topic_is_a?(type)
153
+ #
154
+ def topic_is_a?(type)
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?
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
+
205
+ end
206
+ end
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