rtm 0.1.6 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
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
data/COPYRIGHT DELETED
@@ -1,4 +0,0 @@
1
- Copyright (c) 2007-2008 Benjamin Bock.
2
- All rights reserved.
3
-
4
- See http://rtm.rubyforge.org/
@@ -1,42 +0,0 @@
1
- #
2
- # Rakefile.rb
3
- #
4
- # Created on 02.10.2007, 11:40:17
5
- #
6
- # To change this template, choose Tools | Templates
7
- # and open the template in the editor.
8
-
9
-
10
- require 'rake'
11
- require 'rake/clean'
12
- require 'rake/testtask'
13
- require 'rake/rdoctask'
14
-
15
-
16
- task :default => [:test]
17
-
18
- Rake::RDocTask.new do |t|
19
- t.rdoc_files.include("lib/**/*.rb")
20
- end
21
-
22
- desc "Run all tests"
23
- task :test => :test_units
24
-
25
- desc "Run unit tests"
26
- Rake::TestTask.new("test_units") do |t|
27
- t.pattern = '../test/*_test.rb'
28
- t.verbose = true
29
- t.warning = true
30
- end
31
-
32
- desc "List all lines with TODO, FIXME or XXX in ruby source files"
33
- task :todo do
34
- FileList.new("**/*.rb").each do |source|
35
- File.open(source) do |f|
36
- f.each_line do |line|
37
- puts "#{source}, #{f.lineno}: #{line.strip}" if line =~ /(FIXME|TODO|XXX)/
38
- end
39
- end
40
- end
41
- end
42
-
@@ -1,278 +0,0 @@
1
- require 'rtm'
2
- # Yep, this is the easter egg I told of on the website.
3
- # See the source code at the very end of this file for an explanation.
4
- # Pleace note, this is not beta code, not even alpha - it's just an experiment.
5
-
6
- module ActiveTopicMaps
7
- class Base
8
- def self.inherited(klass)
9
- klass.send(:include, ActiveTopicMaps::Topic)
10
- end
11
- end
12
-
13
- module Topic
14
- def self.included(klass)
15
- klass.extend(ClassMethods)
16
- end
17
- def initialize(topic)
18
- @topic = topic
19
- end
20
- def topic;@topic;end
21
-
22
- module ClassMethods
23
- def acts_as_topic
24
- self.class_eval <<-EOS
25
- def method_missing(name, *args)
26
- @topic.send(name, *args)
27
- end
28
-
29
- alias atm_old_respond_to? respond_to?
30
- def respond_to?(*args)
31
- atm_old_respond_to?(*args) || @topic.respond_to?(*args)
32
- end
33
-
34
- alias old_methods methods
35
- def methods
36
- @methods ||= (old_methods + @topic.methods).uniq
37
- end
38
- EOS
39
- end
40
-
41
- # def acts_smart
42
- # self.class_eval <<-EOS
43
- # alias atm_old_method_missing method_missing
44
- # def method_missing(name, *args)
45
- # if @topic.respond_to?(name)
46
- # @topic.send(name, *args)
47
- # else
48
- # begin
49
- # if name =~ /=$/
50
- # smart_setter(name, *args)
51
- # else
52
- # smart_getter(name, *args)
53
- # end
54
- # rescue
55
- # atm_old_method_missing(name, *args)
56
- # end
57
- # end
58
- # end
59
- #
60
- # def smart_getter(name, *args)
61
- # val = instance_variable_set(("smart_prop_" + name.to_s).to_sym, smart_prop_name)
62
- # prefix = ""
63
- # smart_prop_name ||= (iname = @topic["#{prefix}#{name}"].first) ? iname.value : nil
64
- # instance_variable_set(name, smart_prop_name)
65
- # end
66
- #
67
- # def smart_setter(name, *args)
68
- #
69
- # end
70
- #
71
- # alias atm_old_respond_to? respond_to?
72
- # def respond_to?(*args)
73
- # atm_old_respond_to?(*args) || @topic.respond_to?(*args)
74
- # end
75
- # EOS
76
- # end
77
-
78
- def name(name, type=nil)
79
- type ||= name
80
- prop_getter(name, type, "-")
81
- prop_setter(name, type, "-")
82
- end
83
-
84
- def names(name, type=nil)
85
- type ||= name.singularize
86
- prop_getters(name, type, "-")
87
- prop_adderremover(name, type, "-")
88
- end
89
-
90
- def occurrence(name, type=nil)
91
- type ||= name
92
- prop_getter(name, type)
93
- prop_setter(name, type)
94
- end
95
-
96
- def occurrences(name, type=nil)
97
- type ||= name.singularize
98
- prop_getters(name, type)
99
- prop_adderremover(name, type)
100
- end
101
-
102
- def prop_getter(name, type, prefix="")
103
- self.class_eval <<-EOS
104
- def #{name}
105
- @#{name} ||= (iname = @topic["#{prefix}#{type}"].first) ? iname.value : nil
106
- end
107
- EOS
108
- end
109
-
110
- def prop_getters(name, type, prefix="")
111
- self.class_eval <<-EOS
112
- def #{name}
113
- @#{name} ||= @topic["#{prefix}#{type}"].map{|n| n.value}
114
- end
115
- EOS
116
- end
117
-
118
- def prop_setter(name, type, prefix="")
119
- self.class_eval <<-EOS
120
- def #{name}=(name)
121
- old = @topic["#{prefix}#{type}"].first
122
- @#{name} = if old
123
- old.value = name
124
- else
125
- @topic["#{prefix}#{type}"] = name
126
- end
127
- end
128
- EOS
129
- end
130
-
131
- def prop_adderremover(name, type, prefix="")
132
- self.class_eval <<-EOS
133
- def add_#{name.singularize}(name)
134
- @topic["#{prefix}#{type}"] = name
135
- end
136
- def remove_#{name.singularize}(name)
137
- @topic["#{prefix}#{type}"].each {|item| item.remove if item.value == name}
138
- end
139
- EOS
140
- end
141
-
142
- def has_many(name, rt1, at, rt2, klass)
143
- eval(<<-EOS)
144
- class RTM::AR::Topic
145
- index_property_set :#{name}, :type => :Topic, :rule => {
146
- :transitive => true,
147
- :role_type => "#{rt1}",
148
- :association_type => "#{at}",
149
- :association_arity => 2,
150
- :other_role_type => "#{rt2}",
151
- :add => "#{name.to_s.singularize}",
152
- }
153
- end
154
- EOS
155
- self.class_eval <<-EOS
156
- def #{name}
157
- @topic.#{name}.map{|o| #{klass}.new(o)}
158
- end
159
- def add_#{name.to_s.singularize}(o)
160
- @topic.add_#{name.to_s.singularize}(o.topic)
161
- end
162
- def remove_#{name.to_s.singularize}(o)
163
- @topic.remove_#{name.to_s.singularize}(o.topic)
164
- end
165
- EOS
166
- end
167
-
168
- def topic_map(base_uri_or_tm)
169
- @tm = base_uri_or_tm.is_a?(RTM::TopicMap) ? base_uri_or_tm : RTM.create(base_uri_or_tm)
170
- end
171
-
172
- def create(ref)
173
- t = @tm.get!(ref)
174
- if @psi
175
- @ty ||= @tm.get!(@psi)
176
- t.add_type @ty unless t.types.include? @ty
177
- end
178
- self.new(t)
179
- end
180
- alias get! create
181
-
182
- def find(ref)
183
- t = @tm.get(ref)
184
- self.new(t) if t
185
- end
186
- alias get find
187
-
188
- def find_by_type(ref=nil)
189
- ref ||= @psi
190
- ty = @tm.get(ref)
191
- ty.instances.map {|t| self.new(t)}
192
- end
193
-
194
- def psi(ref)
195
- @psi = ref
196
- end
197
- end
198
- end
199
- end
200
-
201
-
202
- #require 'activetopicmaps'
203
- #RTM.connect
204
- #
205
- #class Person < ActiveTopicMaps::Base
206
- # topic_map "urn:/base"
207
- # psi "person"
208
- #
209
- # name :name
210
- # occurrence :age
211
- # occurrence :shoesize, "http://rtm.rubyforge.org/psi/shoesize" # this tells ActiveTM to use this as occurrence type
212
- #
213
- # def to_s
214
- # a = " (#{age})" if age
215
- # "#{name}#{a}"
216
- # end
217
- #end
218
- #
219
- #class Country
220
- # include ActiveTopicMaps::Topic
221
- #
222
- # topic_map "urn:/base"
223
- # psi "country"
224
- #
225
- # acts_as_topic
226
- #
227
- # name :name
228
- # occurrence :population
229
- # occurrence :size
230
- #
231
- # has_many :inhabitants, "country", "country-inhabitant", "inhabitant", :Person
232
- #
233
- # def to_s
234
- # "There is a country called #{name} with #{population} inhabitants and a size of #{size} km^2.\n" +
235
- # "These are some of the inhabitants: #{inhabitants.map{|i| i.to_s}.join(", ")}."
236
- # end
237
- #end
238
- #
239
- ## create a new object with a (new?) topic
240
- #p = Person.create("max")
241
- #
242
- ## set name, age, shoesize
243
- #p.name = "Max Mustermann"
244
- #p.age = 30
245
- #p.shoesize = 44 # european ;)
246
- #
247
- ## print out the name
248
- #puts p.name
249
- #
250
- ## create a new object, using a topic (might be queried before, ... you know)
251
- #h = Person.new(RTM[0].get!("hans"))
252
- #
253
- ## set name
254
- #h.name = "Hans Maier"
255
- ## set another name (overwrites the old one! this is different from topic["-name"] !!!)
256
- #h.name = "Hans Meyer"
257
- #
258
- ## don't know what that does, maybe you?
259
- #puts h.name
260
- #
261
- ## Norway is the item identifier, here
262
- #no=Country.create("Norway")
263
- #
264
- #no.name="Norway"
265
- #no.population = "4.743.000"
266
- #no.size = "385.199"
267
- #
268
- ## use real person objects here
269
- #no.add_inhabitant h
270
- #no.add_inhabitant p
271
- #
272
- ## use this nice to_s method we provided above
273
- #puts no.to_s
274
- #
275
- ## find hans
276
- #puts "Trying to find Hans: #{Person.find("hans")}"
277
- ## won't find otto
278
- #puts "Trying to find Otto: #{Person.find("otto")}"
@@ -1,58 +0,0 @@
1
- class Class
2
- alias :rtm_old_const_missing :const_missing
3
- def const_missing(const_name)
4
- puts "Constant missing: #{const_name.inspect}"
5
- rtm_old_const_missing(const_name)
6
- end
7
- end
8
- # The following methods allow automatic +map+ping on arrays to their containees properties.
9
- # However this is a dirt hack and did no longer work in ActiveRecord 2.1.0.
10
- # This should be fixed some time later.
11
- #
12
- #class Array
13
- # alias :rtm_old_method_missing :method_missing
14
- # def method_missing(method_name, *args)
15
- # if size > 0 && first.respond_to?(method_name) && (![:__getobj__, :__setobj__].include?(method_name))
16
- # inject([]) {|all,single| all << single.send(method_name, *args)}
17
- # else
18
- # rtm_old_method_missing(method_name, *args)
19
- # end
20
- # end
21
- #
22
- # alias :rtm_old_respond_to? :respond_to?
23
- # def respond_to?(method_name, *args)
24
- # resp = rtm_old_respond_to?(method_name, *args)
25
- # return resp if resp # i.e. if true
26
- # # check for special calls we don't want to pass
27
- # return false if [:__getobj__, :__setobj__].include?(method_name)
28
- # # ... and ask first child otherwise
29
- # @obj && @obj.size > 0 && first.respond_to?(method_name, *args)
30
- # end
31
- #
32
- # def compact_empty
33
- # compact.reject{|e| e.empty?}
34
- # end
35
- #end
36
- class ActiveRecord::Associations::AssociationProxy
37
- # this is needed to prevent the associations from being instantly loaded
38
- alias :rtm_old_respond_to? :respond_to?
39
- def respond_to?(method_name, *args)
40
- return false if method_name == :__getobj__
41
- rtm_old_respond_to?(method_name, *args)
42
- end
43
- end
44
- # ActiveRecord implementation
45
- module RTM::AR
46
- require 'uri'
47
- require 'rtm/backend/active_record/tmdm'
48
- require 'rtm/backend/active_record/tm_delegator'
49
- require 'rtm/backend/active_record/tm_set_delegator'
50
- require 'rtm/backend/active_record/tm_construct'
51
- require 'rtm/backend/active_record/topic_map'
52
- require 'rtm/backend/active_record/traverse_associations'
53
- require 'rtm/backend/active_record/topic'
54
- require 'rtm/backend/active_record/association_and_role'
55
- require 'rtm/backend/active_record/name_variant_occurrence'
56
- require 'rtm/backend/active_record/locators'
57
- require 'rtm/backend/active_record/set_wrapper'
58
- end
@@ -1,116 +0,0 @@
1
- require 'active_record'
2
-
3
- module RTM
4
- module AR
5
- module TMDM
6
- class InitialSchema < ActiveRecord::Migration
7
- def self.up
8
- create_table :topic_maps do |t|
9
- t.column :base_locator, :string, :null => false
10
- end
11
- create_table :topics do |t|
12
- t.column :topic_map_id, :integer, :null => false
13
- t.column :reified_id, :integer
14
- t.column :reified_type, :string
15
- end
16
- create_table :associations do |t|
17
- t.column :topic_map_id, :integer, :null => false
18
- t.column :ttype_id, :integer
19
- end
20
- create_table :association_roles do |t|
21
- t.column :association_id, :integer, :null => false
22
- t.column :ttype_id, :integer
23
- t.column :topic_id, :integer
24
- end
25
- create_table :topic_names do |t|
26
- t.column :topic_id, :integer, :null => false
27
- t.column :ttype_id, :integer
28
- t.column :value, :string
29
- end
30
- create_table :occurrences do |t|
31
- t.column :topic_id, :integer, :null => false
32
- t.column :ttype_id, :integer
33
- t.column :value, :text
34
- t.column :datatype, :string
35
- end
36
- create_table :variants do |t|
37
- t.column :topic_name_id, :integer, :null => false
38
- t.column :value, :text
39
- t.column :datatype, :string
40
- end
41
- create_table :item_identifiers do |t|
42
- t.column :topic_map_id, :integer, :null => false
43
- t.column :reference, :string, :null => false
44
- t.column :topic_map_construct_id, :integer
45
- t.column :topic_map_construct_type, :string
46
- end
47
- create_table :subject_identifiers do |t|
48
- t.column :topic_map_id, :integer, :null => false
49
- t.column :reference, :string, :null => false
50
- t.column :topic_id, :integer
51
- end
52
- create_table :subject_locators do |t|
53
- t.column :topic_map_id, :integer, :null => false
54
- t.column :reference, :string, :null => false
55
- t.column :topic_id, :integer
56
- end
57
- create_table :scoped_objects_topics do |t|
58
- t.column :scoped_object_id, :integer
59
- t.column :scoped_object_type, :string
60
- t.column :topic_id, :integer
61
- end
62
- # execute("
63
- # create view associations_rolecount as
64
- # select a.id as id, a.topic_map_id as topic_map_id, a.ttype_id as ttype_id, count(a.id) as rcnt
65
- # from associations a inner join association_roles r1 on a.id == r1.association_id;
66
- # ")
67
- #
68
- # execute("
69
- # create view associations_cache as
70
- # select distinct
71
- # a.id as id, a.topic_map_id, a.ttype_id, a.rcnt,
72
- # r1.id as role1_id, r1.ttype_id as type1_id, r1.topic_id as player1_id,
73
- # r2.id as role2_id, r2.ttype_id as type2_id, r2.topic_id as player2_id
74
- # from associations_rolecount a
75
- # inner join association_roles r1 on a.id == r1.association_id
76
- # inner join association_roles r2 on a.id == r2.association_id
77
- # where r1.id != r2.id;
78
- # ")
79
- # execute("
80
- # create view associationcache as
81
- # select distinct
82
- # a.id as association_id, a.topic_map_id, a.ttype_id,
83
- # r1.id as association_role1_id, r1.ttype_id as role_type1_id, r1.topic_id as player1_id,
84
- # r2.id as association_role2_id, r2.ttype_id as role_type2_id, r2.topic_id as player2_id
85
- # from associations a
86
- # inner join association_roles r1 on a.id == r1.association_id
87
- # inner join association_roles r2 on a.id == r2.association_id
88
- # where r1.id != r2.id
89
- # ")
90
- end
91
-
92
- def self.down
93
- drop_table :topic_maps
94
- drop_table :topic
95
- drop_table :associations
96
- drop_table :association_roles
97
- drop_table :topic_names
98
- drop_table :occurrences
99
- drop_table :variants
100
- drop_table :scoped_objects_topics
101
- end
102
-
103
- end
104
- end
105
- end
106
- end
107
-
108
- if __FILE__ == $0
109
- puts "Generating SQLite3 Databse tmdm.sqlite3."
110
- ActiveRecord::Base.establish_connection(
111
- :adapter => "sqlite3",
112
- :database => "tmdm.sqlite3"
113
- )
114
- RTM::AR::TMDM::InitialSchema.migrate(:up)
115
- end
116
-