Class: Mexico::Fiesta::Interfaces::ElanInterface

Inherits:
Object
  • Object
show all
Includes:
Mexico::FileSystem, Singleton
Defined in:
lib/mexico/fiesta/interfaces/elan_interface.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.export(doc, io = $stdout, params = {}) ⇒ Object



34
35
36
# File 'lib/mexico/fiesta/interfaces/elan_interface.rb', line 34

def self.export(doc, io=$stdout, params = {})
  instance.export(doc, io, params)
end

.import(io = $stdin, params = {}) ⇒ Object



29
30
31
32
# File 'lib/mexico/fiesta/interfaces/elan_interface.rb', line 29

def self.import(io=$stdin, params = {})
  puts 'class method import'
  instance.import(io, params)
end

Instance Method Details

#export(doc, io = $stdout, params = {}) ⇒ Object



138
139
140
# File 'lib/mexico/fiesta/interfaces/elan_interface.rb', line 138

def export(doc, io=$stdout, params = {})

end

#import(io = $stdin, params = {}) ⇒ Object



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

  # 1. create a standard timeline
  timeline = document.add_standard_timeline('s')

  # 2. find time slots, store
  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

  # create temporary hash for storage of layers
  layerHash = Hash.new

  xmldoc.xpath("//TIER").each do |t|

    # @todo (DEFAULT_LOCALE="en") (LINGUISTIC_TYPE_REF="default-lt")
    tierID = t["TIER_ID"]
    puts 'Read layers, %s' % tierID

    layer = Mexico::FileSystem::Layer.new(identifier: tierID,
                                 name: tierID,
                                 document: document)
    #layer.name = tierID
    #layer.id = ToE::Util::to_xml_id(tierID)

    document.layers << layer

    puts t.attributes
    puts t.attributes.has_key?('PARENT_REF')
    if t.attributes.has_key?('PARENT_REF')
      # puts "TATT: %s" % t['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"

          # puts anno.xpath("./ANNOTATION_VALUE/text()").first
          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

    #if t["PARENT_REF"]
    #  parent = layerHash[t["PARENT_REF"]]
    #  if parent
    #    document.layer_connectors << Mexico::FileSystem::LayerConnector.new(parent, layer)
    #    # structure.connect(parent, layer)
    #  end
    #end

  end
  puts 'instance method over'
  document
end