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.
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,31 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM
5
+ module Navigation
6
+ module Topic
7
+
8
+ # Returns all indicators (subject identifiers) of this Topic.
9
+ #
10
+ # The result may be empty.
11
+ #
12
+ # :call-seq:
13
+ # indicators -> Array of Strings
14
+ #
15
+ def indicators
16
+ getSubjectIdentifiers.map{|locator| locator.value}
17
+ end
18
+
19
+ # Returns one indicator (subject identifier) of this Topic or nil
20
+ # if this Topic has no indicator.
21
+ #
22
+ # :call-seq:
23
+ # indicator -> String or nil
24
+ #
25
+ def indicator
26
+ return indicators.empty? ? nil : indicators.sort.first # TODO Which sorting algorithm?
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM
5
+ module Navigation
6
+ module Topic
7
+
8
+ # Returns all item identifier of this Topic.
9
+ #
10
+ # The result may be empty.
11
+ #
12
+ # :call-seq:
13
+ # items -> Array of Strings
14
+ #
15
+ def items
16
+ getItemIdentifiers.map{|locator| locator.value}
17
+ end
18
+
19
+ # Returns one item identifier of this Topic or nil
20
+ # if this Topic has no item identifier.
21
+ #
22
+ # :call-seq:
23
+ # item -> String or nil
24
+ #
25
+ def item
26
+ return items.empty? ? nil : items.sort.first # TODO Which sorting algorithm?
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM
5
+ module Navigation
6
+ module Topic
7
+
8
+ # Returns all subject locators of this Topic.
9
+ #
10
+ # The result may be empty.
11
+ #
12
+ # :call-seq:
13
+ # locators -> Array of Strings
14
+ #
15
+ def locators
16
+ getSubjectLocators.map{|locator| locator.value}
17
+ end
18
+
19
+ # Returns one subject locator of this Topic or nil
20
+ # if this Topic has no subject locator.
21
+ #
22
+ # :call-seq:
23
+ # locator -> String or nil
24
+ #
25
+ def locator
26
+ return locators.empty? ? nil : locators.sort.first # TODO Which sorting algorithm?
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM
5
+ module Navigation
6
+ module Topic
7
+
8
+ # Returns all Associations in which this Topic plays a Role.
9
+ #
10
+ # The optional
11
+ # identifier specifies the type of the Roles to be considered.
12
+ # The identifier may be a topic reference.
13
+ #
14
+ # Multiple instances of the same Association are possible.
15
+ # The result may be empty.
16
+ #
17
+ # :call-seq:
18
+ # reverse_players -> Array of Associations
19
+ # reverse_players(identifier) -> Array of Associations
20
+ #
21
+ def reverse_players(type = :any)
22
+ roles_played(type).map{|r| r.parent}
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,166 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM
5
+ module Navigation
6
+ module Topic
7
+
8
+ # Returns all Topic players that exist in binary supertype-subtype Associations
9
+ # where this Topic playes the subtype-Role.
10
+ #
11
+ # The result may be an empty Array.
12
+ #
13
+ # :call-seq:
14
+ # direct-supertypes -> Array of Topics
15
+ #
16
+ def direct_supertypes
17
+ roles_played(topic_map.get(RTM::PSI[:subtype]),topic_map.get(RTM::PSI[:supertype_subtype])).
18
+ reject{|r| r.getParent.getRoles.size!=2}.
19
+ map{|r| r.parent[RTM::PSI[:supertype]].first.player}.flatten.uniq
20
+ end
21
+
22
+ # Creates a binary supertype-subtype-Association where identifier defines
23
+ # the player of the supertype-Role. The current Topic will play the
24
+ # subtype-Role. Returns the created Association.
25
+ #
26
+ # Identifier may be a topic reference.
27
+ #
28
+ # :call-seq:
29
+ # add_supertype(identifier) -> Association
30
+ #
31
+ def add_supertype(new_supertype)
32
+ asso = topic_map.create_association(RTM::PSI[:supertype_subtype])
33
+ asso.create_role(RTM::PSI[:subtype],self)
34
+ asso.create_role(RTM::PSI[:supertype],new_supertype)
35
+ asso
36
+ end
37
+
38
+ # Creates one or several binary supertype-subtype-Associations where
39
+ # each identifier defines
40
+ # the player of a supertype-Role. The current topic will play the
41
+ # subtype-Role in each association. Returns the associations.
42
+ #
43
+ # The identifiers may be topic references.
44
+ #
45
+ # :call-seq:
46
+ # add_supertypes(identifier1, identifier2, ...) -> Array of Associtions
47
+ #
48
+ def add_supertypes(*args)
49
+ args.flatten!
50
+ args.map{|identifier| add_supertype(identifier)}
51
+ end
52
+
53
+ # Returns all supertypes of this Topic. The result includes
54
+ # all direct supertypes
55
+ # and the supertypes of these direct supertypes.
56
+ #
57
+ # The result may be an empty Array.
58
+ #
59
+ # :call-seq:
60
+ # transitive_supertypes -> Array of Topics
61
+ #
62
+ def transitive_supertypes
63
+ # topic_map.cached self, :transitive_supertypes do
64
+ result_types = new_s_t = direct_supertypes
65
+ until new_s_t.empty?
66
+ new_s_t = new_s_t.map{|s| s.direct_supertypes}.flatten.uniq
67
+ new_s_t = new_s_t.reject{|s| result_types.include?(s)}
68
+ result_types = result_types + new_s_t
69
+ end
70
+ result_types
71
+ # end
72
+ end
73
+
74
+ # Returns all supertypes of this Topic. The result includes the direct_supertypes
75
+ # and the supertypes of these direct_supertypes of this Topic as well as the Topic itself.
76
+ #
77
+ # :call-seq:
78
+ # transitive_supertypes_with_self -> Array of Topics
79
+ #
80
+ def transitive_supertypes_with_self
81
+ transitive_supertypes + self
82
+ end
83
+
84
+ # Returns all Topics that exist in binary supertype-subtype Associations
85
+ # where this Topic playes the supertype-Role.
86
+ #
87
+ # The result may be an empty Array.
88
+ #
89
+ # :call-seq:
90
+ # direct-subtypes -> Array of Topics
91
+ #
92
+ def direct_subtypes
93
+ roles(topic_map.get(RTM::PSI[:supertype]),topic_map.get(RTM::PSI[:supertype_subtype])).
94
+ reject{|r| r.getParent.getRoles.size!=2}.
95
+ map {|r| r.getParent[RTM::PSI[:subtype]].first.player}.flatten.uniq
96
+ end
97
+
98
+ # Creates a binary supertype-subtype-Association where identifier defines
99
+ # the player of the subtype-Role. The current Topic will play the
100
+ # supertype-Role. Returns the created Association.
101
+ #
102
+ # Identifier may be topic reference.
103
+ #
104
+ # :call-seq:
105
+ # add_subtype(identifier) -> Association
106
+ #
107
+ def add_subtype(new_subtype)
108
+ asso = topic_map.create_association(RTM::PSI[:supertype_subtype])
109
+ asso.create_role(RTM::PSI[:supertype],self)
110
+ asso.create_role(RTM::PSI[:subtype],new_subtype)
111
+ asso
112
+ end
113
+
114
+ # Creates one or several binary supertype-subtype-Associations where
115
+ # each identifier defines
116
+ # the player of a subtype-Role. The current topic will play the
117
+ # supertype-Role in each association. Returns the associations.
118
+ #
119
+ # The identifiers may be topic references.
120
+ #
121
+ # :call-seq:
122
+ # add_subtypes(identifier1, identifier2, ...) -> Array of Associtions
123
+ #
124
+ def add_subtypes(*args)
125
+ args.flatten!
126
+ args.map{|identifier| add_subtype(identifier)}
127
+ end
128
+
129
+ # Returns all subtypes of this Topic. The result includes the direct subtypes
130
+ # and the subtypes of these direct subtypes.
131
+ #
132
+ # The result may be an empty Array.
133
+ #
134
+ # :call-seq:
135
+ # transitive_subtypes -> Array of Topics
136
+ #
137
+ def transitive_subtypes
138
+ topic_map.cached self, :transitive_subtypes do
139
+ result_types = new_s_t = direct_subtypes
140
+ until new_s_t.empty?
141
+ new_s_t = new_s_t.map{|s| s.direct_subtypes}.flatten.uniq
142
+ new_s_t = new_s_t.reject{|s| result_types.include?(s)}
143
+ result_types = result_types + new_s_t
144
+ end
145
+ result_types
146
+ end
147
+ end
148
+
149
+ # Returns all subtypes of this Topic. The result includes the direct_subtypes
150
+ # and the subtypes of these direct_subtypes of this Topic as well as the Topic itself.
151
+ #
152
+ # :call-seq:
153
+ # transitive_subtypes_with_self -> Array of Topics
154
+ #
155
+ def transitive_subtypes_with_self
156
+ transitive_subtypes + self
157
+ end
158
+
159
+ alias :supertypes :transitive_supertypes
160
+ alias :subtypes :transitive_subtypes
161
+ alias :reverse_subtypes :supertypes
162
+ alias :reverse_supertypes :subtypes
163
+
164
+ end
165
+ end
166
+ end
@@ -0,0 +1,51 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM
5
+ module Navigation
6
+ module Topic
7
+
8
+ # First computes all Associations where this Topic playes a Role.
9
+ # There, the optional identifier filters the Associations for their type.
10
+ #
11
+ # Returns all Players of all Roles in these Associations.
12
+ # The current Topic is not included in the result.
13
+ # The result may be empty.
14
+ #
15
+ # The identifier may be a topic reference.
16
+ #
17
+ # :call-seq:
18
+ # traverse(identifier) -> Array of Topics
19
+ #
20
+ def traverse(type = :any)
21
+ unless type == :any
22
+ _topic = topic_map.get(type)
23
+ return [] unless _topic
24
+ end
25
+ _res = roles_played.map{|r| r.parent} #associations
26
+ _res = _res.select{|a| a.type == _topic} unless type == :any
27
+ _res = _res.map{|a| a.roles.map{ |r| r.player}}.flatten #players of all roles in these associations
28
+ # unless _res.empty?
29
+ # _res.each_with_index do |x,i|
30
+ # if x == self
31
+ # _res.delete_at(i)
32
+ # break
33
+ # end
34
+ # end
35
+ # end
36
+ _res =_res.reject{|p| p == self}
37
+ return _res
38
+ end
39
+
40
+ # Always returns an empty Array
41
+ #
42
+ # :call-seq:
43
+ # reverse_traverse -> Array
44
+ #
45
+ def reverse_traverse
46
+ Array.new
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,109 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM
5
+ module Navigation
6
+ module Topic
7
+
8
+ # Returns the topics this topic is an instance of.
9
+ #
10
+ # The result may be empty.
11
+ #
12
+ # :call-seq:
13
+ # types -> Set of Topics
14
+ #
15
+ def types
16
+ # NO SUPERISE IN Axes/NAVIGATION
17
+ raise "This method (types) should never be executed because the corresponding TMAPI function should be called"
18
+ getTypes
19
+ end
20
+
21
+ # Returns the topic this topic is an instance of. It must have
22
+ # exactly one type, else an error is raised.
23
+ #
24
+ # Returns nil if this Topic has no type.
25
+ #
26
+ # :call-seq:
27
+ # type -> Topic or nil
28
+ #
29
+ def type
30
+ _types = types
31
+ raise "Topic must have exactly one type to call the type-method. Use the types-method instead." unless _types.size < 2
32
+ _types.size == 1 ? _types.to_a.first : nil
33
+ end
34
+
35
+ # Returns the topics which are instances of this topic.
36
+ # This method uses the TMAPI TypeInstanceIndex.
37
+ #
38
+ # The result may be empty.
39
+ #
40
+ # :call-seq:
41
+ # instances -> Set of Topics
42
+ #
43
+ def instances
44
+ type_instance_index.getTopics(self)
45
+ end
46
+
47
+ # Returns the instance of this Topic. It must have exactly one
48
+ # instance, else an error is raised.
49
+ #
50
+ # Returns nil if this Topic has no instance.
51
+ #
52
+ # :call-seq:
53
+ # instance -> Topic
54
+ #
55
+ def instance
56
+ _instances = instances
57
+ raise "Topic must have exactly one instance to call the instance-method. Use the instances-method instead." unless _instances.size < 2
58
+ _instances.size == 1 ? _instances.to_a.first : nil
59
+ end
60
+
61
+ alias :reverse_types :instances
62
+
63
+ # Returns the types this topic is an instance of. Calls
64
+ # the TMAPI getTypes method.
65
+ #
66
+ # The result may be empty.
67
+ #
68
+ # :call-seq:
69
+ # reverse_instances -> Set of Topics
70
+ #
71
+ def reverse_instances
72
+ types
73
+ end
74
+
75
+ # Returns the types and all transitive supertypes of the types of
76
+ # this topic. No duplicates are returned.
77
+ #
78
+ # The result may be empty.
79
+ #
80
+ # :call-seq:
81
+ # transitive_types -> Array of Topics
82
+ #
83
+ def transitive_types
84
+ trans_types = types.to_a #may be empty
85
+ types.each do |type|
86
+ trans_types.concat(type.transitive_supertypes)
87
+ end
88
+ trans_types = trans_types.uniq #no duplicates outside of tmql mode
89
+ end
90
+
91
+ # Returns instances and the instances of all transitive subtypes
92
+ # of this topic. No duplicates are returned.
93
+ #
94
+ # The result may be empty.
95
+ #
96
+ # :call-seq:
97
+ # transitive_instances -> Array of Topics
98
+ #
99
+ def transitive_instances
100
+ trans_instances = instances.to_a #may be empty
101
+ transitive_subtypes.each do |subtype|
102
+ trans_instances.concat(subtype.instances.to_a)
103
+ end
104
+ trans_instances = trans_instances.uniq #no duplicates outside of tmql mode
105
+ end
106
+
107
+ end
108
+ end
109
+ end