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
data/DISCLAIMER CHANGED
@@ -1,3 +1,5 @@
1
+ Copyright 2006-2008 Benjamin Bock
2
+
1
3
  Copyright 2008-2010 Topic Maps Lab, University of Leipzig.
2
4
 
3
5
  Licensed under the Apache License, Version 2.0 (the "License");
@@ -10,4 +12,4 @@ Unless required by applicable law or agreed to in writing, software
10
12
  distributed under the License is distributed on an "AS IS" BASIS,
11
13
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
14
  See the License for the specific language governing permissions and limitations
13
- under the License.
15
+ under the License.
data/README CHANGED
File without changes
data/lib/rtm.rb CHANGED
@@ -37,7 +37,6 @@ module RTM
37
37
  module Reifiable; end
38
38
 
39
39
  module TopicMap
40
- attr_accessor :engine
41
40
  end
42
41
 
43
42
  module TopicMapSystem; end
@@ -164,9 +164,6 @@ module RTM::Axes
164
164
  _res = @construct.transitive_subtypes_with_self.map{|r| r.axes}
165
165
  _res.extend(Topics)
166
166
  end
167
-
168
- alias reverse_subtypes supertypes
169
- alias reverse_supertypes subtypes
170
167
 
171
168
  # ---- traverse-axis ---------------------------------------------------#
172
169
 
@@ -196,9 +196,6 @@ module RTM::Axes
196
196
  _res = _res.extend(Topics)
197
197
  _res
198
198
  end
199
-
200
- alias reverse_subtypes supertypes
201
- alias reverse_supertypes subtypes
202
199
 
203
200
  # ---- traverse-axis ---------------------------------------------------#
204
201
 
@@ -30,17 +30,17 @@ module RTM
30
30
  connection
31
31
  end
32
32
 
33
- # Return all connections or a particular connection.
33
+ # Returns all connections or a particular connection.
34
34
  # @overload connections
35
35
  # Returns all registered connections, keyed by their identifiers.
36
36
  # @return [Hash]
37
37
  # @overload connections(identifier)
38
38
  # @param [Symbol] identifier of the registered connection
39
39
  # @return [Engine] the connection object
40
- def connections(*args)
40
+ def connections(key=nil)
41
41
  @connections ||= {}
42
- if args.size > 0
43
- @connections[*args]
42
+ if key
43
+ @connections[key]
44
44
  else
45
45
  @connections
46
46
  end
@@ -49,19 +49,20 @@ module RTM
49
49
  require "rtm/#{engine_gem_name}"
50
50
  self[engine_name]
51
51
  end
52
-
52
+
53
+ # Changed 2010-07-29: engine_name now symbols, cause, list elements are also symbol
53
54
  def self.load!(engine_name=nil)
54
55
  engine_name = self.detect unless engine_name
55
- unless list.include?(engine_name)
56
+ unless list.include?(engine_name.to_sym)
56
57
  warn("Requested engine '#{engine_name}' not loaded. Trying to autoload it.")
57
- engine = load(engine_name)
58
- if list.include?(engine_name)
58
+ engine = load(engine_name.to_sym)
59
+ if list.include?(engine_name.to_sym)
59
60
  warn("Autoloading '#{engine_name}' was successful")
60
61
  else
61
62
  raise "Autoloading '#{engine_name}' failed. Make sure rtm-#{engine_name} exists and is installed or require it manually."
62
63
  end
63
64
  end
64
- engine || load(engine_name)
65
+ engine || load(engine_name.to_sym)
65
66
  end
66
67
 
67
68
  def self.detect(preferred=nil)
@@ -45,7 +45,7 @@ module RTM
45
45
  end
46
46
 
47
47
  # A standard Ruby hook to be notified about inclusions of this module.
48
- # This normally eliminates the need to register a module as implementa
48
+ # This normally eliminates the need to register a module as implementation
49
49
  def included(klass)
50
50
  # super
51
51
  # puts "[RTMEXT] including #{self} into #{klass} in #{caller(1).first}"
@@ -3,7 +3,7 @@
3
3
 
4
4
  # Executes the given block while suppressing all standard output.
5
5
  def no_output
6
- $stdout = File.open( PLATFORM =~ /mswin/ ? "NUL" : "/dev/null", "w" )
6
+ $stdout = File.open( PLATFORM =~ /mswin|mingw/ ? "NUL" : "/dev/null", "w" )
7
7
  yield if block_given?
8
8
  $stdout.close
9
9
  $stdout = STDOUT
@@ -22,7 +22,7 @@ module RTM::IO
22
22
  def self.from_xtm2(source, base_locator, target=nil,options={})
23
23
  tm = RTM.create(base_locator) unless target
24
24
  parser = XML::SaxParser.new
25
- parser.callbacks = XML::LibXMLSax2wrapper.new(FROMXTM2::XTM2Listener.new(base_locator, target || tm, options))
25
+ parser.callbacks = RTM::XML::LibXMLSax2wrapper.new(FROMXTM2::XTM2Listener.new(base_locator, target || tm, options))
26
26
  parser.filename = source
27
27
  parser.parse
28
28
  #true
@@ -30,7 +30,7 @@ module RTM::IO
30
30
  end
31
31
  end
32
32
 
33
- module XML
33
+ module RTM::XML
34
34
  # Acts as Callback structure for the LibXML-Ruby SAX Parser and calls
35
35
  # a REXML SAX2Listener API.
36
36
  class LibXMLSax2wrapper
@@ -38,7 +38,12 @@ module RTM::IO
38
38
  topic_map = create(base_iri)
39
39
  end
40
40
 
41
- reader_class.new(topic_map, java.io.File.new(source)).read
41
+ # TODO catch java.io.FileNotFoundException
42
+ reader = reader_class.new(topic_map, java.io.File.new(source), base_iri)
43
+ if reader_class == Java::OrgTmapixIo::LTMTopicMapReader
44
+ reader.setLegacyMode(true)
45
+ end
46
+ reader.read
42
47
  topic_map
43
48
  end
44
49
 
@@ -69,7 +74,6 @@ module RTM::IO
69
74
  # from_jtm(filename)
70
75
  #
71
76
  def from_jtm(*args)
72
- # seems not to acceped all files that are found to be valid by the JTM validator
73
77
  from_anything(Java::OrgTmapixIo::JTMTopicMapReader, *args)
74
78
  end
75
79
 
@@ -84,28 +88,6 @@ module RTM::IO
84
88
  from_anything(Java::OrgTmapixIo::TMXMLTopicMapReader, *args)
85
89
  end
86
90
 
87
- # Reads a XML Topic Maps (XTM) 1.0 File
88
- # whose location is given as String parameter.
89
- #
90
- # :call-seq:
91
- # from_xtm10(filename)
92
- #
93
- def from_xtm10(*args)
94
- from_anything(Java::OrgTmapixIo::XTM10TopicMapReader, *args)
95
- end
96
- alias :from_xtm1 :from_xtm10
97
-
98
- # Reads a XML Topic Maps (XTM) 2.0 File
99
- # whose location is given as String parameter.
100
- #
101
- # :call-seq:
102
- # from_xtm20(filename)
103
- #
104
- def from_xtm20(*args)
105
- from_xtm(*args)
106
- end
107
- alias :from_xtm2 :from_xtm20
108
-
109
91
  # Reads a XML Topic Maps (XTM) File
110
92
  # independent of the version
111
93
  # whose location is given as String parameter.
@@ -116,6 +98,11 @@ module RTM::IO
116
98
  def from_xtm(*args)
117
99
  from_anything(Java::OrgTmapixIo::XTMTopicMapReader, *args)
118
100
  end
101
+ alias :from_xtm21 :from_xtm
102
+ alias :from_xtm20 :from_xtm
103
+ alias :from_xtm2 :from_xtm
104
+ alias :from_xtm10 :from_xtm
105
+ alias :from_xtm1 :from_xtm
119
106
 
120
107
  # Reads a Notation3 (N3) File
121
108
  # whose location is given as String .
@@ -50,6 +50,8 @@ module RTM::IO
50
50
  # Use the topic maps's base_iri if neither found.
51
51
  base_iri = args.shift || params[:base_iri] || self.base_iri
52
52
 
53
+ xtm_version = params[:xtm_version]
54
+
53
55
  # If a file was provided somehow, we wrap it with output streams
54
56
  if file
55
57
  if file.is_a?(java.io.OutputStream)
@@ -63,11 +65,16 @@ module RTM::IO
63
65
  end
64
66
 
65
67
  # create the java writer
66
- writer = writer_class.new(out_stream, base_iri)
68
+ if xtm_version
69
+ writer = writer_class.new(out_stream, base_iri, xtm_version)
70
+ else
71
+ writer = writer_class.new(out_stream, base_iri)
72
+ end
73
+
67
74
  # set params
68
75
  params.each do |k,v|
69
76
  # skip our params, as they're not of interest for the writer
70
- next if k == :file || k == :base_iri
77
+ next if [:file, :base_iri, :xtm_version].include?(k)
71
78
  writer.setProperty(k.to_s,v.to_s)
72
79
  end if writer.respond_to?(:setProperty)
73
80
  # do the actual work
@@ -83,6 +90,29 @@ module RTM::IO
83
90
  end
84
91
 
85
92
  public
93
+
94
+ # Serializes an RTM::TopicMap to XTM v. 2.1.
95
+ #
96
+ # If no file argument is given, a String is returned.
97
+ #
98
+ # The argument file can be provided as a String
99
+ # (which is then interpreted as a filename) or as a java.io.OutputStream.
100
+ #
101
+ # The argument base_iri may be used to define a new base_iri, if not, the current
102
+ # one is used. Base_iri may be a String.
103
+ #
104
+ # :call-seq:
105
+ # to_xtm21
106
+ # to_xtm21(file)
107
+ # to_xtm21(file, base_iri)
108
+ #
109
+ def to_xtm21(*args)
110
+ args.push({}) unless args.last.is_a?(Hash)
111
+ args.last[:xtm_version] = Java::OrgTmapixIo::XTMVersion::XTM_2_1
112
+ to_anything(Java::OrgTmapixIo::XTM2TopicMapWriter, *args)
113
+ end
114
+ alias :to_xtm :to_xtm21
115
+
86
116
  # Serializes an RTM::TopicMap to XTM v. 2.0.
87
117
  #
88
118
  # If no argument is given, a String is returned.
@@ -94,14 +124,15 @@ module RTM::IO
94
124
  # one is used. Base_iri may be a String.
95
125
  #
96
126
  # :call-seq:
97
- # to_xtm20
98
- # to_xtm20(file)
99
- # to_xtm20(file, base_iri)
127
+ # to_xtm21
128
+ # to_xtm21(file)
129
+ # to_xtm21(file, base_iri)
100
130
  #
101
131
  def to_xtm20(*args)
102
- to_anything(Java::OrgTmapixIo::XTM20TopicMapWriter, *args)
132
+ args.push({}) unless args.last.is_a?(Hash)
133
+ args.last[:xtm_version] = Java::OrgTmapixIo::XTMVersion::XTM_2_0
134
+ to_anything(Java::OrgTmapixIo::XTM2TopicMapWriter, *args)
103
135
  end
104
- alias :to_xtm :to_xtm20
105
136
  alias :to_xtm2 :to_xtm20
106
137
 
107
138
  # Serializes an RTM::TopicMap to XTM v. 1.0.
@@ -17,15 +17,13 @@ module RTM
17
17
  # characteristics -> Array of Names and Occurrences
18
18
  # characteristics(identifier) -> Array of Names and Occurrences
19
19
  #
20
- def characteristics(type=:any)
21
- # FIXME which version of the code?
22
- return names.to_a + occurrences.to_a if type == :any
23
- _topic = topic_map.get(type)
24
- return [] unless _topic
25
- #names.select{|n| n.type.include?(_topic) || n.type.supertypes.include?(_topic)}.to_a +
26
- #occurrences.select{|o| o.type.include?(_topic) || o.type.supertypes.include?(_topic)}.to_a
27
- names.select{|n| n.type.supertypes.include?(_topic)}.to_a +
28
- occurrences.select{|o| o.type.supertypes.include?(_topic)}.to_a
20
+ def characteristics(type = :any)
21
+ _characteristics = names.to_a + occurrences.to_a
22
+ return _characteristics if type == :any
23
+ _type = topic_map.get(type)
24
+ return [] unless _type
25
+ #_characteristics.select{|c| c.type == _topic}
26
+ _characteristics.select{|c| c.type.supertypes.include?(_type)}
29
27
  end
30
28
 
31
29
  end
@@ -4,7 +4,7 @@
4
4
  module RTM
5
5
  module Navigation
6
6
  module Topic
7
-
7
+
8
8
  # Returns all Topic players that exist in binary supertype-subtype Associations
9
9
  # where this Topic playes the subtype-Role.
10
10
  #
@@ -32,7 +32,6 @@ module RTM
32
32
  asso = topic_map.create_association(RTM::PSI[:supertype_subtype])
33
33
  asso.create_role(RTM::PSI[:subtype],self)
34
34
  asso.create_role(RTM::PSI[:supertype],new_supertype)
35
- asso
36
35
  end
37
36
 
38
37
  # Creates one or several binary supertype-subtype-Associations where
@@ -108,7 +107,6 @@ module RTM
108
107
  asso = topic_map.create_association(RTM::PSI[:supertype_subtype])
109
108
  asso.create_role(RTM::PSI[:supertype],self)
110
109
  asso.create_role(RTM::PSI[:subtype],new_subtype)
111
- asso
112
110
  end
113
111
 
114
112
  # Creates one or several binary supertype-subtype-Associations where
@@ -158,8 +156,6 @@ module RTM
158
156
 
159
157
  alias :supertypes :transitive_supertypes
160
158
  alias :subtypes :transitive_subtypes
161
- alias :reverse_subtypes :supertypes
162
- alias :reverse_supertypes :subtypes
163
159
 
164
160
  end
165
161
  end
@@ -10,6 +10,7 @@ require 'rtm/sugar/topic/counterparts'
10
10
  require 'rtm/sugar/topic/scoped'
11
11
  require 'rtm/sugar/topic/typed'
12
12
  require 'rtm/sugar/topic/best_name'
13
+ require 'rtm/sugar/topic/remove'
13
14
  RTM::Topic.register_extension(RTM::Sugar::Topic::TopicRef)
14
15
  RTM::Topic.register_extension(RTM::Sugar::Topic::HashAccess)
15
16
  RTM::Topic.register_extension(RTM::Sugar::Topic::Characteristics)
@@ -17,9 +18,15 @@ RTM::Topic.register_extension(RTM::Sugar::Topic::Counterparts)
17
18
  RTM::Topic.register_extension(RTM::Sugar::Topic::Scoped)
18
19
  RTM::Topic.register_extension(RTM::Sugar::Topic::Typed)
19
20
  RTM::Topic.register_extension(RTM::Sugar::Topic::BestName)
21
+ RTM::Topic.register_extension(RTM::Sugar::Topic::Remove)
20
22
 
21
23
  require "rtm/sugar/association/hash_access"
24
+ require "rtm/sugar/association/remove"
22
25
  RTM::Association.register_extension(RTM::Sugar::Association::HashAccess)
26
+ RTM::Association.register_extension(RTM::Sugar::Association::Remove)
27
+
28
+ require "rtm/sugar/name/remove"
29
+ RTM::Name.register_extension(RTM::Sugar::Name::Remove)
23
30
 
24
31
  require "rtm/sugar/role/counterparts"
25
32
  RTM::Role.register_extension(RTM::Sugar::Role::Counterparts)
@@ -27,8 +34,10 @@ RTM::Role.register_extension(RTM::Sugar::Role::Counterparts)
27
34
  require "time"
28
35
  require "rtm/sugar/occurrence/dynamic_value"
29
36
  require "rtm/sugar/occurrence/external"
37
+ require "rtm/sugar/occurrence/remove"
30
38
  RTM::Occurrence.register_extension(RTM::Sugar::Occurrence::DynamicValue)
31
39
  RTM::Occurrence.register_extension(RTM::Sugar::Occurrence::External)
40
+ RTM::Occurrence.register_extension(RTM::Sugar::Occurrence::Remove)
32
41
 
33
42
  require "rtm/sugar/typed/types"
34
43
  RTM::Typed.register_extension(RTM::Sugar::Typed::Types)
@@ -40,6 +49,8 @@ require 'rtm/sugar/topic_map/query_cache'
40
49
  require 'rtm/sugar/topic_map/scoped'
41
50
  require 'rtm/sugar/topic_map/types'
42
51
  require 'rtm/sugar/topic_map/remove'
52
+ require 'rtm/sugar/topic_map/resolve'
53
+ require 'rtm/sugar/topic_map/readable'
43
54
  module RTM::TopicMap
44
55
  @query_cache = nil #disables query caching
45
56
  end
@@ -47,6 +58,10 @@ RTM::TopicMap.register_extension(RTM::Sugar::TopicMap::QueryCache)
47
58
  RTM::TopicMap.register_extension(RTM::Sugar::TopicMap::Scoped)
48
59
  RTM::TopicMap.register_extension(RTM::Sugar::TopicMap::Types)
49
60
  RTM::TopicMap.register_extension(RTM::Sugar::TopicMap::Remove)
61
+ RTM::TopicMap.register_extension(RTM::Sugar::TopicMap::Resolve)
62
+ RTM::TopicMap.register_extension(RTM::Sugar::TopicMap::Readable)
50
63
 
51
64
  require "rtm/sugar/variant/topic"
52
- RTM::Variant.register_extension(RTM::Sugar::Variant::Topic)
65
+ require "rtm/sugar/variant/remove"
66
+ RTM::Variant.register_extension(RTM::Sugar::Variant::Topic)
67
+ RTM::Variant.register_extension(RTM::Sugar::Variant::Remove)
@@ -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::Association
5
+ module Remove
6
+
7
+ def force_remove
8
+ if assoc_reifier = self.reifier
9
+ self.reifier = nil
10
+ assoc_reifier.force_remove
11
+ end
12
+ self.roles.to_a.clone.each do |role|
13
+ if role_reifier = role.reifier
14
+ role.reifier = nil
15
+ role_reifier.force_remove
16
+ end
17
+ end
18
+ remove
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM::Sugar::Name
5
+ module Remove
6
+
7
+ def force_remove
8
+ if name_reifier = self.reifier
9
+ self.reifier = nil
10
+ name_reifier.force_remove
11
+ end
12
+ self.variants.to_a.clone.each do |v|
13
+ v.force_remove
14
+ end
15
+ remove
16
+ end
17
+ end
18
+ end
@@ -40,6 +40,7 @@ module RTM::Sugar::Occurrence
40
40
  #
41
41
  def externalize!(*args)
42
42
  association = externalize(*args)
43
+ self.reifier = nil
43
44
  remove
44
45
  return association
45
46
  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::Occurrence
5
+ module Remove
6
+
7
+ def force_remove
8
+ if occ_reifier = self.reifier
9
+ self.reifier = nil
10
+ occ_reifier.force_remove
11
+ end
12
+ remove
13
+ end
14
+ end
15
+ end