Class: AssemblyAI::Transcripts::SentimentAnalysisResult
- Inherits:
-
Object
- Object
- AssemblyAI::Transcripts::SentimentAnalysisResult
- Defined in:
- lib/assemblyai/transcripts/types/sentiment_analysis_result.rb
Overview
The result of the Sentiment Analysis model
Constant Summary collapse
- OMIT =
Object.new
Instance Attribute Summary collapse
-
#additional_properties ⇒ OpenStruct
readonly
Additional properties unmapped to the current class definition.
-
#channel ⇒ String
readonly
The channel of this utterance.
-
#confidence ⇒ Float
readonly
The confidence score for the detected sentiment of the sentence, from 0 to 1.
-
#end_ ⇒ Integer
readonly
The ending time, in milliseconds, of the sentence.
-
#sentiment ⇒ AssemblyAI::Transcripts::Sentiment
readonly
The detected sentiment for the sentence, one of POSITIVE, NEUTRAL, NEGATIVE.
-
#speaker ⇒ String
readonly
The speaker of the sentence if [Speaker Diarization](www.assemblyai.com/docs/models/speaker-diarization) is enabled, else null.
-
#start ⇒ Integer
readonly
The starting time, in milliseconds, of the sentence.
-
#text ⇒ String
readonly
The transcript of the sentence.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ AssemblyAI::Transcripts::SentimentAnalysisResult
Deserialize a JSON object to an instance of SentimentAnalysisResult.
-
.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.
Instance Method Summary collapse
- #initialize(text:, start:, end_:, sentiment:, confidence:, channel: OMIT, speaker: OMIT, additional_properties: nil) ⇒ AssemblyAI::Transcripts::SentimentAnalysisResult constructor
-
#to_json(*_args) ⇒ String
Serialize an instance of SentimentAnalysisResult to a JSON object.
Constructor Details
#initialize(text:, start:, end_:, sentiment:, confidence:, channel: OMIT, speaker: OMIT, additional_properties: nil) ⇒ AssemblyAI::Transcripts::SentimentAnalysisResult
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/assemblyai/transcripts/types/sentiment_analysis_result.rb', line 48 def initialize(text:, start:, end_:, sentiment:, confidence:, channel: OMIT, speaker: OMIT, additional_properties: nil) @text = text @start = start @end_ = end_ @sentiment = sentiment @confidence = confidence @channel = channel if channel != OMIT @speaker = speaker if speaker != OMIT @additional_properties = additional_properties @_field_set = { "text": text, "start": start, "end": end_, "sentiment": sentiment, "confidence": confidence, "channel": channel, "speaker": speaker }.reject do |_k, v| v == OMIT end end |
Instance Attribute Details
#additional_properties ⇒ OpenStruct (readonly)
Returns Additional properties unmapped to the current class definition.
29 30 31 |
# File 'lib/assemblyai/transcripts/types/sentiment_analysis_result.rb', line 29 def additional_properties @additional_properties end |
#channel ⇒ String (readonly)
Returns The channel of this utterance. The left and right channels are channels 1 and 2. Additional channels increment the channel number sequentially.
23 24 25 |
# File 'lib/assemblyai/transcripts/types/sentiment_analysis_result.rb', line 23 def channel @channel end |
#confidence ⇒ Float (readonly)
Returns The confidence score for the detected sentiment of the sentence, from 0 to 1.
20 21 22 |
# File 'lib/assemblyai/transcripts/types/sentiment_analysis_result.rb', line 20 def confidence @confidence end |
#end_ ⇒ Integer (readonly)
Returns The ending time, in milliseconds, of the sentence.
16 17 18 |
# File 'lib/assemblyai/transcripts/types/sentiment_analysis_result.rb', line 16 def end_ @end_ end |
#sentiment ⇒ AssemblyAI::Transcripts::Sentiment (readonly)
Returns The detected sentiment for the sentence, one of POSITIVE, NEUTRAL, NEGATIVE.
18 19 20 |
# File 'lib/assemblyai/transcripts/types/sentiment_analysis_result.rb', line 18 def sentiment @sentiment end |
#speaker ⇒ String (readonly)
Returns The speaker of the sentence if [Speaker Diarization](www.assemblyai.com/docs/models/speaker-diarization) is enabled, else null.
27 28 29 |
# File 'lib/assemblyai/transcripts/types/sentiment_analysis_result.rb', line 27 def speaker @speaker end |
#start ⇒ Integer (readonly)
Returns The starting time, in milliseconds, of the sentence.
14 15 16 |
# File 'lib/assemblyai/transcripts/types/sentiment_analysis_result.rb', line 14 def start @start end |
#text ⇒ String (readonly)
Returns The transcript of the sentence.
12 13 14 |
# File 'lib/assemblyai/transcripts/types/sentiment_analysis_result.rb', line 12 def text @text end |
Class Method Details
.from_json(json_object:) ⇒ AssemblyAI::Transcripts::SentimentAnalysisResult
Deserialize a JSON object to an instance of SentimentAnalysisResult
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/assemblyai/transcripts/types/sentiment_analysis_result.rb', line 75 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) text = struct["text"] start = struct["start"] end_ = struct["end"] sentiment = struct["sentiment"] confidence = struct["confidence"] channel = struct["channel"] speaker = struct["speaker"] new( text: text, start: start, end_: end_, sentiment: sentiment, confidence: confidence, channel: channel, speaker: speaker, 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.
109 110 111 112 113 114 115 116 117 |
# File 'lib/assemblyai/transcripts/types/sentiment_analysis_result.rb', line 109 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.start.is_a?(Integer) != false || raise("Passed value for field obj.start is not the expected type, validation failed.") obj.end_.is_a?(Integer) != false || raise("Passed value for field obj.end_ is not the expected type, validation failed.") obj.sentiment.is_a?(AssemblyAI::Transcripts::Sentiment) != false || raise("Passed value for field obj.sentiment is not the expected type, validation failed.") obj.confidence.is_a?(Float) != false || raise("Passed value for field obj.confidence is not the expected type, validation failed.") obj.channel&.is_a?(String) != false || raise("Passed value for field obj.channel is not the expected type, validation failed.") obj.speaker&.is_a?(String) != false || raise("Passed value for field obj.speaker is not the expected type, validation failed.") end |
Instance Method Details
#to_json(*_args) ⇒ String
Serialize an instance of SentimentAnalysisResult to a JSON object
99 100 101 |
# File 'lib/assemblyai/transcripts/types/sentiment_analysis_result.rb', line 99 def to_json(*_args) @_field_set&.to_json end |