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,166 @@
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 basic data unit object.
20
+ class Mexico::FileSystem::Item
21
+
22
+ include ::ROXML
23
+ xml_name 'I'
24
+
25
+ xml_accessor :identifier, :from => '@id'
26
+
27
+ # @todo compound links (later)
28
+
29
+ # collection of Mexico::FileSystem::ItemLink
30
+ xml_accessor :explicit_item_links, :as => [Mexico::FileSystem::ItemLink], :from => "ItemLink", :in => "Links"
31
+
32
+ # collection of Mexico::FileSystem::LayerLink
33
+ xml_accessor :layer_links, :as => [Mexico::FileSystem::LayerLink], :from => "LayerLink", :in => "Links"
34
+
35
+ # collection of Mexico::FileSystem::PointLink
36
+ xml_accessor :point_links, :as => [Mexico::FileSystem::PointLink], :from => "PointLink", :in => "Links"
37
+
38
+ # collection of Mexico::FileSystem::IntervalLink
39
+ xml_accessor :interval_links, :as => [Mexico::FileSystem::IntervalLink], :from => "IntervalLink", :in => "Links"
40
+
41
+ # collection of Mexico::FileSystem::Data
42
+ xml_accessor :data, :as => Mexico::FileSystem::Data, :from => "Data"
43
+
44
+ attr_accessor :document
45
+
46
+ attr_accessor :implicit_item_links
47
+
48
+ # POSEIdON-based RDF augmentation
49
+ include Poseidon
50
+ self_uri %q(http://cats.sfb673.org/Item)
51
+ instance_uri_scheme %q(#{document.self_uri}##{identifier})
52
+ rdf_property :identifier, %q(http://cats.sfb673.org/identifier)
53
+ rdf_property :name, %q(http://cats.sfb673.org/name)
54
+
55
+ rdf_include :layer_links, %q(http://cats.sfb673.org/hasLayerLink)
56
+ rdf_include :item_links, %q(http://cats.sfb673.org/hasItemLink)
57
+ rdf_include :point_links, %q(http://cats.sfb673.org/hasPointLink)
58
+ rdf_include :interval_links, %q(http://cats.sfb673.org/hasIntervalLink)
59
+ rdf_include :data, %q(http://cats.sfb673.org/hasData)
60
+
61
+ def initialize(args={})
62
+ args.each do |k,v|
63
+ if self.respond_to?("#{k}=")
64
+ send("#{k}=", v)
65
+ end
66
+ end
67
+ @explicit_item_links = []
68
+ @implicit_item_links = []
69
+ @inverse_linked_items = []
70
+ @layer_links = []
71
+ @point_links = []
72
+ @interval_links = []
73
+ end
74
+
75
+ # This method attempts to link objects from other locations of the XML/object tree
76
+ # into position inside this object, by following the xml ids given in the
77
+ # appropriate fields of this class.
78
+ def after_parse
79
+ # store self
80
+ ::Mexico::FileSystem::FiestaDocument.store(self.identifier, self)
81
+
82
+ [item_links,layer_links,point_links,interval_links].flatten.each do |link|
83
+ link.item = self
84
+
85
+ if ::Mexico::FileSystem::FiestaDocument.knows?(link.target)
86
+ link.target_object=::Mexico::FileSystem::FiestaDocument.resolve(link.target)
87
+ else
88
+ # store i in watch list
89
+ ::Mexico::FileSystem::FiestaDocument.watch(link.target, link, :target_object=)
90
+ end
91
+
92
+ end
93
+
94
+ end
95
+
96
+ def item_links
97
+ @explicit_item_links + @implicit_item_links
98
+ end
99
+
100
+ def add_inverse_linked_item(item)
101
+ @inverse_linked_items << item
102
+ end
103
+
104
+ def add_item_link(new_item_link)
105
+ # add the item link
106
+ add_explicit_item_link(new_item_link)
107
+
108
+ other_item = new_item_link.target_item
109
+
110
+ # add an inverse item link for _every_ item link
111
+ # this is for retrieving item links from the other direction
112
+ other_item.add_inverse_linked_item(self)
113
+
114
+ # if an inverse relation for the role exists,
115
+ # puts Mexico::FileSystem::ItemLink::INVERSE_ROLES.has_key?(new_item_link.role)
116
+ if Mexico::FileSystem::ItemLink::INVERSE_ROLES.has_key?(new_item_link.role)
117
+ # add an implicit link for this inverse relation
118
+ # puts new_item_link.target_item
119
+
120
+ other_item.add_implicit_item_link Mexico::FileSystem::ImplicitItemLink.new(
121
+ role: Mexico::FileSystem::ItemLink::INVERSE_ROLES[new_item_link.role],
122
+ target_object: self, item: other_item )
123
+ end
124
+ end
125
+
126
+ def add_explicit_item_link(new_item_link)
127
+ @explicit_item_links << new_item_link
128
+ end
129
+
130
+ def add_implicit_item_link(new_item_link)
131
+ @implicit_item_links << new_item_link
132
+ end
133
+
134
+ def add_point_link(new_point_link)
135
+ @point_links << new_point_link
136
+ end
137
+
138
+
139
+ def add_interval_link(new_interval_link)
140
+ @interval_links << new_interval_link
141
+ end
142
+
143
+
144
+ def add_layer_link(new_layer_link)
145
+ @layer_links << new_layer_link
146
+ end
147
+
148
+ def layers
149
+ #puts layer_links.collect{|l| l.target}.join
150
+ #puts layer_links.collect{|l| l.target.class }.join
151
+ layer_links.collect{|l| l.layer }
152
+ end
153
+
154
+ # Retrieves all items that act as a source (or predecessor)
155
+ # in the item link graph.
156
+ def sources
157
+ @inverse_linked_items
158
+ end
159
+
160
+ # Retrieves all items that act as a target (or successor)
161
+ # in the item link graph.
162
+ def targets
163
+ item_links.collect{|l| l.target_object }
164
+ end
165
+
166
+ end
@@ -0,0 +1,98 @@
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 from an item to a layer.
20
+ class Mexico::FileSystem::ItemLink
21
+
22
+ ROLE_PARENT = 'parent'
23
+ ROLE_CHILD = 'child'
24
+ ROLE_PREDECESSOR = 'predecessor'
25
+ ROLE_SUCCESSOR = 'successor'
26
+
27
+ INVERSE_ROLES = {
28
+ ROLE_PARENT => ROLE_CHILD,
29
+ ROLE_CHILD => ROLE_PARENT,
30
+ ROLE_PREDECESSOR => ROLE_SUCCESSOR,
31
+ ROLE_SUCCESSOR => ROLE_PREDECESSOR
32
+ }
33
+
34
+ include ::ROXML
35
+ xml_name 'ItemLink'
36
+
37
+ # identifier
38
+ xml_accessor :identifier, :from => '@id'
39
+
40
+ # type String
41
+ xml_accessor :role, :from => '@role'
42
+
43
+ # type String
44
+ xml_accessor :target, :from => "@target"
45
+
46
+ attr_accessor :item
47
+ attr_accessor :document
48
+
49
+ # POSEIdON-based RDF augmentation
50
+ include Poseidon
51
+ self_uri %q(http://cats.sfb673.org/ItemLink)
52
+ instance_uri_scheme %q(#{document.self_uri}##{identifier})
53
+ rdf_property :identifier, %q(http://cats.sfb673.org/identifier)
54
+ rdf_property :role, %q(http://cats.sfb673.org/role)
55
+ rdf_property :target, %q(http://cats.sfb673.org/target), :value_expression => 'RDF::URI(target_object.self_uri)'
56
+
57
+ def initialize(args={})
58
+ args.each do |k,v|
59
+ if self.respond_to?("#{k}=")
60
+ send("#{k}=", v)
61
+ end
62
+ end
63
+ end
64
+
65
+ # returns the target object, in this case, an Item.
66
+ # @return (Mexico::FileSystem::Item) the scale this interval link points to.
67
+ def target_object
68
+ @target_object
69
+ end
70
+
71
+ # Sets a new target object (and updates the corresponding identifier)
72
+ # @param (Mexico::FileSystem::Item) new_target The new target object to set
73
+ # @return (void)
74
+ def target_object=(new_target)
75
+ # puts "SETTING target object to %s, %s" % [new_target.identifier, new_target]
76
+ @target_object=new_target
77
+ @target=target_object.identifier
78
+ end
79
+
80
+ # This method attempts to link objects from other locations of the XML/object tree
81
+ # into position inside this object, by following the xml ids given in the
82
+ # appropriate fields of this class.
83
+ def after_parse
84
+ # puts "item link after parse. What is the situation?"
85
+ #
86
+ # if ::Mexico::FileSystem::FiestaDocument.knows?(target)
87
+ # puts " store knows the needed target. fetch it and set it."
88
+ # @target_object=::Mexico::FileSystem::FiestaDocument.resolve(target)
89
+ # puts " %s" % @target_object
90
+ # else
91
+ # # store i in watch list
92
+ # ::Mexico::FileSystem::FiestaDocument.watch(target, item, :target_object=)
93
+ # end
94
+ end
95
+
96
+ alias_method :target_item, :target_object
97
+
98
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ class Mexico::FileSystem::ItemLinksProxy < Array
4
+
5
+ def initialize(parent_item)
6
+ @item = parent_item
7
+ end
8
+
9
+ def <<(item_link)
10
+ @item.add_item_link(item_link)
11
+ end
12
+
13
+ end
@@ -0,0 +1,89 @@
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 layer (or tier) in an transcription or annotation document.
20
+ class ::Mexico::FileSystem::Layer
21
+
22
+ include ROXML
23
+
24
+ xml_accessor :identifier, :from => '@id'
25
+ xml_accessor :name, :from => '@name'
26
+
27
+ attr_accessor :document
28
+
29
+ # POSEIdON-based RDF augmentation
30
+ include Poseidon
31
+ self_uri %q(http://cats.sfb673.org/Layer)
32
+ instance_uri_scheme %q(#{document.self_uri}##{identifier})
33
+ rdf_property :identifier, %q(http://cats.sfb673.org/identifier)
34
+ rdf_property :name, %q(http://cats.sfb673.org/name)
35
+
36
+
37
+ # data type
38
+ # content structure
39
+
40
+ def initialize(args={})
41
+ args.each do |k,v|
42
+ if self.respond_to?("#{k}=")
43
+ send("#{k}=", v)
44
+ end
45
+ end
46
+ end
47
+
48
+ def items
49
+ @document.items.select{|i| i.layers.include?(self) }
50
+ end
51
+
52
+ # overrides method in ROXML
53
+ # callback after xml parsing process, to store this element in the
54
+ # document cache.
55
+ def after_parse
56
+ ::Mexico::FileSystem::FiestaDocument.store(self.identifier, self)
57
+ end
58
+
59
+ # returns all layers that are linked to this layer such that this layer
60
+ # is the target, and the result layer is the source.
61
+ def predecessor_layers
62
+ document.layer_connectors.select{|c| c.target==self}.collect{|c| [c.source, c.role]}
63
+ end
64
+
65
+ # returns all layers that are linked to this layer such that this layer
66
+ # is the source, and the result layer is the target.
67
+ def successor_layers
68
+ document.layer_connectors.select{|c| c.source==self}.collect{|c| [c.target, c.role]}
69
+ end
70
+
71
+ def items_form_a_forest?
72
+
73
+ # I need precise semantics what kinds of item links
74
+ # are supposed to model an actual parent-child-relationship.
75
+ self.items.each do |item|
76
+ puts "sources size for items %s: %i" % [item.identifier, item.sources.size]
77
+ return false if item.sources.size > 1
78
+ end
79
+ return true
80
+ end
81
+
82
+ def items_form_an_edgeless_graph?
83
+ self.items.each do |item|
84
+ return false if item.item_links.size > 1
85
+ end
86
+ end
87
+
88
+
89
+ end
@@ -0,0 +1,74 @@
1
+ # encoding: utf-8
2
+ # This file is part of the MExiCo gem.
3
+ # Copyright (c) 2012-2014 Peter Menke, SFB 673, Universität Bielefeld
4
+ # http://www.sfb673.org
5
+ #
6
+ # MExiCo is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as
8
+ # published by the Free Software Foundation, either version 3 of
9
+ # the License, or (at your option) any later version.
10
+ #
11
+ # MExiCo is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with MExiCo. If not, see
18
+ # <http://www.gnu.org/licenses/>.
19
+
20
+ # A typed connector between two layers (or tiers) in an transcription or annotation document.
21
+ class Mexico::FileSystem::LayerConnector
22
+
23
+ include ROXML
24
+
25
+ xml_accessor :identifier, :from => '@id'
26
+ xml_accessor :name, :from => '@name'
27
+
28
+ xml_accessor :source_id, :from => '@source'
29
+ xml_accessor :target_id, :from => '@target'
30
+
31
+ xml_accessor :role, :from => '@role'
32
+
33
+ attr_accessor :document
34
+
35
+
36
+ def initialize(new_source, new_target, args={})
37
+ self.source= new_source
38
+ self.target= new_target
39
+ args.each do |k,v|
40
+ if self.respond_to?("#{k}=")
41
+ send("#{k}=", v)
42
+ end
43
+ end
44
+ end
45
+
46
+ # Retrieves the source layer for this layer connector.
47
+ # @return [Layer] The source layer.
48
+ def source
49
+ @source
50
+ end
51
+
52
+ # Sets a new source layer for this layer connector.
53
+ # @param new_source_layer [Layer] The layer to be set as the new source.
54
+ # @return [void]
55
+ def source=(new_source_layer)
56
+ @source = new_source_layer
57
+ @source_id = @source.identifier
58
+ end
59
+
60
+ # Retrieves the target layer for this layer connector.
61
+ # @return [Layer] The target layer.
62
+ def target
63
+ @target
64
+ end
65
+
66
+ # Sets a new target layer for this layer connector.
67
+ # @param new_target_layer [Layer] The layer to be set as the new target.
68
+ # @return [void]
69
+ def target=(new_target_layer)
70
+ @target = new_target_layer
71
+ @target_id = @target.identifier
72
+ end
73
+
74
+ end
@@ -0,0 +1,75 @@
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 from an item to a layer.
20
+ class Mexico::FileSystem::LayerLink
21
+
22
+ include ::ROXML
23
+ xml_name 'LayerLink'
24
+
25
+ # identifier
26
+ xml_accessor :identifier, :from => '@id'
27
+
28
+ xml_accessor :role, :from => '@role'
29
+
30
+ xml_accessor :target, :from => "@target"
31
+
32
+ attr_accessor :item
33
+ attr_accessor :document
34
+
35
+ # POSEIdON-based RDF augmentation
36
+ include Poseidon
37
+ self_uri %q(http://cats.sfb673.org/LayerLink)
38
+ instance_uri_scheme %q(#{document.self_uri}##{identifier})
39
+ rdf_property :identifier, %q(http://cats.sfb673.org/identifier)
40
+ rdf_property :role, %q(http://cats.sfb673.org/role)
41
+ rdf_property :target, %q(http://cats.sfb673.org/target), :value_expression => 'RDF::URI(target_object.self_uri)'
42
+
43
+
44
+ def initialize(args={})
45
+ args.each do |k,v|
46
+ if self.respond_to?("#{k}=")
47
+ send("#{k}=", v)
48
+ end
49
+ end
50
+ end
51
+
52
+ # returns the target object, in this case, a Layer.
53
+ # @return (Mexico::FileSystem::Layer) the scale this interval link points to.
54
+ def target_object
55
+ @target_object
56
+ end
57
+
58
+ # Sets a new target object (and updates the corresponding identifier)
59
+ # @param (Mexico::FileSystem::Layer) new_target The new target object to set
60
+ # @return (void)
61
+ def target_object=(new_target)
62
+ @target_object=new_target
63
+ @target=@target_object.identifier
64
+ end
65
+
66
+ # This method attempts to link objects from other locations of the XML/object tree
67
+ # into position inside this object, by following the xml ids given in the
68
+ # appropriate fields of this class.
69
+ def after_parse
70
+
71
+ end
72
+
73
+ alias_method :layer, :target_object
74
+
75
+ end
@@ -0,0 +1,101 @@
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
+ require 'poseidon'
20
+
21
+ # A LocalFile object represents a file on a local file system, with additional
22
+ # information
23
+ class Mexico::FileSystem::LocalFile
24
+
25
+ include Mexico::FileSystem::BoundToCorpus
26
+ extend Mexico::FileSystem::IdRef
27
+ extend Mexico::FileSystem::StaticCollectionRef
28
+
29
+ include ::ROXML
30
+
31
+ # identifier
32
+ xml_accessor :identifier, :from => '@identifier'
33
+
34
+ # type String
35
+ xml_accessor :name, :from => '@name'
36
+
37
+ # type String
38
+ xml_accessor :description, :from => 'Description'
39
+
40
+ # type String
41
+ xml_accessor :path, :from => "@path"
42
+
43
+
44
+ # POSEIdON-based RDF augmentation
45
+ include Poseidon
46
+ self_uri %q(http://cats.sfb673.org/LocalFile)
47
+ instance_uri_scheme %q(http://phoibos.sfb673.org/corpora/#{corpus.identifier}/local_files/#{identifier})
48
+ rdf_property :identifier, %q(http://cats.sfb673.org/identifier)
49
+ rdf_property :name, %q(http://cats.sfb673.org/name)
50
+ rdf_property :description, %q(http://cats.sfb673.org/description)
51
+ rdf_property :path, %q(http://cats.sfb673.org/path)
52
+
53
+
54
+ # Creates a new local file object.
55
+ # @option opts [String] :identifier The identifier of the new design (required).
56
+ # @option opts [String] :name The name of the new design. (required).
57
+ # @option opts [String] :description A description of the new design (optional).
58
+ def initialize(opts={})
59
+ [:identifier,:name,:description].each do |att|
60
+ send("#{att}=", opts[att]) if opts.has_key?(att)
61
+ end
62
+ end
63
+
64
+ # Resolves any relative path given in the path field, and returns an absolute
65
+ # path suited for the current operating system.
66
+ # @return (String) a string containing the absolute path to the file.
67
+ def absolute_path
68
+ if path.starts_with? "."
69
+ return File.expand_path(File.join(@corpus.base_path, path))
70
+ end
71
+ return path
72
+ end
73
+
74
+ # Indicates whether the file described at the path actually exists.
75
+ # @return (Boolean) +true+ if the described file exists, +false+ otherwise.
76
+ def file_exists?
77
+ return false if path.blank?
78
+ File.exists?(absolute_path)
79
+ end
80
+
81
+ # Returns a file object for this {LocalFile} object.
82
+ # @return (File) a file object for the described file, or +nil+ if there is no readable file at that location.
83
+ def file_handle
84
+ return nil if path.blank?
85
+ return File.open(absolute_path)
86
+ end
87
+
88
+ # Returns the size of the file (in bytes).
89
+ # @return (Integer) the size of the file in bytes, or +nil+ if no file can be found.
90
+ def file_size
91
+ return nil if path.blank?
92
+ return File.size(absolute_path)
93
+ end
94
+
95
+
96
+ # This method performs additional linking and cleanup after parsing a XML representation.
97
+ def after_parse
98
+ # puts "Parsed LocalFile"
99
+ end
100
+
101
+ end
@@ -0,0 +1,69 @@
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
+ # Participant Roles describe the nature of the associated participant:
20
+ # Possible values are, e.g., naive participants, confederates,
21
+ # experimenters, etc.
22
+ class Mexico::FileSystem::Participant
23
+
24
+ include Mexico::FileSystem::BoundToCorpus
25
+ extend Mexico::FileSystem::IdRef
26
+
27
+ include ::ROXML
28
+
29
+ xml_accessor :identifier, :from => '@identifier'
30
+ xml_accessor :name, :from => '@name'
31
+ xml_accessor :participant_role_id, :from => '@participant_role_id'
32
+
33
+ xml_accessor :description, :from => "Description"
34
+
35
+
36
+ # def participant_role
37
+ # ::Mexico::Constants::ParticipantRoles.get(participant_role_id)
38
+ # end
39
+
40
+ # def participant_role=(new_participant_role)
41
+ # # check whether param is a string or a participant role object
42
+ # if new_participant_role.kind_of?(String)
43
+ # new_object = ::Mexico::Constants::ParticipantRoles.get(new_participant_role)
44
+ # @participant_role_id=new_participant_role
45
+ # end
46
+ # if new_participant_role.kind_of?(::Mexico::FileSystem::ParticipantRole)
47
+ # unless ::Mexico::Constants::ParticipantRoles.has?(new_participant_role.identifier)
48
+ # # raise exception, this pr isn't available
49
+ # else
50
+ # participant_role_id = new_participant_role.identifier
51
+ # end
52
+ # end
53
+ # end
54
+
55
+ # Creates a new participant object.
56
+ # @option opts [String] :identifier The identifier of the new participant object.
57
+ # @option opts [String] :name The name of the new participant object.
58
+ # @option opts [String] :description The identifier of the new participant object.
59
+ # @option opts [String] :identifier The identifier of the new participant object.
60
+ # @option opts [String] :name The name of the new participant object.
61
+ # @option opts [String] :participant_role The participant role of the new participant object.
62
+ def initialize(opts={})
63
+ # @corpus = corpus
64
+ [:identifier,:name,:description,:participant_role].each do |att|
65
+ send("#{att}=", opts[att]) if opts.has_key?(att)
66
+ end
67
+ end
68
+
69
+ end