Sha256: a75d55b29b15fc1c8cfbeb1f175945d3ee53750a931ce9da8328049700fbabba

Contents?: true

Size: 932 Bytes

Versions: 5

Compression:

Stored size: 932 Bytes

Contents

# frozen_string_literal: true

# frozen_string_literal

module AzureSTT
  module Parsers
    #
    # Parse the "nBest" field from the result file to a Models::Sentence
    #
    class Sentence < Base
      protected

      #
      # Build the attributes needed to instantiate a Models::Sentence
      #
      # @return [Hash]
      #
      def build_attributes
        {
          confidence: hash['confidence'],
          lexical: hash['lexical'],
          itn: hash['itn'],
          masked_itn: hash['maskedITN'],
          transcript: hash['display'],
          words: build_words
        }.compact
      end

      private

      #
      # Build the words. Returns nil if they are not defined
      #
      # @return [Array[Word]]
      #
      def build_words
        hash['words']&.map do |word_hash|
          Models::Word.new(
            Word.new(word_hash).attributes
          )
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
azure_stt-0.4.0 lib/azure_stt/parsers/sentence.rb
azure_stt-0.3.0 lib/azure_stt/parsers/sentence.rb
azure_stt-0.2.0 lib/azure_stt/parsers/sentence.rb
azure_stt-0.1.1 lib/azure_stt/parsers/sentence.rb
azure_stt-0.1.0 lib/azure_stt/parsers/sentence.rb