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
@@ -1,3 +1,6 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
1
4
  module RTM
2
5
  PSI = {}
3
6
  PSI[:type_instance] = "http://psi.topicmaps.org/iso13250/model/type-instance"
@@ -20,10 +23,21 @@ module RTM
20
23
  #PSI[:XTMxx] = "http://www.topicmaps.org/xtm/"
21
24
  #PSI[:XS] = "http://www.w3.org/2001/XMLSchema"
22
25
  #PSI[:DC] = "http://purl.org/dc/elements/1.1/"
26
+ PSI[:Float] = "http://www.w3.org/2001/XMLSchema#float"
27
+ PSI[:Double] = "http://www.w3.org/2001/XMLSchema#double"
28
+ PSI[:Long] = "http://www.w3.org/2001/XMLSchema#long"
29
+ PSI[:Integer] = "http://www.w3.org/2001/XMLSchema#integer"
30
+ PSI[:Int] = "http://www.w3.org/2001/XMLSchema#int"
31
+ PSI[:Decimal] = "http://www.w3.org/2001/XMLSchema#decimal"
32
+ PSI[:Date] = "http://www.w3.org/2001/XMLSchema#date"
33
+ PSI[:DateTime] = "http://www.w3.org/2001/XMLSchema#dateTime"
34
+ PSI[:Time] = "http://www.w3.org/2001/XMLSchema#time"
23
35
 
24
36
  PSI[:XTM] = "http://psi.topicmaps.org/iso13250/glossary/XTM"
25
37
  PSI[:association] = "http://psi.topicmaps.org/iso13250/glossary/association"
38
+ PSI[:role] = "http://psi.topicmaps.org/iso13250/glossary/association-role"
26
39
  PSI[:association_role] = "http://psi.topicmaps.org/iso13250/glossary/association-role"
40
+ PSI[:role_type] = "http://psi.topicmaps.org/iso13250/glossary/association-role-type"
27
41
  PSI[:association_role_type] = "http://psi.topicmaps.org/iso13250/glossary/association-role-type"
28
42
  PSI[:association_type] = "http://psi.topicmaps.org/iso13250/glossary/association-type"
29
43
  PSI[:information_resource] = "http://psi.topicmaps.org/iso13250/glossary/information-resource"
@@ -41,14 +55,36 @@ module RTM
41
55
  PSI[:subject_locator] = "http://psi.topicmaps.org/iso13250/glossary/subject-locator"
42
56
  PSI[:topic] = "http://psi.topicmaps.org/iso13250/glossary/topic"
43
57
  PSI[:topic_map] = "http://psi.topicmaps.org/iso13250/glossary/topic-map"
58
+ PSI[:construct] = "http://psi.topicmaps.org/iso13250/glossary/topic-map-construct"
44
59
  PSI[:topic_map_construct] = "http://psi.topicmaps.org/iso13250/glossary/topic-map-construct"
45
60
  PSI[:Topic_Maps] = "http://psi.topicmaps.org/iso13250/glossary/Topic-Maps"
46
61
  PSI[:topic_name] = "http://psi.topicmaps.org/iso13250/glossary/topic-name"
47
62
  PSI[:topic_name_type] = "http://psi.topicmaps.org/iso13250/glossary/topic-name-type"
48
63
  PSI[:topic_type] = "http://psi.topicmaps.org/iso13250/glossary/topic-type"
49
64
  PSI[:unconstrained_scope] = "http://psi.topicmaps.org/iso13250/glossary/unconstrained-scope"
65
+ PSI[:variant] = "http://psi.topicmaps.org/iso13250/glossary/variant-name"
50
66
  PSI[:variant_name] = "http://psi.topicmaps.org/iso13250/glossary/variant-name"
51
67
 
68
+ PSI[:subject_representation] = "http://psi.topicmapslab.de/subject-representation"
69
+ PSI[:represented_subject] = "http://psi.topicmapslab.de/represented-subject"
70
+
71
+ # languages
72
+ # PSI[:] = "http://psi.oasis-open.org/iso/639/#"
73
+ PSI[:language] = "http://psi.oasis-open.org/iso/639/#language"
74
+ PSI[:language_group] = "http://psi.oasis-open.org/iso/639/#language-group"
75
+ PSI[:code_a2] = "http://psi.oasis-open.org/iso/639/#code-a2"
76
+ PSI[:code_a3b] = "http://psi.oasis-open.org/iso/639/#code-a3b"
77
+ PSI[:code_a3t] = "http://psi.oasis-open.org/iso/639/#code-a3t"
78
+ PSI[:multiple_languages] = "http://psi.oasis-open.org/iso/639/#mul"
79
+ #PSI[:czech] = "http://psi.oasis-open.org/iso/639/#ces"
80
+ #PSI[:dutch] = "http://psi.oasis-open.org/iso/639/#nld"
81
+ #PSI[:english] = "http://psi.oasis-open.org/iso/639/#eng"
82
+ #PSI[:french] = "http://psi.oasis-open.org/iso/639/#fra"
83
+ #PSI[:german] = "http://psi.oasis-open.org/iso/639/#deu"
84
+ #PSI[:italien] = "http://psi.oasis-open.org/iso/639/#ita"
85
+ #PSI[:japanese] = "http://psi.oasis-open.org/iso/639/#jpn"
86
+
87
+
52
88
  PSI1 = {}
53
89
  PSI1[:XTM] = "http://www.topicmaps.org/xtm/1.0/core.xtm"
54
90
  PSI1[:topic] = "http://www.topicmaps.org/xtm/1.0/core.xtm#topic"
@@ -67,7 +103,8 @@ module RTM
67
103
  PREFIX[:tm] = "http://psi.topicmaps.org/iso13250/model/" # This is the namespace for the concepts defined by TMDM.
68
104
  PREFIX[:glossary] = "http://psi.topicmaps.org/iso13250/glossary/"
69
105
  PREFIX[:xsd] = "http://www.w3.org/2001/XMLSchema#" # This is the namespace for the XML Schema Datatypes.
70
- PREFIX[:tmql] = "http://psi.topicmaps.org/tmql/1.0/" # Under this prefix the concepts of TMQL itself are located.
71
- PREFIX[:fn] = "http://psi.topicmaps.org/tmql/1.0/functions" # Under this prefix user-callable functions of the predefined TMQL environment are located.
106
+ PREFIX[:tmql] = "http://psi.topicmaps.org/tmql/1.0/" # Under this prefix the concepts of Axes itself are located.
107
+ PREFIX[:fn] = "http://psi.topicmaps.org/tmql/1.0/functions" # Under this prefix user-callable functions of the predefined Axes environment are located.
72
108
  PREFIX[:xtm1] = "http://www.topicmaps.org/xtm/1.0/core.xtm#"
109
+ PREFIX[:language] = "http://psi.oasis-open.org/iso/639/#" # This is the namespace for the languae PSIs
73
110
  end
@@ -0,0 +1,47 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM::Sugar;end
5
+
6
+ require 'rtm/sugar/topic/topic_ref'
7
+ require 'rtm/sugar/topic/hash_access'
8
+ require 'rtm/sugar/topic/characteristics'
9
+ require 'rtm/sugar/topic/counterparts'
10
+ require 'rtm/sugar/topic/scoped'
11
+ require 'rtm/sugar/topic/typed'
12
+ require 'rtm/sugar/topic/best_name'
13
+ RTM::Topic.register_extension(RTM::Sugar::Topic::TopicRef)
14
+ RTM::Topic.register_extension(RTM::Sugar::Topic::HashAccess)
15
+ RTM::Topic.register_extension(RTM::Sugar::Topic::Characteristics)
16
+ RTM::Topic.register_extension(RTM::Sugar::Topic::Counterparts)
17
+ RTM::Topic.register_extension(RTM::Sugar::Topic::Scoped)
18
+ RTM::Topic.register_extension(RTM::Sugar::Topic::Typed)
19
+ RTM::Topic.register_extension(RTM::Sugar::Topic::BestName)
20
+
21
+ require "rtm/sugar/association/hash_access"
22
+ RTM::Association.register_extension(RTM::Sugar::Association::HashAccess)
23
+
24
+ require "rtm/sugar/role/counterparts"
25
+ RTM::Role.register_extension(RTM::Sugar::Role::Counterparts)
26
+
27
+ require "time"
28
+ require "rtm/sugar/occurrence/dynamic_value"
29
+ require "rtm/sugar/occurrence/external"
30
+ RTM::Occurrence.register_extension(RTM::Sugar::Occurrence::DynamicValue)
31
+ RTM::Occurrence.register_extension(RTM::Sugar::Occurrence::External)
32
+
33
+ require "rtm/sugar/typed/types"
34
+ RTM::Typed.register_extension(RTM::Sugar::Typed::Types)
35
+
36
+ require 'rtm/sugar/reifiable/reifier'
37
+ RTM::Reifiable.register_extension(RTM::Sugar::Reifiable::CreateReifier)
38
+
39
+ require 'rtm/sugar/topic_map/query_cache'
40
+ require 'rtm/sugar/topic_map/themes'
41
+ module RTM::TopicMap
42
+ include RTM::Reifiable
43
+ @query_cache = nil #disables query caching
44
+ end
45
+ RTM::TopicMap.register_extension(RTM::Sugar::TopicMap::QueryCache)
46
+ RTM::TopicMap.register_extension(RTM::Sugar::TopicMap::Themes)
47
+
@@ -0,0 +1,46 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM::Sugar
5
+ module Association
6
+ # This module implements methods for Hash-like access in Associations.
7
+ module HashAccess
8
+
9
+ # Returns all Roles of this Association.
10
+ #
11
+ # If type is given, returns the Roles of this Association
12
+ # whose Role type match type.
13
+ # Type may be a topic reference.
14
+ #
15
+ # The result may be empty.
16
+ #
17
+ # :call-seq:
18
+ # [] -> Array of Roles
19
+ # [type] -> Array of Roles
20
+ #
21
+ def [](type=:any)
22
+ return getRoles.to_a if type == :any
23
+ return getRoles.to_a unless type
24
+ type = topic_map.get(type)
25
+ if type
26
+ return getRoles(type).to_a
27
+ else
28
+ return []
29
+ end
30
+ end
31
+
32
+
33
+ # Creates a new Role in this Association where type specifies the
34
+ # Role type and player the associated Role player.
35
+ # Type and player may each be a topic reference.
36
+ #
37
+ # :call-seq:
38
+ # [type]= player
39
+ #
40
+ # TODO Issue #919
41
+ def []=(type,player)
42
+ create_role(type,player)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,58 @@
1
+ # Copyright: Copyright 2010 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM::Sugar::Occurrence
5
+ module DynamicValue
6
+
7
+ # Given the occurrence's datatype this method returns the value of this
8
+ # occurrence cast as appropriate Ruby type.
9
+ #
10
+ # :call-seq:
11
+ # dynamic_value -> Object
12
+ #
13
+ def dynamic_value
14
+ value = self.value # a String
15
+ case self.datatype.reference
16
+ when RTM::PSI[:IRI]
17
+ return topic_map.create_locator(value)
18
+ when RTM::PSI[:Decimal]
19
+ return value.to_f
20
+ when RTM::PSI[:Double]
21
+ return value.to_f
22
+ when RTM::PSI[:Int]
23
+ return value.to_i
24
+ when RTM::PSI[:Integer]
25
+ return value.to_i
26
+ when RTM::PSI[:Float]
27
+ return value.to_f
28
+ when RTM::PSI[:Long]
29
+ return value.to_i
30
+ when RTM::PSI[:Date]
31
+ return Date.parse(value)
32
+ when RTM::PSI[:DateTime]
33
+ return DateTime.parse(value)
34
+ when RTM::PSI[:Time]
35
+ return Time.parse(value)
36
+ else
37
+ return value
38
+ end
39
+ end
40
+
41
+ end
42
+ end
43
+
44
+ class Float
45
+ def to_xsd_double
46
+ s = self.to_s
47
+
48
+ case s
49
+ when "Infinity"
50
+ "INF"
51
+ when "-Infinity"
52
+ "-INF"
53
+ else
54
+ s
55
+ end
56
+ end
57
+ end
58
+
@@ -0,0 +1,53 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM::Sugar::Occurrence
5
+ module External
6
+
7
+ # Creates an association out of this occurrence which represents the
8
+ # occurrence information in relation to the parent topic.
9
+ #
10
+ # The association is of type "http://psi.topicmapslab.de/subject-representation".
11
+ # It includes two roles. The parent topic plays the role of type
12
+ # "http://psi.topicmapslab.de/represented-subject". The topic with the
13
+ # subject locator created from the occurrence value plays the role
14
+ # of a type the same as the occurrence type.
15
+ #
16
+ # The subject locator will be resolved using the get-method of RTM::TopicMap,
17
+ # that means if the occurrence value is stored as String and is not a valid uri
18
+ # the base_iri of the topic map is used to create one.
19
+ #
20
+ # The occurrence datatype may be xsd:anyURI as well as xsd:String.
21
+ # The occurrence value must be a valid URL.
22
+ #
23
+ # Example: Creates an association out of the occurrence with value
24
+ # "http://www.leipzig.de" and type "webpage" of the topic Leipzig:
25
+ # * association type: subject_representation
26
+ # * role 1: Leipzig plays the role "represented_subject"
27
+ # * role 2: topic with subject locator "http://www.leipzig.de" plays the role "webpage"
28
+ #
29
+ # :call-seq:
30
+ # externalize -> Association
31
+ #
32
+ def externalize
33
+ topic_map.create_association(RTM::PSI[:subject_representation], RTM::PSI[:represented_subject] => parent, self.type => "=#{self.value}")
34
+ end
35
+
36
+ # Executes externalize and removes this occurrence from the topic map afterwards
37
+ #
38
+ # :call-seq:
39
+ # externalize!
40
+ #
41
+ def externalize!(*args)
42
+ association = externalize(*args)
43
+ remove
44
+ return association
45
+ end
46
+
47
+ # Returns true, if the datatype of this occurrence equals xsd:anyURI.
48
+ def external?
49
+ return self.datatype.reference == RTM::PSI[:IRI] ? true : false
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,21 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM::Sugar::Reifiable
5
+ module CreateReifier
6
+
7
+ # Returns the reifier (a topic) of this Reifiable.
8
+ # If there is no current reifier, then a reifier will be generated.
9
+ # This reifier did not exist in the topic map before.
10
+ #
11
+ # :call-seq:
12
+ # reifier! -> Topic
13
+ #
14
+ def reifier!
15
+ self.reifier ||= self.topic_map.create_topic
16
+ end
17
+ alias :create_reifier :reifier!
18
+
19
+ end
20
+ end
21
+
@@ -1,51 +1,144 @@
1
- module RTM::Sugar
2
- module Role
3
- module Counterparts
4
- # This method fetches all roles from the parent association of this role, except itself (i.e. current role).
5
- # A filter-hash may be used to filter for the type of the other role (:otype =>topic_reference).
6
- # Examples:
7
- # this_role.counterparts # returns all
8
- # this_role.counterparts(:otype => some_topic) # returns only other roles which have type some_topic
9
- # this_role.counterparts(:otype => "some_reference") # as above, looking up the reference first
10
- def counterparts(filter={})
11
- self.parent.roles.reject{|r| r.id==self.id}.
12
- select{|r| filter[:otype] ? r.type == self.topic_map.get(filter[:otype]) : true}
13
- end
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
14
3
 
15
- # This methods fetches all players of the parent association of this role, except the player of itself.
16
- # It accepts a filter-hash like the counterparts-method.
17
- def counterplayers(*args)
18
- self.counterparts(*args).map{|r| r.player}
19
- end
4
+ module RTM::Sugar::Role
5
+ module Counterparts
6
+
7
+ # Returns all roles from the parent association of this role,
8
+ # except itself.
9
+ #
10
+ # A filter-hash may be used to filter for the type of the other roles
11
+ # (:otype) or the player of the other roles (:oplayer).
12
+ #
13
+ # The identfiers may be topic references.
14
+ #
15
+ # :call-seq:
16
+ # counterparts -> Array of Roles
17
+ # counterparts({:otype => identifier}) -> Array of Roles
18
+ #
19
+ def counterparts(filter={})
20
+ _roles = parent.roles.reject{|r| r.id==self.id}
21
+ otype = filter[:otype]
22
+ _roles = _roles.select{|r| r.type == topic_map.get(otype)} if otype && otype != :any
23
+ oplayer = filter[:oplayer]
24
+ _roles = _roles.select{|r| r.player == topic_map.get(oplayer)} if oplayer && oplayer != :any
25
+ return _roles
26
+ end
27
+
28
+ # Returns the other role, if the parent association is binary.
29
+ #
30
+ # :call-seq:
31
+ # counterpart -> Role
32
+ #
33
+ def counterpart
34
+ n = parent.roles.size
35
+ raise "Association must be unary or binary to use counterpart method. Please use counterparts for n-ary associations." if n > 2
36
+ return nil if n == 1
37
+ counterparts.first
38
+ end
39
+
40
+ # Returns all players of the parent Association of this Role,
41
+ # except the player of itself.
42
+ #
43
+ # A filter-hash may be used to filter for the type of the other Roles
44
+ # (:otype). The identifier may be a topic reference.
45
+ #
46
+ # :call-seq:
47
+ # counterplayers -> Array of Topics
48
+ # counterplayers({:otype => identifier}) -> Array of Topics
49
+ #
50
+ def counterplayers(filter={})
51
+ counterparts(filter).map{|r| r.player}
52
+ end
53
+
54
+ # Returns the player of the other role, if the parent association is binary.
55
+ #
56
+ # :call-seq:
57
+ # counterplayer -> Topic
58
+ #
59
+ def counterplayer
60
+ n = parent.roles.size
61
+ raise "Association must be unary or binary to use counterplayer method. Please use counterplayers for n-ary associations (n>2)." if n > 2
62
+ return nil if n == 1
63
+ counterparts.first.player
64
+ end
65
+
66
+ # Returns the Roles of other binary Associations for which the following
67
+ # applies:
68
+ #
69
+ # - this Role and all returned Roles must share a counterplayer.
70
+ #
71
+ # - if :rtype is set to :strict, the type of the returned Roles must equal
72
+ # the type of this Role
73
+ #
74
+ # - if :atype is set to :strict, the type of the parent Associaton of this Role must be equal
75
+ # to the type of the parent Associations of the other Roles
76
+ #
77
+ # - if :otype is set to :strict, the type of the Roles the shared counterplayers play (counterparts)
78
+ # must equal
79
+ #
80
+ # - if :arity is set to :strict, the size of the parent Associations must
81
+ # equal the size of the other associations involved
82
+ #
83
+ # Example: Returns all employee-roles of a company, if self is a Role an employee plays in an
84
+ # "firm-employee"-Association.
85
+ #
86
+ # Default: peers(:arity => :strict, :atype => :strict, :otype => :strict, :rtype => :strict)
87
+ #
88
+ # The result may be empty. Esp. if the parent Association includes only this Role, an empty Array is returned.
89
+ #
90
+ # :call-seq:
91
+ # peers -> Array of Roles
92
+ # peers(:arity => :strict) -> Array of Roles
93
+ # peers(:rtype => :strict, :atype => strict, :otype => :loose) -> Array of Roles
94
+ # etc.
95
+ #
96
+ def peers(params = {})
97
+ default_hash = {:arity => :strict, :atype => :strict, :otype => :strict, :rtype => :strict}
98
+ raise("peers: argument has to be a Hash") unless params.is_a? Hash
99
+ params.reject!{|k,v| ![:strict,:loose].include?(v)}
100
+ params = default_hash.merge(params)
101
+ # puts "\narity = " + (params[:arity] == :strict ? "strict" : "loose")
102
+ # puts "atype = " + (params[:atype] == :strict ? "strict" : "loose")
103
+ # puts "otype = " + (params[:otype] == :strict ? "strict" : "loose")
104
+ # puts "rtype = " + (params[:rtype] == :strict ? "strict" : "loose")
105
+ n = self.parent.roles.size
106
+ return [] if n == 1
107
+ atype = self.parent.type # association type
108
+ rtype = self.type #role type
109
+ c_parts = self.counterparts # other roles in the association of this player
110
+ _roles = []
111
+ c_parts.each do |c_part|
112
+ otype = c_part.type # type of the other role in the association
113
+ c_player = c_part.player
114
+ if params[:otype] == :loose
115
+ other_roles = c_player.roles.to_a
116
+ else
117
+ if params[:atype] == :strict
118
+ other_roles = c_player.roles(otype,atype).to_a
119
+ else
120
+ other_roles = c_player.roles(otype).to_a
121
+ end
122
+ end
123
+ other_roles = other_roles.select{|r| r.parent.roles.size == n} if params[:arity] == :strict #same n-ary
124
+ other_roles = other_roles.map{|r| r.counterparts}.flatten # other roles in these associations
125
+ other_roles = other_roles.select{|r| r.type == rtype} if params[:rtype] == :strict
126
+ other_roles = other_roles.reject{|r| r == self} # reject self
127
+ _roles = _roles + other_roles
128
+ end
129
+ return _roles
130
+ end
20
131
 
21
- # Fetches the other role, if the parent association is binary.
22
- def counterpart
23
- n = self.parent.roles.size
24
- raise "Association must be unary or binary to use counterpart method. Please use counterparts for n-ary associations." if n > 2
25
- return nil if n == 1
26
- self.counterparts.first
27
- end
28
-
29
- # Fetches the player of the other role, if the parent association is binary.
30
- def counterplayer
31
- n = self.parent.roles.size
32
- raise "Association must be unary or binary to use counterplayer method. Please use counterplayers for n-ary associations." if n > 2
33
- return nil if n == 1
34
- self.counterparts.first.player
35
- end
36
-
37
- # Fetches all roles of the (binary) parent associations which play the same role in the same with the counterplayer
38
- # TODO: filter not only otype but also atype and rtype.
39
- def peers
40
- cp = self.counterpart
41
- cp.player.roles.select{|r| r.type == cp.type}.map{|r| r.counterpart}
42
- end
43
- # Fetches all players of roles being in the same association with another topic as self
44
- # Example: current_role is a role of player "me" and type "employee"
45
- # current_role.peerplayers # returns all employees of my company (including me)
46
- def peerplayers
47
- self.peers.map{|r| r.player}
48
- end
132
+ # Returns all players of the peers of this Role.
133
+ #
134
+ # Example: Returns all employees of a company except the
135
+ # player of itself.
136
+ #
137
+ # :call-seq:
138
+ # peerplayers -> Array of Topics
139
+ #
140
+ def peerplayers
141
+ peers.map{|r| r.player}
49
142
  end
50
143
  end
51
144
  end