Class: Diarize::Segment

Inherits:
Object
  • Object
show all
Includes:
ToRdf
Defined in:
lib/diarize/segment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(audio, start, duration, speaker_gender, bandwidth, speaker_id) ⇒ Segment

Returns a new instance of Segment.



7
8
9
10
11
12
13
14
# File 'lib/diarize/segment.rb', line 7

def initialize(audio, start, duration, speaker_gender, bandwidth, speaker_id)
  @audio          = audio
  @start          = start
  @duration       = duration
  @bandwidth      = bandwidth
  @speaker_id     = speaker_id
  @speaker_gender = speaker_gender
end

Instance Attribute Details

#bandwidthObject (readonly)

Returns the value of attribute bandwidth.



5
6
7
# File 'lib/diarize/segment.rb', line 5

def bandwidth
  @bandwidth
end

#durationObject (readonly)

Returns the value of attribute duration.



5
6
7
# File 'lib/diarize/segment.rb', line 5

def duration
  @duration
end

#speaker_genderObject (readonly)

Returns the value of attribute speaker_gender.



5
6
7
# File 'lib/diarize/segment.rb', line 5

def speaker_gender
  @speaker_gender
end

#speaker_idObject (readonly)

Returns the value of attribute speaker_id.



5
6
7
# File 'lib/diarize/segment.rb', line 5

def speaker_id
  @speaker_id
end

#startObject (readonly)

Returns the value of attribute start.



5
6
7
# File 'lib/diarize/segment.rb', line 5

def start
  @start
end

Instance Method Details

#as_jsonObject Also known as: _as_json



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/diarize/segment.rb', line 43

def as_json
  {
    'start' => start,
    'duration' => duration,
    'gender' => speaker_gender,
    'bandwidth' => bandwidth,
    'speaker_id' => speaker_id
  }.tap {|s|
    s['speaker'] = speaker.as_json if speaker
  }
end

#namespacesObject



20
21
22
# File 'lib/diarize/segment.rb', line 20

def namespaces
  super.merge({'ws' => 'http://wsarchive.prototype0.net/ontology/'})
end

#rdf_mappingObject



33
34
35
36
37
38
39
40
41
# File 'lib/diarize/segment.rb', line 33

def rdf_mapping
  {
    'ws:start' => start,
    'ws:duration' => duration,
    'ws:gender' => speaker_gender,
    'ws:bandwidth' => bandwidth,
    'ws:speaker' => speaker,
  }
end

#speakerObject



16
17
18
# File 'lib/diarize/segment.rb', line 16

def speaker
  Speaker.find_or_create(URI("#{@audio.base_uri}##{@speaker_id}"), @speaker_gender)
end

#to_jsonObject Also known as: _to_json



56
57
58
# File 'lib/diarize/segment.rb', line 56

def to_json
  as_json.to_json
end

#type_uriObject



29
30
31
# File 'lib/diarize/segment.rb', line 29

def type_uri
  'ws:Segment'
end

#uriObject



24
25
26
27
# File 'lib/diarize/segment.rb', line 24

def uri
  # http://www.w3.org/TR/media-frags/
  URI("#{@audio.base_uri}#t=#{start},#{start + duration}")
end