mexico 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +15 -0
  2. data/.document +5 -0
  3. data/.gitmodules +3 -0
  4. data/.project +14 -0
  5. data/.rspec +2 -0
  6. data/Gemfile +31 -0
  7. data/LICENSE.txt +165 -0
  8. data/README.md +116 -0
  9. data/Rakefile +66 -0
  10. data/VERSION +1 -0
  11. data/assets/TESTCORPUS/Corpus.xml +26 -0
  12. data/assets/fiesta/b6/layer_connectors.fst +16 -0
  13. data/assets/fiesta/b6/match_jones_161_CM_neu_checked.parsed.xml +1225 -0
  14. data/assets/fiesta/elan/ElanFileFormat.eaf +76 -0
  15. data/assets/fiesta/elan/ElanFileFormat.pfsx +8 -0
  16. data/assets/fiesta/elan/ElanFileFormatComplexInterLayerLinks.eaf +107 -0
  17. data/assets/fiesta/elan/reflinks_example.eaf +270 -0
  18. data/assets/fiesta/elan/test_all_interlayerrelations.fst +43 -0
  19. data/assets/fiesta/head/head.fst +24 -0
  20. data/assets/fiesta/praat/mexico.ShortTextGrid +81 -0
  21. data/assets/fiesta/praat/mexico.TextGrid +104 -0
  22. data/assets/helpers/collection_ref_handler.rb +29 -0
  23. data/assets/helpers/id_ref_handler.rb +29 -0
  24. data/assets/helpers/roxml_attribute_handler.rb +57 -0
  25. data/assets/out_only/construct_and_write_spec.toe +99 -0
  26. data/assets/spec.html +554 -0
  27. data/bin/mexico +5 -0
  28. data/features/mexico.feature +9 -0
  29. data/features/step_definitions/mexico_steps.rb +0 -0
  30. data/features/support/env.rb +15 -0
  31. data/info/releasenotes/0.0.1.md +5 -0
  32. data/info/releasenotes/0.0.2.md +5 -0
  33. data/info/releasenotes/0.0.3.md +5 -0
  34. data/info/releasenotes/0.0.4.md +5 -0
  35. data/info/releasenotes/0.0.5.md +8 -0
  36. data/info/releasenotes/0.0.6.md +3 -0
  37. data/info/releasenotes/0.0.7.md +4 -0
  38. data/info/releasenotes/0.0.8.md +9 -0
  39. data/info/releasenotes/0.0.9.md +7 -0
  40. data/lib/mexico/cmd.rb +210 -0
  41. data/lib/mexico/constants.rb +82 -0
  42. data/lib/mexico/constraints/constraint.rb +85 -0
  43. data/lib/mexico/constraints/fiesta_constraints.rb +209 -0
  44. data/lib/mexico/constraints.rb +27 -0
  45. data/lib/mexico/core/corpus_core.rb +39 -0
  46. data/lib/mexico/core/design_core.rb +31 -0
  47. data/lib/mexico/core/media_type.rb +61 -0
  48. data/lib/mexico/core.rb +36 -0
  49. data/lib/mexico/fiesta/interfaces/b6_chat_game_interface.rb +222 -0
  50. data/lib/mexico/fiesta/interfaces/elan_interface.rb +143 -0
  51. data/lib/mexico/fiesta/interfaces/short_text_grid_interface.rb +99 -0
  52. data/lib/mexico/fiesta/interfaces/text_grid_interface.rb +103 -0
  53. data/lib/mexico/fiesta/interfaces.rb +31 -0
  54. data/lib/mexico/fiesta.rb +27 -0
  55. data/lib/mexico/file_system/bound_to_corpus.rb +37 -0
  56. data/lib/mexico/file_system/corpus.rb +207 -0
  57. data/lib/mexico/file_system/data.rb +96 -0
  58. data/lib/mexico/file_system/design.rb +75 -0
  59. data/lib/mexico/file_system/design_component.rb +78 -0
  60. data/lib/mexico/file_system/entry.rb +59 -0
  61. data/lib/mexico/file_system/fiesta_document.rb +344 -0
  62. data/lib/mexico/file_system/fiesta_map.rb +112 -0
  63. data/lib/mexico/file_system/head.rb +33 -0
  64. data/lib/mexico/file_system/id_ref.rb +46 -0
  65. data/lib/mexico/file_system/implicit_item_link.rb +19 -0
  66. data/lib/mexico/file_system/interval_link.rb +84 -0
  67. data/lib/mexico/file_system/item.rb +166 -0
  68. data/lib/mexico/file_system/item_link.rb +98 -0
  69. data/lib/mexico/file_system/item_links_proxy.rb +13 -0
  70. data/lib/mexico/file_system/layer.rb +89 -0
  71. data/lib/mexico/file_system/layer_connector.rb +74 -0
  72. data/lib/mexico/file_system/layer_link.rb +75 -0
  73. data/lib/mexico/file_system/local_file.rb +101 -0
  74. data/lib/mexico/file_system/participant.rb +69 -0
  75. data/lib/mexico/file_system/participant_role.rb +43 -0
  76. data/lib/mexico/file_system/point_link.rb +79 -0
  77. data/lib/mexico/file_system/property.rb +35 -0
  78. data/lib/mexico/file_system/property_map.rb +37 -0
  79. data/lib/mexico/file_system/resource.rb +174 -0
  80. data/lib/mexico/file_system/scale.rb +125 -0
  81. data/lib/mexico/file_system/section.rb +41 -0
  82. data/lib/mexico/file_system/static_collection_ref.rb +64 -0
  83. data/lib/mexico/file_system/template.rb +23 -0
  84. data/lib/mexico/file_system/trial.rb +87 -0
  85. data/lib/mexico/file_system/url.rb +65 -0
  86. data/lib/mexico/file_system.rb +62 -0
  87. data/lib/mexico/not_yet_implemented_error.rb +28 -0
  88. data/lib/mexico/util/fancy_container.rb +57 -0
  89. data/lib/mexico/util.rb +51 -0
  90. data/lib/mexico.rb +36 -0
  91. data/spec/constraints/constraints_spec.rb +306 -0
  92. data/spec/core/media_type_spec.rb +50 -0
  93. data/spec/fiesta/b6_spec.rb +43 -0
  94. data/spec/fiesta/elan_spec.rb +43 -0
  95. data/spec/fiesta/head_spec.rb +54 -0
  96. data/spec/fiesta/praat_spec.rb +54 -0
  97. data/spec/fiesta/read_spec.rb +76 -0
  98. data/spec/file_system_based/better_collection_spec.rb +142 -0
  99. data/spec/file_system_based/corpus_spec.rb +194 -0
  100. data/spec/file_system_based/design_spec.rb +100 -0
  101. data/spec/file_system_based/inter_links_spec.rb +100 -0
  102. data/spec/file_system_based/item_links_spec.rb +76 -0
  103. data/spec/file_system_based/rdf_spec.rb +177 -0
  104. data/spec/file_system_based/resource_spec.rb +111 -0
  105. data/spec/file_system_based/trial_spec.rb +129 -0
  106. data/spec/spec_helper.rb +14 -0
  107. data/spec/toe/construct_and_write_spec.rb +82 -0
  108. data/spec/toe/construction_spec.rb +110 -0
  109. data/spec/toe/item_spec.rb +58 -0
  110. data/spec/toe/layer_spec.rb +63 -0
  111. data/spec/toe/scale_spec.rb +89 -0
  112. data/spec/toe/toe_document_spec.rb +39 -0
  113. data/test/helper.rb +19 -0
  114. data/test/test_mexico.rb +7 -0
  115. metadata +357 -0
@@ -0,0 +1,344 @@
1
+ # This file is part of the MExiCo gem.
2
+ # Copyright (c) 2012-2014 Peter Menke, SFB 673, Universität Bielefeld
3
+ # http://www.sfb673.org
4
+ #
5
+ # MExiCo is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as
7
+ # published by the Free Software Foundation, either version 3 of
8
+ # the License, or (at your option) any later version.
9
+ #
10
+ # MExiCo is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with MExiCo. If not, see
17
+ # <http://www.gnu.org/licenses/>.
18
+
19
+ # This class provides a corpus representation that is backed up by the filesystem.
20
+ # A central Corpus definition file in the top-level folder contains an
21
+ # XML representation of the corpus structure, and all actual resources are found
22
+ # as files on a file system reachable from the top-level folder.
23
+
24
+ require 'poseidon'
25
+
26
+ # FiESTA Document
27
+ class Mexico::FileSystem::FiestaDocument
28
+
29
+ # This class stands for an XML document in the Toe format.
30
+
31
+ include ::ROXML
32
+
33
+ extend ::Mexico::Util::FancyContainer
34
+
35
+ xml_name 'FiestaDocument'
36
+
37
+ # identifier
38
+ xml_accessor :identifier, :from => '@id'
39
+
40
+ # type String
41
+ xml_accessor :name, :from => '@name'
42
+
43
+ # type Mexico::FileSystem::Head
44
+ xml_accessor :head, :from => "Head", :as => Mexico::FileSystem::Head
45
+
46
+ # collection of Mexico::FileSystem::Scale
47
+ xml_accessor :scales_container, :as => [::Mexico::FileSystem::Scale], :from => "Scale", :in => "ScaleSet"
48
+
49
+ # collection of Mexico::FileSystem::Layer
50
+ xml_accessor :layers_container, :as => [::Mexico::FileSystem::Layer], :from => "Layer", :in => "LayerSet"
51
+
52
+ # collection of Mexico::FileSystem::Layer
53
+ xml_accessor :layer_connectors, :as => [::Mexico::FileSystem::LayerConnector], :from => "LayerConnector", :in => "LayerSet"
54
+
55
+ # collection of Mexico::FileSystem::Item
56
+ xml_accessor :items_container, :as => [::Mexico::FileSystem::Item], :from => "Item", :in => "ItemSet"
57
+
58
+ attr_accessor :resource
59
+
60
+ add_fancy_container :scales
61
+ add_fancy_container :layers
62
+ add_fancy_container :items
63
+
64
+ @@CACHE = {}
65
+ # POSEIdON-based RDF augmentation
66
+ include Poseidon
67
+ self_uri %q(http://cats.sfb673.org/FiestaDocument)
68
+ # instance_uri_scheme %q(http://phoibos.sfb673.org/corpora/#{resource.corpus.identifier}/resources/#{resource.identifier}.fst)
69
+ instance_uri_scheme %q(http://phoibos.sfb673.org/resources/#{identifier})
70
+ rdf_property :identifier, %q(http://cats.sfb673.org/identifier)
71
+ rdf_property :name, %q(http://cats.sfb673.org/name)
72
+
73
+ rdf_include :scales, %q(http://cats.sfb673.org/hasScale)
74
+ rdf_include :layers, %q(http://cats.sfb673.org/hasLayer)
75
+ rdf_include :items, %q(http://cats.sfb673.org/hasItem)
76
+
77
+ # Retrieves a stored object from the temporary import cache.
78
+ # @param (String) xml_id The xml id of the needed object.
79
+ # @return (Object) The needed object, or +nil+ if nothing could be found.
80
+ def self.resolve(xml_id)
81
+ @@CACHE["#{Thread.current.__id__}.#{xml_id}"]
82
+ end
83
+
84
+ # Retrieves a stored object from the temporary import cache.
85
+ # @param (String) xml_id The xml id of the needed object.
86
+ # @return (Boolean) +true+ if there is an entry for the given id, +false+ otherwise.
87
+ def self.knows?(xml_id)
88
+ @@CACHE.has_key?("#{Thread.current.__id__}.#{xml_id}")
89
+ end
90
+
91
+ # Retrieves a stored object from the temporary import cache.
92
+ # @param (String) xml_id The xml id of the needed object.
93
+ # @param (String) ruby_object The ruby object to be stored.
94
+ # @return (void)
95
+ def self.store(xml_id, ruby_object)
96
+ @@CACHE = {} unless defined?(@@CACHE)
97
+ @@CACHE["#{Thread.current.__id__}.#{xml_id}"] = ruby_object
98
+ ::Mexico::FileSystem::FiestaDocument.check_watch(xml_id, ruby_object)
99
+ end
100
+
101
+ # Put an xml id into the watch list, along with an object and a method
102
+ def self.watch(needed_id, object, method)
103
+ @@WATCHLIST = {} unless defined?(@@WATCHLIST)
104
+ @@WATCHLIST["#{Thread.current.__id__}.#{needed_id}"] = [] unless @@WATCHLIST.has_key?("#{Thread.current.__id__}.#{needed_id}")
105
+ @@WATCHLIST["#{Thread.current.__id__}.#{needed_id}"] << [object, method]
106
+ end
107
+
108
+ # Checks whether the given id/object pair is watched, and takes appropriate action
109
+ # if this is the case.
110
+ # @param (String) needed_id The XML ID that might be watched.
111
+ # @param (Object) needed_object The ruby object that might be watched.
112
+ # @return (void)
113
+ def self.check_watch(needed_id, needed_object)
114
+ if defined?(@@WATCHLIST)
115
+ if @@WATCHLIST.has_key?("#{Thread.current.__id__}.#{needed_id}")
116
+ @@WATCHLIST["#{Thread.current.__id__}.#{needed_id}"].each do |entry|
117
+ entry[0].send(entry[1], needed_object)
118
+ end
119
+ @@WATCHLIST.delete("#{Thread.current.__id__}.#{needed_id}")
120
+ end
121
+ end
122
+ end
123
+
124
+ # Opens the document at the given location.
125
+ # @param (String) filename The path that points to the file to be opened.
126
+ # @return (Mexico::FileSystem::FiestaDocument) a toe document with that file's contents.
127
+ def self.open(filename)
128
+ self.from_xml(File.open(filename))
129
+ end
130
+
131
+ # Creates a new, empty instance of a FiESTA document.
132
+ # @todo Check if all standard or default values are set correctly.
133
+ def initialize
134
+ super
135
+ @head = Mexico::FileSystem::Head.new
136
+ @scales_container = []
137
+ @layers_container = []
138
+ @layer_connectors = []
139
+ @items_container = []
140
+ link_document
141
+ end
142
+
143
+ # Adds a standard timeline scale to the document.
144
+ # @param unit [String] The unit to be used for this timeline.
145
+ # @return [Scale] The created timeline scale object.
146
+ def add_standard_timeline(unit="ms")
147
+ @scales_container << Mexico::FileSystem::Scale.new(identifier: 'timeline01', name: 'Timeline', unit: unit, dimension: Mexico::FileSystem::Scale::DIM_TIME)
148
+ @scales_container.last.document = self
149
+ @scales_container.last
150
+ end
151
+
152
+ def add_layer(args)
153
+ if args.is_a?(Hash)
154
+ new_layer = Mexico::FileSystem::Layer.new(args.merge({document: self}))
155
+ @layers_container << new_layer
156
+ return new_layer
157
+ end
158
+ if args.is_a?(Mexico::FileSystem::Layer)
159
+ @layers_container << args
160
+ return args
161
+ end
162
+ # @TODO catch error if parameter has wrong object type
163
+ return nil
164
+ end
165
+
166
+ # This method attempts to link objects from other locations of the XML/object tree
167
+ # into position inside this object, by following the xml ids given in the
168
+ # appropriate fields of this class.
169
+ def after_parse
170
+ link_document
171
+ # then clear cache
172
+ @@CACHE.clear
173
+ end
174
+
175
+ def link_document
176
+ # process xml ids
177
+ scales.each do |x|
178
+ x.document = self
179
+ end
180
+ layers.each do |x|
181
+ x.document = self
182
+ end
183
+ items.each do |x|
184
+ x.document = self
185
+ x.item_links.each do |y|
186
+ y.document = self
187
+ end
188
+ x.layer_links.each do |y|
189
+ y.document = self
190
+ end
191
+ x.point_links.each do |y|
192
+ y.document = self
193
+ end
194
+ x.interval_links.each do |y|
195
+ y.document = self
196
+ end
197
+ end
198
+ end
199
+
200
+ def add_item(item=nil)
201
+ if item.nil?
202
+ new_item = Mexico::FileSystem::Item.new(identifier: "item#{rand(2**16)}")
203
+ # @TODO check if that random ID is still available!
204
+ end
205
+ if item.is_a?(Hash)
206
+ new_item = Mexico::FileSystem::Item.new(item.merge({document: self}))
207
+ end
208
+ if item.is_a?(Mexico::FileSystem::Item)
209
+ new_item = item
210
+ end
211
+ # @TODO catch error if parameter has wrong object type
212
+ if block_given?
213
+ yield new_item
214
+ end
215
+ # check if item is not in the array already
216
+ @items_container << new_item
217
+ new_item
218
+ end
219
+
220
+ def add_layer_connector(layer_connector)
221
+ @layer_connectors << layer_connector
222
+ end
223
+
224
+ def get_layer_by_id(id)
225
+ matches = layers.select{|l| l.identifier == id}
226
+ return matches[0] if matches.size>0
227
+ return nil
228
+ end
229
+
230
+ def layers_form_a_graph?
231
+ true
232
+ end
233
+
234
+ def layers_form_a_dag?
235
+ raise Mexico::NotYetImplementedError.new('This method has not been implemented yet.')
236
+ end
237
+
238
+ def layers_form_a_cdag?
239
+ raise Mexico::NotYetImplementedError.new('This method has not been implemented yet.')
240
+ end
241
+
242
+ def layers_form_a_forest?
243
+ # check whether all layers have at most one parent layer
244
+ self.layers.each do |layer|
245
+ return false if layer.predecessor_layers.size > 1
246
+ end
247
+ return true
248
+ end
249
+
250
+ def layers_form_a_tree?
251
+ # check whether all layers but one have exactly one parent layer
252
+ other_than_ones = []
253
+ self.layers.each do |layer|
254
+ s = layer.predecessor_layers.size
255
+ other_than_ones << s if s != 1
256
+ end
257
+ true if s.size == 1 && s.first==0
258
+ end
259
+
260
+ def layers_form_an_edgeless_graph?
261
+ @layer_connectors.empty?
262
+ end
263
+
264
+ def layers_form_an_empty_graph?
265
+ layers.empty?
266
+ end
267
+
268
+ def inter_layer_graph(layer1, layer2)
269
+ # 0: source items, 1: target items, 2: links
270
+ result_graph = {
271
+ sources: Set.new,
272
+ sinks: Set.new,
273
+ links: Set.new,
274
+ source_map: Hash.new,
275
+ sink_map: Hash.new
276
+ }
277
+
278
+ result_graph[:sources].merge layer1.items
279
+ result_graph[:sinks].merge layer2.items
280
+
281
+ links = result_graph[:sources].collect{|i| i.item_links }.flatten
282
+ links = links.select{|l| l.target_object.layers.include?(layer2) }
283
+ result_graph[:links] = links
284
+
285
+ # fill the source and target maps with data
286
+ result_graph[:sources].each do |node|
287
+ result_graph[:source_map][node] = Set.new
288
+ end
289
+ result_graph[:sinks].each do |node|
290
+ result_graph[:sink_map][node] = Set.new
291
+ end
292
+
293
+ result_graph[:links].each do |link|
294
+ source = link.item
295
+ sink = link.target_item
296
+ result_graph[:source_map][source] << sink
297
+ result_graph[:sink_map][sink] << source
298
+ end
299
+
300
+ result_graph
301
+ end
302
+
303
+ def inter_layer_graph_list
304
+ # collect all parent child pairs of layers
305
+ # calculate layer graphs for all of them
306
+ ilg_list = Hash.new
307
+ layers.each do |parent_layer|
308
+ parent_layer.successor_layers.each do |child_layer|
309
+ ilg_list[ [parent_layer, child_layer[0]] ] = inter_layer_graph(parent_layer, child_layer[0])
310
+ end
311
+ end
312
+ ilg_list
313
+ end
314
+
315
+ def source_cardinality_for_layer(layer1, layer2)
316
+ inter_layer_graph_list[[layer1,layer2]][:sink_map].values.collect{|m| m.size}.max
317
+ end
318
+
319
+ def sink_cardinality_for_layer(layer1, layer2)
320
+ inter_layer_graph_list[[layer1,layer2]][:source_map].values.collect{|m| m.size}.max
321
+ end
322
+
323
+
324
+ # Cardinality of source elements: how many links are connected to the source nodes?
325
+ def inter_layer_source_cardinality
326
+ card = 0
327
+ inter_layer_graph_list.each do |k,v|
328
+ graph_card = v[:sink_map].values.collect{|m| m.size}.max
329
+ card = [card,graph_card].max
330
+ end
331
+ card
332
+ end
333
+
334
+ # Cardinality of source elements: how many links are connected to the source nodes?
335
+ def inter_layer_sink_cardinality
336
+ card = 0
337
+ inter_layer_graph_list.each do |k,v|
338
+ graph_card = v[:source_map].values.collect{|m| m.size}.max
339
+ card = [card,graph_card].max
340
+ end
341
+ card
342
+ end
343
+
344
+ end
@@ -0,0 +1,112 @@
1
+ # This file is part of the MExiCo gem.
2
+ # Copyright (c) 2012-2014 Peter Menke, SFB 673, Universität Bielefeld
3
+ # http://www.sfb673.org
4
+ #
5
+ # MExiCo is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as
7
+ # published by the Free Software Foundation, either version 3 of
8
+ # the License, or (at your option) any later version.
9
+ #
10
+ # MExiCo is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with MExiCo. If not, see
17
+ # <http://www.gnu.org/licenses/>.
18
+
19
+ # This class models a data container for map (or attribute value) structures.
20
+
21
+ class Mexico::FileSystem::FiestaMap
22
+
23
+ include ::ROXML
24
+
25
+ attr_reader :map_items
26
+
27
+ # Creates a new map instance. If initial_vals is defined and contains values,
28
+ # those will be used to populate the map.
29
+ # @param initial_vals [Hash] Initial values for the new map object.
30
+ def initialize(initial_vals={})
31
+ @map = Hash.new
32
+ @map.merge!(initial_vals)
33
+ end
34
+
35
+ # Adds or modifies an entry with the key +k+ in the map.
36
+ # @param k [Object] The key to be used.
37
+ # @param v [Object] The value to be used.
38
+ # @return [void]
39
+ def []=(k,v)
40
+ @map[k]=v
41
+ end
42
+
43
+ # Retrieves the value for the given key +k+ from the map.
44
+ # @param k [Object] The key to be used.
45
+ # @return [Object,nil] The corresponding value object, or +nil+
46
+ # if there was no entry for the given key.
47
+ def [](k)
48
+ @map[k]
49
+ end
50
+
51
+ # Returns the number of entries in this map.
52
+ # @return [Integer] The number of entries.
53
+ def size
54
+ @map.size
55
+ end
56
+
57
+ # Returns +true+ iff this map is empty.
58
+ # @return [Boolean] Returns +true+ iff this map is empty, +false+ otherwise.
59
+ def empty?
60
+ @map.empty?
61
+ end
62
+
63
+ # Returns +true+ iff this map contains an entry with the given key.
64
+ # @param k [Object] The key to be found.
65
+ # @return [Boolean] Returns +true+ iff the given key is used in this map, +false+ otherwise.
66
+ def has_key?(k)
67
+ @map.has_key?(k)
68
+ end
69
+
70
+ # Auxiliary method that reads a +FiestaMap+ object
71
+ # from the standard XML representation of FiESTA.
72
+ # @param node [XML::Node] The XML node to read from
73
+ # @return [FiestaMap] The map object represented in that XML node.
74
+ def self.from_xml(node)
75
+ #puts "SOMEONE CALLED FiestaMap.from_xml"
76
+ #puts node.name
77
+ # @map = Hash.new
78
+
79
+ map = self.new
80
+
81
+ node.xpath('./MapItem').each do |mi|
82
+ #puts mi.name
83
+ #puts mi['key']
84
+ #puts mi.text
85
+ map[mi['key']]=mi.text
86
+ end
87
+ #puts map.size
88
+ map
89
+ end
90
+
91
+ # Creates a human-readable string representation of this map.
92
+ # @return [String] A string describing this map object.
93
+ def to_s
94
+ @map.to_a.collect{|k,v| "#{k} => #{v}"}.join(", ")
95
+ end
96
+
97
+ # Converts this map object to its standard XML representation
98
+ # @todo what does the variable +x+ do?
99
+ # @return [XML::Node] the node containing the XML representation
100
+ def to_xml(x)
101
+ n = XML::new_node("Map")
102
+ @map.each_pair do |k,v|
103
+ i_node = XML::new_node("MapItem")
104
+ i_node['key'] = k
105
+ i_node.content = v
106
+ n.add_child(i_node)
107
+ end
108
+
109
+ n
110
+ end
111
+
112
+ end
@@ -0,0 +1,33 @@
1
+ # This file is part of the MExiCo gem.
2
+ # Copyright (c) 2012-2014 Peter Menke, SFB 673, Universität Bielefeld
3
+ # http://www.sfb673.org
4
+ #
5
+ # MExiCo is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as
7
+ # published by the Free Software Foundation, either version 3 of
8
+ # the License, or (at your option) any later version.
9
+ #
10
+ # MExiCo is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with MExiCo. If not, see
17
+ # <http://www.gnu.org/licenses/>.
18
+
19
+ # This class provides a corpus representation that is backed up by the filesystem.
20
+ # A central Corpus definition file in the top-level folder contains an
21
+ # XML representation of the corpus structure, and all actual resources are found
22
+ # as files on a file system reachable from the top-level folder.
23
+
24
+ # Add class documentation here
25
+ class Mexico::FileSystem::Head
26
+
27
+ include ::ROXML
28
+ xml_name 'Head'
29
+
30
+ # many HeadSections with keys
31
+ xml_accessor :sections, :as => [::Mexico::FileSystem::Section], :from => "Section"
32
+
33
+ end
@@ -0,0 +1,46 @@
1
+ # This file is part of the MExiCo gem.
2
+ # Copyright (c) 2012-2014 Peter Menke, SFB 673, Universität Bielefeld
3
+ # http://www.sfb673.org
4
+ #
5
+ # MExiCo is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as
7
+ # published by the Free Software Foundation, either version 3 of
8
+ # the License, or (at your option) any later version.
9
+ #
10
+ # MExiCo is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with MExiCo. If not, see
17
+ # <http://www.gnu.org/licenses/>.
18
+
19
+ # The +IdRef+ module provides a simple mechanism to map IDREF attributes
20
+ # in an XML document to Ruby objects that are stored elsewhere in the
21
+ # object tree. They are retrieved and accessed via the central corpus
22
+ # object.
23
+ module Mexico::FileSystem::IdRef
24
+
25
+ # Defines a foreign key reference for an object. By default, it will
26
+ # refer to the corresponding collection in the top-level corpus, and
27
+ # it will retrieve the object via its +identifier+ field.
28
+ def id_ref(field_name)
29
+
30
+ pluralized_field_name = "#{field_name}s"
31
+ field_name_id = "#{field_name}_id"
32
+
33
+ define_method field_name do
34
+ inst_var = instance_variable_get("@#{field_name}")
35
+ inst_var = instance_variable_set("@#{field_name}", @corpus.send(pluralized_field_name).find{|x| x.identifier==instance_variable_get("@#{field_name_id}") }) if inst_var.nil?
36
+ return inst_var
37
+ end
38
+
39
+ define_method "#{field_name}=" do |param|
40
+ instance_variable_set("@#{field_name_id}", param.identifier)
41
+ instance_variable_set("@#{field_name}", param)
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ class Mexico::FileSystem::ImplicitItemLink
4
+
5
+ attr_accessor :role
6
+ attr_accessor :target_object
7
+ attr_accessor :item
8
+
9
+ def initialize(args={})
10
+ args.each do |k,v|
11
+ if self.respond_to?("#{k}=")
12
+ send("#{k}=", v)
13
+ end
14
+ end
15
+ end
16
+
17
+ alias_method :target_item, :target_object
18
+
19
+ end
@@ -0,0 +1,84 @@
1
+ # This file is part of the MExiCo gem.
2
+ # Copyright (c) 2012-2014 Peter Menke, SFB 673, Universität Bielefeld
3
+ # http://www.sfb673.org
4
+ #
5
+ # MExiCo is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as
7
+ # published by the Free Software Foundation, either version 3 of
8
+ # the License, or (at your option) any later version.
9
+ #
10
+ # MExiCo is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with MExiCo. If not, see
17
+ # <http://www.gnu.org/licenses/>.
18
+
19
+ # a link that targets an interval out of a scale object.
20
+ class Mexico::FileSystem::IntervalLink
21
+ include ROXML
22
+
23
+ xml_name "IntervalLink"
24
+
25
+ # identifier
26
+ xml_accessor :identifier, :from => '@id'
27
+
28
+ # type Float
29
+ xml_accessor :min, :as => Float, :from => "@min"
30
+
31
+ # type Float
32
+ xml_accessor :max, :as => Float, :from => "@max"
33
+
34
+ # type String
35
+ xml_accessor :role, :from => '@role'
36
+
37
+ # type String
38
+ xml_accessor :target, :from => "@target"
39
+
40
+ attr_accessor :item
41
+ attr_accessor :document
42
+
43
+
44
+ # POSEIdON-based RDF augmentation
45
+ include Poseidon
46
+ self_uri %q(http://cats.sfb673.org/PointLink)
47
+ instance_uri_scheme %q(#{document.self_uri}##{identifier})
48
+ rdf_property :identifier, %q(http://cats.sfb673.org/identifier)
49
+ rdf_property :role, %q(http://cats.sfb673.org/role)
50
+ rdf_property :min, %q(http://cats.sfb673.org/min)
51
+ rdf_property :max, %q(http://cats.sfb673.org/max)
52
+ rdf_property :target, %q(http://cats.sfb673.org/target), :value_expression => 'RDF::URI(target_object.self_uri)'
53
+
54
+
55
+ def initialize(args={})
56
+ args.each do |k,v|
57
+ if self.respond_to?("#{k}=")
58
+ send("#{k}=", v)
59
+ end
60
+ end
61
+ end
62
+
63
+ # returns the target object, in this case, a Scale.
64
+ # @return (Mexico::FileSystem::Scale) the scale this interval link points to.
65
+ def target_object
66
+ @target_object
67
+ end
68
+
69
+ # Sets a new target object (and updates the corresponding identifier)
70
+ # @param (Mexico::FileSystem::Scale) new_target The new target object to set
71
+ # @return (void)
72
+ def target_object=(new_target)
73
+ @target_object=new_target
74
+ @target=target_object.identifier
75
+ end
76
+
77
+ # This method attempts to link objects from other locations of the XML/object tree
78
+ # into position inside this object, by following the xml ids given in the
79
+ # appropriate fields of this class.
80
+ def after_parse
81
+
82
+ end
83
+
84
+ end