rtm 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/DISCLAIMER +3 -1
  2. data/README +0 -0
  3. data/lib/rtm.rb +0 -1
  4. data/lib/rtm/axes/topic.rb +0 -3
  5. data/lib/rtm/axes/topics.rb +0 -3
  6. data/lib/rtm/connection.rb +4 -4
  7. data/lib/rtm/engine.rb +6 -5
  8. data/lib/rtm/extensions.rb +1 -1
  9. data/lib/rtm/helpers/no_output.rb +1 -1
  10. data/lib/rtm/io/from_xtm2_libxml.rb +2 -2
  11. data/lib/rtm/io/tmapix_from.rb +11 -24
  12. data/lib/rtm/io/tmapix_to.rb +38 -7
  13. data/lib/rtm/navigation/topic/characteristics.rb +7 -9
  14. data/lib/rtm/navigation/topic/supertypes.rb +1 -5
  15. data/lib/rtm/sugar.rb +16 -1
  16. data/lib/rtm/sugar/association/remove.rb +21 -0
  17. data/lib/rtm/sugar/name/remove.rb +18 -0
  18. data/lib/rtm/sugar/occurrence/external.rb +1 -0
  19. data/lib/rtm/sugar/occurrence/remove.rb +15 -0
  20. data/lib/rtm/sugar/topic/remove.rb +23 -0
  21. data/lib/rtm/sugar/topic/topic_ref.rb +111 -7
  22. data/lib/rtm/sugar/topic_map/readable.rb +19 -0
  23. data/lib/rtm/sugar/topic_map/remove.rb +15 -6
  24. data/lib/rtm/sugar/topic_map/resolve.rb +44 -0
  25. data/lib/rtm/sugar/topic_map/scoped.rb +42 -0
  26. data/lib/rtm/sugar/topic_map/types.rb +46 -0
  27. data/lib/rtm/sugar/variant/remove.rb +15 -0
  28. data/lib/rtm/version.rb +1 -2
  29. data/spec/rtm/axes/topic_spec.rb +4 -4
  30. data/spec/rtm/axes/topics_spec.rb +4 -4
  31. data/spec/rtm/engine_spec.rb +10 -1
  32. data/spec/rtm/io/tmapix_from_spec.rb +41 -9
  33. data/spec/rtm/io/tmapix_to_spec.rb +58 -32
  34. data/spec/rtm/io/to_rdf_spec.rb +8 -4
  35. data/spec/rtm/javatmapi_spec.rb +39 -29
  36. data/spec/rtm/navigation/topic/characteristics_spec.rb +11 -16
  37. data/spec/rtm/navigation/topic/supertypes_spec.rb +32 -89
  38. data/spec/rtm/navigation/topic_spec.rb +4 -4
  39. data/spec/rtm/sugar/association/hash_access_spec.rb +1 -1
  40. data/spec/rtm/sugar/topic/counterparts_spec.rb +18 -2
  41. data/spec/rtm/sugar/topic/remove_spec.rb +46 -0
  42. data/spec/rtm/sugar/topic/topic_ref_spec.rb +99 -26
  43. data/spec/rtm/sugar/topic_map/readable_spec.rb +25 -0
  44. data/spec/rtm/sugar/topic_map/remove_spec.rb +4 -1
  45. data/spec/rtm/sugar/topic_map/resolve_spec.rb +56 -0
  46. data/spec/rtm/sugar/topic_map/types_spec.rb +31 -0
  47. data/spec/rtm/tmapi/core/reifiable_spec.rb +0 -1
  48. data/spec/rtm/tmapi/core/topic_map_spec.rb +13 -8
  49. data/spec/rtm/tmapi/core/topic_spec.rb +17 -6
  50. data/spec/rtm/tmapi_spec.rb +2 -2
  51. data/spec/rtm_spec.rb +3 -3
  52. data/spec/spec_helper.rb +34 -6
  53. data/test/javalibs/junit-4.8.1.jar +0 -0
  54. data/test/javalibs/tmapi-tests-2.0.3-SNAPSHOT.jar +0 -0
  55. metadata +175 -165
  56. data/test/javalibs/junit-4.5.jar +0 -0
  57. data/test/javalibs/tmapi-2.0-tests.jar +0 -0
@@ -0,0 +1,23 @@
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 Remove
6
+
7
+ # Forcibly removes this topic from the topic map:
8
+ #
9
+ # * Forcibly removes all associations in which this topic is a player.
10
+ # * Forcibly removes all names and occurrences of this topic.
11
+ # * Removes the type-instance relations this topic occurrs in.
12
+ def force_remove
13
+ # TODO extend this, maybe allow for a removal of any topic no matter how important
14
+ # it may be for the whole topic map
15
+ self.roles_played.to_a.clone.each{ |role| role.parent.force_remove}
16
+ self.names.to_a.clone.each{ |name| name.force_remove}
17
+ self.occurrences.to_a.clone.each{ |occ| occ.force_remove}
18
+ self.types.each{ |type| self.remove_type(type) }
19
+ self.remove
20
+ end
21
+
22
+ end
23
+ end
@@ -25,7 +25,7 @@ module RTM::Sugar::Topic
25
25
  # references(params = {}) -> Array of Strings
26
26
  #
27
27
  def references(params = {})
28
- default_hash = {:outputstyle => :ctm, :resolve_qnames => :false, :resolve_base_iri => :false, :sort_by_length => :false}
28
+ default_hash = {:outputstyle => :ctm, :resolve_qnames => :false, :resolve_base_iri => :false, :sort_by_length => :true}
29
29
  params = default_hash.merge(params) if params.is_a? Hash
30
30
  prefixes = topic_map.prefixes
31
31
 
@@ -56,7 +56,7 @@ module RTM::Sugar::Topic
56
56
  end
57
57
 
58
58
  case params[:outputstyle]
59
- when :yaml
59
+ when :yaml, :jtm
60
60
  identifiers = set_of_si.map{ |si| "si:#{si}"} +
61
61
  set_of_sl.map{ |sl| "sl:#{sl}"} +
62
62
  set_of_ii.map{ |ii| "ii:#{ii}"}
@@ -95,7 +95,7 @@ module RTM::Sugar::Topic
95
95
  # reference(params = {}) -> String
96
96
  #
97
97
  def reference(params = {})
98
- return references(params).sort_by{|identifier| identifier.size}.reverse.first
98
+ return references(params).first
99
99
  end
100
100
 
101
101
  # Returns all identifiers of this Topic as Array of Locators.
@@ -116,14 +116,118 @@ module RTM::Sugar::Topic
116
116
  if topic_map.create_locator(short_form).reference == identifier
117
117
  return short_form
118
118
  end
119
- # if short_form[0] == "/"
120
- # short_form = short_form.sub("/", "")
121
- #
122
- # end
119
+ # if short_form[0] == "/"
120
+ # short_form = short_form.sub("/", "")
121
+ #
122
+ # end
123
123
  else
124
124
  return identifier #nothing happened
125
125
  end
126
126
  end
127
127
 
128
+ # Returns true if this topic has a subject identifer equal to the
129
+ # given identifier. Returns false otherwise.
130
+ #
131
+ # A relative identifier is resolved against the base_iri of the topic map.
132
+ # QNames are resolved beforehand.
133
+ #
134
+ # Identifier may be a String or Locator.
135
+ #
136
+ # :call-seq:
137
+ # has_si?(identifier) -> true or false
138
+ #
139
+ def has_si?(identifier)
140
+ identifier = topic_map.create_locator(identifier)
141
+ return subject_identifiers.include?(identifier)
142
+ end
143
+
144
+ # Returns true if this topic has an item identifer equal to the
145
+ # given identifier. Returns false otherwise.
146
+ #
147
+ # A relative identifier is resolved against the base_iri of the topic map.
148
+ # QNames are resolved beforehand.
149
+ #
150
+ # Identifier may be a String or Locator.
151
+ #
152
+ # :call-seq:
153
+ # has_ii?(identifier) -> true or false
154
+ #
155
+ def has_ii?(identifier)
156
+ identifier = topic_map.create_locator(identifier)
157
+ return item_identifiers.include?(identifier)
158
+ end
159
+
160
+ # Returns true if this topic has a subject locator equal to the
161
+ # given identifier. Returns false otherwise.
162
+ #
163
+ # A relative identifier is resolved against the base_iri of the topic map.
164
+ # QNames are resolved beforehand.
165
+ #
166
+ # Identifier may be a String or Locator.
167
+ #
168
+ # :call-seq:
169
+ # has_sl?(identifier) -> true or false
170
+ #
171
+ def has_sl?(identifier)
172
+ identifier = topic_map.create_locator(identifier)
173
+ return subject_locators.include?(identifier)
174
+ end
175
+
176
+ # Returns true if this topic is instance of another topic,
177
+ # that has a subject identifer equal to the
178
+ # given identifier. Returns false otherwise.
179
+ #
180
+ # A relative identifier is resolved against the base_iri of the topic map.
181
+ # QNames are resolved beforehand.
182
+ #
183
+ # Identifier may be a String or Locator.
184
+ #
185
+ # :call-seq:
186
+ # has_type_with_si?(identifier) -> true or false
187
+ #
188
+ def has_type_with_si?(identifier)
189
+ types.each do |type|
190
+ return true if type.has_si?(identifier)
191
+ end
192
+ return false
193
+ end
194
+
195
+ # Returns true if this topic is instance of another topic,
196
+ # that has an item identifer equal to the
197
+ # given identifier. Returns false otherwise.
198
+ #
199
+ # A relative identifier is resolved against the base_iri of the topic map.
200
+ # QNames are resolved beforehand.
201
+ #
202
+ # Identifier may be a String or Locator.
203
+ #
204
+ # :call-seq:
205
+ # has_type_with_ii?(identifier) -> true or false
206
+ #
207
+ def has_type_with_ii?(identifier)
208
+ types.each do |type|
209
+ return true if type.has_ii?(identifier)
210
+ end
211
+ return false
212
+ end
213
+
214
+ # Returns true if this topic is instance of another topic,
215
+ # that has a subject locator equal to the
216
+ # given identifier. Returns false otherwise.
217
+ #
218
+ # A relative identifier is resolved against the base_iri of the topic map.
219
+ # QNames are resolved beforehand.
220
+ #
221
+ # Identifier may be a String or Locator.
222
+ #
223
+ # :call-seq:
224
+ # has_type_with_sl?(identifier) -> true or false
225
+ #
226
+ def has_type_with_sl?(identifier)
227
+ types.each do |type|
228
+ return true if type.has_sl?(identifier)
229
+ end
230
+ return false
231
+ end
128
232
  end
129
233
  end
@@ -0,0 +1,19 @@
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 Readable
7
+
8
+ def read_only?
9
+ begin
10
+ answer = engine.feature("http://tmapi.org/features/readOnly")
11
+ rescue org.tmapi.core.FeatureNotRecognizedException
12
+ answer = false
13
+ end
14
+ return answer
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -7,28 +7,37 @@ module RTM::Sugar::TopicMap
7
7
  # Removes all variants, names, occurrences, roles, asssociations and
8
8
  # topics (esp. reifier) from this topic map.
9
9
  def clear
10
+ # This is supported by some backends (e.g. Ontopia) and should be faster than the procedure below.
11
+ if self.respond_to?(:wrapped) && self.wrapped.respond_to?(:clear)
12
+ self.wrapped.clear
13
+ return
14
+ end
15
+
16
+ raise("should not be called on majortom topic maps") if self.respond_to?(:store)
17
+
10
18
  set_reifier(nil)
11
-
19
+
12
20
  variants.to_a.each do |v|
13
21
  v.set_reifier(nil)
14
22
  v.remove
15
23
  end
16
-
24
+
17
25
  names.to_a.each do |n|
18
26
  n.set_reifier(nil)
19
27
  n.remove
20
28
  end
21
-
29
+
22
30
  occurrences.to_a.each do |o|
23
31
  o.set_reifier(nil)
24
32
  o.remove
25
33
  end
26
-
34
+
27
35
  roles.to_a.each do |r|
28
36
  r.set_reifier(nil)
29
- r.remove
37
+ # Roles should not be removed here! They are removed when the association is removed
38
+ #r.remove
30
39
  end
31
-
40
+
32
41
  associations.to_a.each do |a|
33
42
  a.set_reifier(nil)
34
43
  a.remove
@@ -0,0 +1,44 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM::Sugar::TopicMap
5
+ module Resolve
6
+
7
+ def deresolve(iri)
8
+ if iri.is_a?(RTM::Locator)
9
+ iri = iri.reference
10
+ elsif iri.is_a?(String)
11
+ iri = strip_identifier(iri)
12
+ else
13
+ raise("iri should be a String or Locator")
14
+ end
15
+ prefixes.each do |identifier, reference|
16
+ if iri.index(reference) == 0 && iri.length > reference.length
17
+ return iri.sub(reference, identifier + ":")
18
+ elsif iri.index(base_iri) == 0
19
+ _iri = iri.sub(base_iri, "")
20
+ return _iri if locator.resolve(_iri) == create_locator(iri)
21
+ end
22
+ end
23
+ return iri
24
+ end
25
+
26
+ private
27
+
28
+ def strip_identifier(identifier)
29
+ case identifier
30
+ when /^(si:|sl:|ii:|=|\^)$/
31
+ return ""
32
+ when /^(\^|ii:)\s*(.*)/ #identifiers starts with ^ or ii:
33
+ return $2
34
+ when /^(=|sl:)\s*(.+)/ #identifier starts with = or sl:
35
+ return $2
36
+ when /^(si:)\s*(.+)/ #identifier starts with si:
37
+ return $2
38
+ else #identifier does not start with a special character
39
+ return identifier.lstrip #lstrip: leading whitespace chars removed
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -17,6 +17,18 @@ module RTM::Sugar
17
17
  scoped_index.getAssociationThemes
18
18
  end
19
19
 
20
+ # Returns all topics in the topic map used
21
+ # in the scope property of Associations sorted by their best names.
22
+ #
23
+ # The result may be empty.
24
+ #
25
+ # :call-seq:
26
+ # association_themes -> Array of Topics sorted by their best_name
27
+ #
28
+ def association_themes_sorted(by_what = :best_name)
29
+ scoped_index.getAssociationThemes.sort_by(&by_what)
30
+ end
31
+
20
32
  # Returns all topics in the topic map used
21
33
  # in the scope property of Names.
22
34
  #
@@ -27,6 +39,16 @@ module RTM::Sugar
27
39
  scoped_index.getNameThemes
28
40
  end
29
41
 
42
+ # Returns all topics in the topic map used
43
+ # in the scope property of Names sorted by their best names.
44
+ #
45
+ # :call-seq:
46
+ # name_themes -> Array of Topics sorted by their best_name
47
+ #
48
+ def name_themes_sorted(by_what = :best_name)
49
+ scoped_index.getNameThemes.sort_by(&by_what)
50
+ end
51
+
30
52
  # Returns all topics in the topic map used
31
53
  # in the scope property of Occurrences.
32
54
  #
@@ -37,6 +59,16 @@ module RTM::Sugar
37
59
  scoped_index.getOccurrenceThemes
38
60
  end
39
61
 
62
+ # Returns all topics in the topic map used
63
+ # in the scope property of Occurrences sorted by their best names.
64
+ #
65
+ # :call-seq:
66
+ # occurrence_themes -> Array of Topics sorted by their best_name
67
+ #
68
+ def occurrence_themes_sorted(by_what = :best_name)
69
+ scoped_index.getOccurrenceThemes.sort_by(&by_what)
70
+ end
71
+
40
72
  # Returns all topics in the topic map used
41
73
  # in the scope property of Variants.
42
74
  #
@@ -47,6 +79,16 @@ module RTM::Sugar
47
79
  scoped_index.getVariantThemes
48
80
  end
49
81
 
82
+ # Returns all topics in the topic map used
83
+ # in the scope property of Variants sorted by their best names.
84
+ #
85
+ # :call-seq:
86
+ # variant_themes -> Array of Topics sorted by their best_name
87
+ #
88
+ def variant_themes_sorted(by_what = :best_name)
89
+ scoped_index.getVariantThemes.sort_by(&by_what)
90
+ end
91
+
50
92
  end
51
93
  end
52
94
  end
@@ -15,6 +15,16 @@ module RTM::Sugar
15
15
  type_instance_index.getAssociationTypes
16
16
  end
17
17
 
18
+ # Returns all topics in this topic map that are used
19
+ # as types of associations sorted by their best names.
20
+ #
21
+ # :call-seq:
22
+ # association_types -> Array of Topics sorted by their best names
23
+ #
24
+ def association_types_sorted(by_what = :best_name)
25
+ type_instance_index.getAssociationTypes.sort_by(&by_what)
26
+ end
27
+
18
28
  # Returns the all Topics in this TopicMap that are used
19
29
  # as types of Roles.
20
30
  #
@@ -25,6 +35,16 @@ module RTM::Sugar
25
35
  type_instance_index.getRoleTypes
26
36
  end
27
37
 
38
+ # Returns the all Topics in this TopicMap that are used
39
+ # as types of Roles sorted by their best names.
40
+ #
41
+ # :call-seq:
42
+ # role_types -> Array of Topics sorted by their best names
43
+ #
44
+ def role_types_sorted(by_what = :best_name)
45
+ type_instance_index.getRoleTypes.sort_by(&by_what)
46
+ end
47
+
28
48
  # Returns all Topics in this TopicMap that are used
29
49
  # as types of Names.
30
50
  #
@@ -35,6 +55,16 @@ module RTM::Sugar
35
55
  type_instance_index.getNameTypes
36
56
  end
37
57
 
58
+ # Returns all Topics in this TopicMap that are used
59
+ # as types of Names sorted by their best names.
60
+ #
61
+ # :call-seq:
62
+ # name_types -> Array of Topics sorted by their best names
63
+ #
64
+ def name_types_sorted(by_what = :best_name)
65
+ type_instance_index.getNameTypes.sort_by(&by_what)
66
+ end
67
+
38
68
  # Returns all Topics in this TopicMap that are used
39
69
  # as types of Occurrences.
40
70
  #
@@ -45,6 +75,22 @@ module RTM::Sugar
45
75
  type_instance_index.getOccurrenceTypes
46
76
  end
47
77
 
78
+ # Returns all Topics in this TopicMap that are used
79
+ # as types of Occurrences sorted by their best names.
80
+ #
81
+ # :call-seq:
82
+ # occurrence_types -> Array of Topics sorted by their best names
83
+ #
84
+ def occurrence_types_sorted(by_what = :best_name)
85
+ type_instance_index.getOccurrenceTypes.sort_by(&by_what)
86
+ end
87
+
88
+ # Returns all Topics that are no type of any kind
89
+ def individuals
90
+ all_types = types.to_a + association_types.to_a + role_types.to_a + name_types.to_a + occurrence_types.to_a
91
+ topics.to_a - all_types
92
+ end
93
+
48
94
  end
49
95
  end
50
96
  end
@@ -0,0 +1,15 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM::Sugar::Variant
5
+ module Remove
6
+
7
+ def force_remove
8
+ if variant_reifier = self.reifier
9
+ self.reifier = nil
10
+ variant_reifier.force_remove
11
+ end
12
+ remove
13
+ end
14
+ end
15
+ end
@@ -23,10 +23,9 @@ module RTM # :nodoc:
23
23
 
24
24
  MAJOR = 0
25
25
  MINOR = 3
26
- TINY = 0
26
+ TINY = 1
27
27
  BUILD = ENV['BUILD_NUMBER'] || COMPACTDATE
28
28
 
29
- #STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
30
29
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
31
30
 
32
31
  SUMMARY = "rtm #{STRING}"