Class: Mexico::Fiesta::Interfaces::ShortTextGridInterface

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

Overview

Import and export interface for Praat’s short text grid format.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

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



31
32
33
# File 'lib/mexico/fiesta/interfaces/short_text_grid_interface.rb', line 31

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

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



26
27
28
29
# File 'lib/mexico/fiesta/interfaces/short_text_grid_interface.rb', line 26

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

Instance Method Details

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



35
36
37
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
# File 'lib/mexico/fiesta/interfaces/short_text_grid_interface.rb', line 35

def import(io=$stdin, params = {})
  puts 'instance method import'
  encoding = params.has_key?(:encoding) ? params[:encoding] : 'UTF-16'

  fdoc = FiestaDocument.new
  timeline = fdoc.add_standard_timeline('s')

  fileType = io.gets.strip
  objectClass = io.gets.strip
  io.gets # blank line
  global_min = io.gets.to_f
  global_max = io.gets.to_f
  io.gets # <exists>

  # get the numbers of tiers in this document.
  numberOfTiers = io.gets.to_i

  numberOfTiers.times do |tierNumber|
    tierType = io.gets.strip
    tierName = Mexico::Util::strip_quotes(io.gets.strip)
    tier_min = io.gets.to_f
    tier_max = io.gets.to_f

    # create layer object from that tier
    #puts "layer constructor before"
    layer = fdoc.add_layer({identifier:tierName, name:tierName})
    #puts "layer constructor done"


    numberOfAnnotations = io.gets.to_i

    numberOfAnnotations.times do |annotationNumber|

      anno_min = io.gets.to_f
      anno_max = io.gets.to_f
      anno_val = io.gets.strip.gsub(/^"/, "").gsub(/"$/, "")

      #puts "  #{anno_val} [#{anno_min}--#{anno_max}]"

      if anno_val.strip != ""

        item = fdoc.add_item({identifier:"l#{tierNumber}a#{annotationNumber}"}) do |i|
          i.add_interval_link IntervalLink.new(
                                  identifier:"#{i.identifier}-il",
                                  min: anno_min,
                                  max: anno_max,
                                  target_object: timeline )
          i.data = Mexico::FileSystem::Data.new(string_value: anno_val)
          i.add_layer_link LayerLink.new(
                               identifier:"#{i.identifier}-ll",
                               target_object: layer )
        end

        puts item

      end

    end

  end

  fdoc
end