rtm 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/README +1 -1
  2. data/lib/rtm.rb +23 -95
  3. data/lib/rtm/connection.rb +51 -0
  4. data/lib/rtm/engine.rb +29 -18
  5. data/lib/rtm/extensions.rb +2 -5
  6. data/lib/rtm/helpers/uri.rb +1 -1
  7. data/lib/rtm/io/tmapix_from.rb +8 -8
  8. data/lib/rtm/io/tmapix_to.rb +6 -6
  9. data/lib/rtm/io/to_rdf.rb +1 -1
  10. data/lib/rtm/io/to_string.rb +22 -14
  11. data/lib/rtm/navigation/topic/supertypes.rb +2 -2
  12. data/lib/rtm/navigation/topic/types.rb +1 -1
  13. data/lib/rtm/psi.rb +3 -1
  14. data/lib/rtm/sugar.rb +8 -3
  15. data/lib/rtm/sugar/topic/best_name.rb +31 -50
  16. data/lib/rtm/sugar/topic/scoped.rb +9 -9
  17. data/lib/rtm/sugar/topic/topic_ref.rb +115 -72
  18. data/lib/rtm/sugar/topic_map/remove.rb +49 -0
  19. data/lib/rtm/sugar/topic_map/{themes.rb → scoped.rb} +9 -10
  20. data/lib/rtm/sugar/topic_map/types.rb +50 -0
  21. data/lib/rtm/sugar/variant/topic.rb +17 -0
  22. data/lib/rtm/topology.rb +134 -0
  23. data/lib/rtm/version.rb +13 -8
  24. data/spec/rtm/engine_spec.rb +45 -0
  25. data/spec/rtm/io/tmapix_from_spec.rb +8 -8
  26. data/spec/rtm/io/tmapix_to_spec.rb +38 -38
  27. data/spec/rtm/io/to_yaml_spec.rb +7 -0
  28. data/spec/rtm/javatmapi_spec.rb +64 -0
  29. data/spec/rtm/navigation/topic/scope_spec.rb +1 -1
  30. data/spec/rtm/sugar/topic/best_name_spec.rb +54 -2
  31. data/spec/rtm/sugar/topic/topic_ref_spec.rb +59 -35
  32. data/spec/rtm/sugar/topic_map/remove_spec.rb +50 -0
  33. data/spec/rtm/sugar/topic_map/{themes_spec.rb → scoped_spec.rb} +1 -1
  34. data/spec/rtm/sugar/topic_map/types_spec.rb +34 -0
  35. data/spec/rtm/sugar/variant/topic_spec.rb +28 -0
  36. data/spec/rtm/tmapi/core/name_spec.rb +1 -7
  37. data/spec/rtm/tmapi/core/topic_map_spec.rb +103 -51
  38. data/spec/rtm/tmapi/core/topic_spec.rb +3 -0
  39. data/spec/rtm_spec.rb +3 -12
  40. data/test/javalibs/tmapi-2.0-tests.jar +0 -0
  41. metadata +26 -9
data/README CHANGED
@@ -34,6 +34,6 @@ The Topic Maps Data Model which is used in this implementation can be found on h
34
34
  * rtm-tmql: Adds support for the Topic Maps Query Language (TMQL), http://isotopicmaps.org/tmql/
35
35
  * rtm-tmcl: Adds support for the Topic Maps Constraint Language (TMCL), http://isotopicmaps.org/tmcl/
36
36
 
37
- ==== License
37
+ ==== License
38
38
  Copyright 2009 Topic Maps Lab, University of Leipzig.
39
39
  Apache License, Version 2.0
data/lib/rtm.rb CHANGED
@@ -12,123 +12,51 @@
12
12
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
13
13
 
14
14
  module RTM
15
- module Topic
16
- end
15
+ module Topic; end
17
16
 
18
- module Association
19
- end
17
+ module Association; end
20
18
 
21
- module Occurrence
22
- end
19
+ module Occurrence; end
23
20
 
24
- module Reifiable
25
- end
21
+ module Reifiable; end
26
22
 
27
- module Name
28
- end
23
+ module Name; end
29
24
 
30
- module Role
31
- end
25
+ module Role; end
32
26
 
33
- module Scoped
34
- end
27
+ module Scoped; end
35
28
 
36
- module Typed
37
- end
29
+ module Typed; end
38
30
 
39
- module Variant
40
- end
31
+ module Variant; end
41
32
 
42
- module Locator
43
- end
33
+ module Locator; end
44
34
 
45
- module Construct
46
- end
35
+ module Construct; end
47
36
 
48
- module Reifiable
49
- end
37
+ module Reifiable; end
50
38
 
51
39
  module TopicMap
52
40
  attr_accessor :engine
53
41
  end
54
42
 
55
- module TopicMapSystem
56
- end
43
+ module TopicMapSystem; end
57
44
 
58
- module ItemIdentifier
59
- end
45
+ module ItemIdentifier; end
60
46
 
61
- module SubjectIdentifier
62
- end
47
+ module SubjectIdentifier; end
63
48
 
64
- module SubjectLocator
65
- end
49
+ module SubjectLocator; end
66
50
 
67
- module DatatypeAware
68
- end
51
+ module DatatypeAware; end
69
52
  end
70
53
 
71
54
  require 'rtm/version'
72
55
  require 'rtm/extensions'
73
- require "rtm/engine"
56
+ require 'rtm/engine'
57
+ require 'rtm/connection'
74
58
  require 'rtm/psi'
75
- require "rtm/navigation"
76
- require "rtm/axes"
77
- require "rtm/sugar"
78
- require "rtm/io"
79
-
80
- module RTM
81
- # Connects to a topic map engine.
82
- # The optional parameter can be used to
83
- # select the backend.
84
- #
85
- # :call-seq:
86
- # RTM.connect(:implementation => :ontopia) -> Ontopia backend
87
- # RTM.connect(:implementation => :tinytim) -> tinyTim backend
88
- # RTM.connect(:implementation => :activerecord) -> Active Record backend
89
- # RTM.connect(:implementation => :sesametm) -> SesameTM backend
90
- # RTM.connect(:implementation => :merged) -> Merged TMAPI backend
91
- #
92
- def self.connect(params = {}, *args)
93
- engine = Engine.load!(params[:implementation])
94
- connection = engine.new(params)
95
- add_connection(connection)
96
- connection
97
- end
98
-
99
- # Returns all connections grouped by their backend
100
- #
101
- # :call-seq:
102
- # connections -> Hash
103
- #
104
- def self.connections
105
- @connections ||= Hash.new{|h,k| h[k] = []}
106
- @connections
107
- end
108
-
109
- # Returns all connections. The optional argument may specify the backend
110
- # the connections should use.
111
- #
112
- # :call-seq:
113
- # [] -> all connections as Hash
114
- # [:tinytim] -> all connections using TinyTiM
115
- # [:ontopia] -> all connections using Ontopia
116
- # [:sesame] -> all connections using SesameTM
117
- # [:activerecord] -> all connectioms using RTM AR
118
- #
119
- def self.[](args = nil)
120
- return @connections[args] if args
121
- connections
122
- end
123
-
124
- def self.included(klass)
125
- @@meine_implementierungen ||= []
126
- @@meine_implementierungen << klass
127
- self.included_modules.each {|im| klass.extend(im)}
128
- end
129
-
130
- private
131
- def self.add_connection(connection)
132
- self.connections[connection.class.identifier] << connection
133
- end
134
- end
59
+ require 'rtm/navigation'
60
+ require 'rtm/axes'
61
+ require 'rtm/sugar'
62
+ require 'rtm/io'
@@ -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 Connections
6
+ # Connects to a topic map engine using the specificed backend and configuration
7
+ #
8
+ # @example Connect to Ontopia backend (in memory)
9
+ # RTM.connect(:backend => :ontopia)
10
+ # @example Connect to Ontopia backend (relational database), here: using the H2 adapter
11
+ # RTM.connect(:backend => :ontopia_rdbms, :config => { :adapter => 'jdbch2', :database => "db-rtm-ontopia"})
12
+ # @example Connect to tinyTim backend (in memory)
13
+ # RTM.connect(:backend => :tinytim)
14
+ # @example Connect to Active Record backend (relational database)
15
+ # RTM.connect(:backend => :activerecord)
16
+ # @example Connect to SesameTM backend
17
+ # RTM.connect(:backend => :sesametm)
18
+ # @example Connect to Hatana backend (in memory, with different stores)
19
+ # RTM.connect(:backend => :hatana)
20
+ # @param [Hash] params the options to create the connection with.
21
+ # @option params [Symbol] :backend (:ontopia) the backend
22
+ # @option params [Symbol] :implementation @deprecated use :backend instead
23
+ # @option params [Hash] :config (nil) the backend-specific configuration
24
+ # @return [Engine] The connection object
25
+ def connect(params = {}, *args)
26
+ params ||= {} # this is needed to handle passing nil
27
+ engine = Engine.load!(params[:backend] || params[:implementation])
28
+ connection = engine.connect(params)
29
+ connections[params[:identifier]] = connection if params[:identifier]
30
+ connection
31
+ end
32
+
33
+ # Return all connections or a particular connection.
34
+ # @overload connections
35
+ # Returns all registered connections, keyed by their identifiers.
36
+ # @return [Hash]
37
+ # @overload connections(identifier)
38
+ # @param [Symbol] identifier of the registered connection
39
+ # @return [Engine] the connection object
40
+ def connections(*args)
41
+ @connections ||= {}
42
+ if args.size > 0
43
+ @connections[*args]
44
+ else
45
+ @connections
46
+ end
47
+ end
48
+
49
+ RTM.extend(self)
50
+ end
51
+ end
@@ -9,12 +9,12 @@ module RTM
9
9
  def self.inherited(subclass)
10
10
  Engine.add(subclass) # this MUST be Engine and not self! Otherwise every intermediate class in the inheritance chain will have it's own list
11
11
  end
12
-
12
+
13
13
  def self.add(engine)
14
14
  @engines ||= []
15
15
  @engines << engine
16
16
  end
17
-
17
+
18
18
  def self.identifier(i=nil)
19
19
  if i
20
20
  # setter / declaration
@@ -24,31 +24,29 @@ module RTM
24
24
  @identifier
25
25
  end
26
26
  end
27
-
27
+
28
28
  def self.all
29
29
  @engines ||= []
30
30
  @engines.reject!{|e| e.abstract?} # this needs to be done here because in the inherited hook the method is not yet available.
31
31
  @engines
32
32
  end
33
-
33
+
34
34
  def self.list
35
35
  all.map{|e| e.identifier}
36
36
  end
37
-
37
+
38
38
  def self.[](identifier)
39
39
  all.find {|e| e.identifier == identifier}
40
40
  end
41
-
41
+
42
42
  def self.load(engine_name)
43
- if Object.const_defined?("Gem") && rtmgem = Gem.loaded_specs["rtm"]
44
- require "rtm/#{engine_name}"
45
- else
46
- engine_path = File.expand_path(File.join(File.dirname(__FILE__), "../../../rtm-#{engine_name}/lib"))
47
- if File.directory?(engine_path)
48
- $LOAD_PATH.unshift engine_path
49
- require "rtm/#{engine_name}"
50
- end
43
+ engine_gem_name = engine_name
44
+ engine_gem_name = engine_name.to_s.split("_").first if engine_gem_name.to_s =~ /_/
45
+ unless Object.const_defined?("Gem") && rtmgem = Gem.loaded_specs["rtm"]
46
+ engine_path = File.expand_path(File.join(File.dirname(__FILE__), "../../../rtm-#{engine_gem_name}/lib"))
47
+ $LOAD_PATH.unshift engine_path if File.directory?(engine_path)
51
48
  end
49
+ require "rtm/#{engine_gem_name}"
52
50
  self[engine_name]
53
51
  end
54
52
 
@@ -65,13 +63,11 @@ module RTM
65
63
  end
66
64
  engine || load(engine_name)
67
65
  end
68
-
66
+
69
67
  def self.detect(preferred=nil)
70
68
  if preferred # return the users preference, if given
71
69
  implementation = preferred
72
- elsif engine_name = ENV['RTM_IMPLEMENTATION'] # inspect system environment
73
- implementation = engine_name.to_sym
74
- elsif engine_name = ENV['RTM_ENGINE'] # inspect system environment (alternative)
70
+ elsif engine_name = ENV['RTM_BACKEND'] || ENV['RTM_IMPLEMENTATION'] || ENV['RTM_ENGINE'] # inspect system environment (several alternatives)
75
71
  implementation = engine_name.to_sym
76
72
  elsif implementation = self.list.first # check if one is already loaded
77
73
  warn("No engine implementation was specified for RTM.connect. Using the first already loaded engine (#{implementation.inspect}).")
@@ -91,11 +87,26 @@ module RTM
91
87
  end
92
88
  end
93
89
 
90
+ def self.connect(*args)
91
+ self.new(*args)
92
+ end
93
+
94
94
  attr_reader :connections
95
95
 
96
96
  def initialize(params={})
97
97
  @params = params
98
98
  end
99
99
 
100
+ # returns an identifier of the engine, e.g. :ontopia or :ontopia_rdbms
101
+ def identifier
102
+ self.class.identifier
103
+ end
104
+
105
+ # Check if everything is set up. This should be overwritten by backends
106
+ # which need special setup, like a database schema migration.
107
+ def check
108
+ true
109
+ end
110
+
100
111
  end
101
112
  end
@@ -50,13 +50,11 @@ module RTM
50
50
  # super
51
51
  # puts "[RTMEXT] including #{self} into #{klass} in #{caller(1).first}"
52
52
  register_implementation(klass)
53
- klass.class_eval do
53
+ klass.class_eval <<-EOS
54
54
  def self.included(klass2)
55
- # puts "[RTMIMPLEXT] #{self} was included into #{klass2} in #{caller(1).first}"
56
- # self.ancestors.select {|anc| anc.respond_to?(:register_implementation)}.each{|anc| anc.register_implementation(klass2) }
57
55
  self.ancestors.find {|anc| anc.respond_to?(:register_implementation)}.register_implementation(klass2)
58
56
  end
59
- end
57
+ EOS
60
58
  end
61
59
 
62
60
  # Register an implementation to this module.
@@ -65,7 +63,6 @@ module RTM
65
63
  # Due to Ruby's restrictions on calling protected methods from other modules extending the very same module Extendable,
66
64
  # this method must be public.
67
65
  def register_implementation(klass)
68
- # super if self.class.superclass.respond_to?(:register_implementation)
69
66
  @implementations ||= []
70
67
  @implementations << klass
71
68
  end
@@ -1,7 +1,7 @@
1
1
  # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
2
  # License: Apache License, Version 2.0
3
3
 
4
- module RTM::RTM
4
+ module RTM
5
5
  def is_uri?(test)
6
6
  begin
7
7
  URI(test)
@@ -49,7 +49,7 @@ module RTM::IO
49
49
  # from_ltm(filename)
50
50
  #
51
51
  def from_ltm(*args)
52
- from_anything(org.tmapix.io.LTMTopicMapReader, *args)
52
+ from_anything(Java::OrgTmapixIo::LTMTopicMapReader, *args)
53
53
  end
54
54
 
55
55
  # Reads a Topic Map from an CTM File
@@ -59,7 +59,7 @@ module RTM::IO
59
59
  # from_ctm(filename)
60
60
  #
61
61
  def from_ctm(*args)
62
- from_anything(org.tmapix.io.CTMTopicMapReader, *args)
62
+ from_anything(Java::OrgTmapixIo::CTMTopicMapReader, *args)
63
63
  end
64
64
 
65
65
  # Reads a JSON Topic Maps (JTM) File
@@ -70,7 +70,7 @@ module RTM::IO
70
70
  #
71
71
  def from_jtm(*args)
72
72
  # seems not to acceped all files that are found to be valid by the JTM validator
73
- from_anything(org.tmapix.io.JTMTopicMapReader, *args)
73
+ from_anything(Java::OrgTmapixIo::JTMTopicMapReader, *args)
74
74
  end
75
75
 
76
76
  # Reads a Friendly Topic Maps XML (TM/XML) File
@@ -81,7 +81,7 @@ module RTM::IO
81
81
  # from_tmxml(filename)
82
82
  #
83
83
  def from_tmxml(*args)
84
- from_anything(org.tmapix.io.TMXMLTopicMapReader, *args)
84
+ from_anything(Java::OrgTmapixIo::TMXMLTopicMapReader, *args)
85
85
  end
86
86
 
87
87
  # Reads a XML Topic Maps (XTM) 1.0 File
@@ -91,7 +91,7 @@ module RTM::IO
91
91
  # from_xtm10(filename)
92
92
  #
93
93
  def from_xtm10(*args)
94
- from_anything(org.tmapix.io.XTM10TopicMapReader, *args)
94
+ from_anything(Java::OrgTmapixIo::XTM10TopicMapReader, *args)
95
95
  end
96
96
  alias :from_xtm1 :from_xtm10
97
97
 
@@ -114,7 +114,7 @@ module RTM::IO
114
114
  # from_xtm(filename)
115
115
  #
116
116
  def from_xtm(*args)
117
- from_anything(org.tmapix.io.XTMTopicMapReader, *args)
117
+ from_anything(Java::OrgTmapixIo::XTMTopicMapReader, *args)
118
118
  end
119
119
 
120
120
  # Reads a Notation3 (N3) File
@@ -128,7 +128,7 @@ module RTM::IO
128
128
  #
129
129
  def from_n3(filename, vocab)
130
130
  raise "Only supported for TMAPI backends!!" unless self.kind_of? Java::OrgTmapiCore::TopicMap
131
- reader = org.tmapix.io.N3TopicMapReader.new self, java.io.File.new(filename)
131
+ reader = Java::OrgTmapixIo::N3TopicMapReader.new self, java.io.File.new(filename)
132
132
  reader.setMappingSource(java.io.File.new(vocab))
133
133
  reader.read
134
134
  end
@@ -144,7 +144,7 @@ module RTM::IO
144
144
  #
145
145
  def from_rdfxml(filename, vocab)
146
146
  raise "Only supported for TMAPI backends!!" unless self.kind_of? Java::OrgTmapiCore::TopicMap
147
- reader = org.tmapix.io.RDFXMLTopicMapReader.new self, java.io.File.new(filename)
147
+ reader = Java::OrgTmapixIo::RDFXMLTopicMapReader.new self, java.io.File.new(filename)
148
148
  reader.setMappingSource(java.io.File.new(vocab))
149
149
  reader.read
150
150
  end
@@ -99,7 +99,7 @@ module RTM::IO
99
99
  # to_xtm20(file, base_iri)
100
100
  #
101
101
  def to_xtm20(*args)
102
- to_anything(org.tmapix.io.XTM20TopicMapWriter, *args)
102
+ to_anything(Java::OrgTmapixIo::XTM20TopicMapWriter, *args)
103
103
  end
104
104
  alias :to_xtm :to_xtm20
105
105
  alias :to_xtm2 :to_xtm20
@@ -120,7 +120,7 @@ module RTM::IO
120
120
  # to_xtm10(file, base_iri)
121
121
  #
122
122
  def to_xtm10(*args)
123
- to_anything(org.tmapix.io.XTM10TopicMapWriter, *args)
123
+ to_anything(Java::OrgTmapixIo::XTM10TopicMapWriter, *args)
124
124
  end
125
125
  alias :to_xtm1 :to_xtm10
126
126
 
@@ -140,7 +140,7 @@ module RTM::IO
140
140
  # to_jtm(file, base_iri)
141
141
  #
142
142
  def to_jtm(*args)
143
- to_anything(org.tmapix.io.JTMTopicMapWriter, *args)
143
+ to_anything(Java::OrgTmapixIo::JTMTopicMapWriter, *args)
144
144
  end
145
145
  alias :to_json :to_jtm
146
146
 
@@ -160,7 +160,7 @@ module RTM::IO
160
160
  # to_ltm(file, base_iri)
161
161
  #
162
162
  def to_ltm(*args)
163
- to_anything(org.tmapix.io.LTMTopicMapWriter, *args)
163
+ to_anything(Java::OrgTmapixIo::LTMTopicMapWriter, *args)
164
164
  end
165
165
 
166
166
  # Serializes an RTM::TopicMap to TM/XML.
@@ -179,7 +179,7 @@ module RTM::IO
179
179
  # to_tmxml(file, base_iri)
180
180
  #
181
181
  def to_tmxml(*args)
182
- to_anything(org.tmapix.io.TMXMLTopicMapWriter, *args)
182
+ to_anything(Java::OrgTmapixIo::TMXMLTopicMapWriter, *args)
183
183
  end
184
184
 
185
185
  # Serializes an RTM::TopicMap to CTM.
@@ -215,7 +215,7 @@ module RTM::IO
215
215
  else
216
216
  args.push(default_params)
217
217
  end
218
- to_anything(de.topicmapslab.ctm.writer.core.CTMTopicMapWriter, *args)
218
+ to_anything(Java::DeTopicmapslabCtmWriterCore::CTMTopicMapWriter, *args)
219
219
  end
220
220
  end
221
221
  RTM.register_extension(self)