Class: AssemblyAI::Transcripts::TopicDetectionResult

Inherits:
Object
  • Object
show all
Defined in:
lib/assemblyai/transcripts/types/topic_detection_result.rb

Overview

The result of the topic detection model

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:, labels: OMIT, timestamp: OMIT, additional_properties: nil) ⇒ AssemblyAI::Transcripts::TopicDetectionResult

Parameters:



31
32
33
34
35
36
37
38
39
# File 'lib/assemblyai/transcripts/types/topic_detection_result.rb', line 31

def initialize(text:, labels: OMIT, timestamp: OMIT, additional_properties: nil)
  @text = text
  @labels = labels if labels != OMIT
  @timestamp = timestamp if timestamp != OMIT
  @additional_properties = additional_properties
  @_field_set = { "text": text, "labels": labels, "timestamp": timestamp }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



19
20
21
# File 'lib/assemblyai/transcripts/types/topic_detection_result.rb', line 19

def additional_properties
  @additional_properties
end

#labelsArray<AssemblyAI::Transcripts::TopicDetectionResultLabelsItem> (readonly)

Returns An array of detected topics in the text.

Returns:



15
16
17
# File 'lib/assemblyai/transcripts/types/topic_detection_result.rb', line 15

def labels
  @labels
end

#textString (readonly)

Returns The text in the transcript in which a detected topic occurs.

Returns:

  • (String)

    The text in the transcript in which a detected topic occurs



13
14
15
# File 'lib/assemblyai/transcripts/types/topic_detection_result.rb', line 13

def text
  @text
end

#timestampAssemblyAI::Transcripts::Timestamp (readonly)



17
18
19
# File 'lib/assemblyai/transcripts/types/topic_detection_result.rb', line 17

def timestamp
  @timestamp
end

Class Method Details

.from_json(json_object:) ⇒ AssemblyAI::Transcripts::TopicDetectionResult

Deserialize a JSON object to an instance of TopicDetectionResult

Parameters:

  • json_object (String)

Returns:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/assemblyai/transcripts/types/topic_detection_result.rb', line 45

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  text = struct["text"]
  labels = parsed_json["labels"]&.map do |v|
    v = v.to_json
    AssemblyAI::Transcripts::TopicDetectionResultLabelsItem.from_json(json_object: v)
  end
  if parsed_json["timestamp"].nil?
    timestamp = nil
  else
    timestamp = parsed_json["timestamp"].to_json
    timestamp = AssemblyAI::Transcripts::Timestamp.from_json(json_object: timestamp)
  end
  new(
    text: text,
    labels: labels,
    timestamp: timestamp,
    additional_properties: struct
  )
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given

hash and check each fields type against the current object's property
definitions.

Parameters:

  • obj (Object)

Returns:

  • (Void)


80
81
82
83
84
# File 'lib/assemblyai/transcripts/types/topic_detection_result.rb', line 80

def self.validate_raw(obj:)
  obj.text.is_a?(String) != false || raise("Passed value for field obj.text is not the expected type, validation failed.")
  obj.labels&.is_a?(Array) != false || raise("Passed value for field obj.labels is not the expected type, validation failed.")
  obj.timestamp.nil? || AssemblyAI::Transcripts::Timestamp.validate_raw(obj: obj.timestamp)
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of TopicDetectionResult to a JSON object

Returns:

  • (String)


70
71
72
# File 'lib/assemblyai/transcripts/types/topic_detection_result.rb', line 70

def to_json(*_args)
  @_field_set&.to_json
end