38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/mexico/fiesta/interfaces/elan_interface.rb', line 38
def import(io=$stdin, params = {})
puts 'instance method import'
encoding = params.has_key?(:encoding) ? params[:encoding] : 'UTF-8'
xmldoc = ::Nokogiri::XML(io)
document = Mexico::FileSystem::FiestaDocument.new
timeline = document.add_standard_timeline('s')
timeslots = Hash.new
xmldoc.xpath("//TIME_ORDER/TIME_SLOT").each do |t|
slot = t["TIME_SLOT_ID"]
val = t["TIME_VALUE"].to_i
timeslots[slot] = val
end
layerHash = Hash.new
xmldoc.xpath("//TIER").each do |t|
tierID = t["TIER_ID"]
puts 'Read layers, %s' % tierID
layer = Mexico::FileSystem::Layer.new(identifier: tierID,
name: tierID,
document: document)
document.layers << layer
puts t.attributes
puts t.attributes.has_key?('PARENT_REF')
if t.attributes.has_key?('PARENT_REF')
document.layers.each do |l|
puts "LAYER %s %s" % [l.identifier, l.name]
end
parent_layer = document.get_layer_by_id(t['PARENT_REF'])
puts parent_layer
if parent_layer
layer_connector = Mexico::FileSystem::LayerConnector.new parent_layer, layer, {
identifier: "#{parent_layer.identifier}_TO_#{layer.identifier}",
role: 'PARENT_CHILD',
document: document
}
document.add_layer_connector(layer_connector)
end
end
layerHash[tierID] = layer
t.xpath("./ANNOTATION").each do |annoContainer|
annoContainer.xpath("child::*").each do |anno|
annoVal = anno.xpath("./ANNOTATION_VALUE/text()").first.to_s
i = document.add_item identifier: anno["ANNOTATION_ID"]
if anno.name == "ALIGNABLE_ANNOTATION"
if annoVal!=nil && annoVal.strip != ""
i.add_interval_link Mexico::FileSystem::IntervalLink.new(identifier: "#{i.identifier}-int",
min: timeslots[anno["TIME_SLOT_REF1"]].to_f,
max: timeslots[anno["TIME_SLOT_REF2"]].to_f,
target_object: timeline)
end
end
if anno.name == "REF_ANNOTATION"
puts pp anno
puts document.items.collect{|x| x.identifier}.join(', ')
puts '-'*80
i.add_item_link Mexico::FileSystem::ItemLink.new(identifier: "#{i.identifier}-itm",
target_object: document.items({identifier: anno["ANNOTATION_REF"]}).first,
role: Mexico::FileSystem::ItemLink::ROLE_PARENT)
end
i.add_layer_link Mexico::FileSystem::LayerLink.new(identifier: "#{i.identifier}-lay",
target_object: layer)
i.data = Mexico::FileSystem::Data.new(string_value: annoVal)
end
end
end
puts 'instance method over'
document
end
|