google-cloud-translate-v2 - Class Google::Cloud::Translate::V2::Detection (v0.3.1)

Reference documentation and code samples for the google-cloud-translate-v2 class Google::Cloud::Translate::V2::Detection.

Detection

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

Inherits

  • Object

Example

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

Methods

#confidence

def confidence() -> Float

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

#language

def language() -> String

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

Returns
  • (String) — the language code

#results

def results() -> Array<Detection::Result>

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

#text

def text() -> String

The text upon which the language detection was performed.

Returns
  • (String)