Class: Google::Cloud::Translate::V2::Detection

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/translate/v2/detection.rb

Overview

Detection

Represents a detect language query result. Returned by Api#detect.

Examples:

require "google/cloud/translate/v2"

translate = Google::Cloud::Translate::V2.new

detections = translate.detect "chien", "chat"

detections.size #=> 2
detections[0].text #=> "chien"
detections[0].language #=> "fr"
detections[0].confidence #=> 0.7109375
detections[1].text #=> "chat"
detections[1].language #=> "en"
detections[1].confidence #=> 0.59922177

See Also:

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#resultsArray<Detection::Result> (readonly)

The list of detection results for the given text. The most likely language is listed first, and its attributes can be accessed through #language and #confidence.

Returns:



54
55
56
# File 'lib/google/cloud/translate/v2/detection.rb', line 54

def results
  @results
end

#textString (readonly)

The text upon which the language detection was performed.

Returns:

  • (String)


47
48
49
# File 'lib/google/cloud/translate/v2/detection.rb', line 47

def text
  @text
end

Instance Method Details

#confidenceFloat

The confidence that the language detection result is correct. The closer this value is to 1, the higher the confidence in language detection.

Returns:

  • (Float)

    a value between 0 and 1



68
69
70
71
# File 'lib/google/cloud/translate/v2/detection.rb', line 68

def confidence
  return nil if results.empty?
  results.first.confidence
end

#languageString

The most likely language that was detected. This is an ISO 639-1 language code.

Returns:

  • (String)

    the language code



78
79
80
81
# File 'lib/google/cloud/translate/v2/detection.rb', line 78

def language
  return nil if results.empty?
  results.first.language
end