Class: Gcloud::Translate::Detection
- Inherits:
-
Object
- Object
- Gcloud::Translate::Detection
- Defined in:
- lib/gcloud/translate/detection.rb
Overview
# Detection
Represents a detect language query result. Returned by Api#detect.
Defined Under Namespace
Classes: Result
Instance Attribute Summary collapse
-
#results ⇒ Array<Detection::Result>
readonly
The list of detection results for the given text.
-
#text ⇒ String
readonly
The text upon which the language detection was performed.
Class Method Summary collapse
-
.from_gapi(gapi, text) ⇒ Object
defined by the Google API Client object.
Instance Method Summary collapse
-
#confidence ⇒ Float
The confidence that the language detection result is correct.
-
#initialize(text, results) ⇒ Detection
constructor
A new instance of Detection.
-
#language ⇒ String
The most likely language that was detected.
Constructor Details
#initialize(text, results) ⇒ Detection
60 61 62 63 |
# File 'lib/gcloud/translate/detection.rb', line 60 def initialize text, results @text = text @results = results end |
Instance Attribute Details
#results ⇒ Array<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.
56 57 58 |
# File 'lib/gcloud/translate/detection.rb', line 56 def results @results end |
#text ⇒ String (readonly)
The text upon which the language detection was performed.
48 49 50 |
# File 'lib/gcloud/translate/detection.rb', line 48 def text @text end |
Class Method Details
.from_gapi(gapi, text) ⇒ Object
defined by the Google API Client object.
89 90 91 92 93 94 95 96 |
# File 'lib/gcloud/translate/detection.rb', line 89 def self.from_gapi gapi, text res = text.zip(Array(gapi.detections)).map do |txt, detections_gapi| results = detections_gapi.map { |g| Result.from_gapi g } new txt, results end return res.first if res.size == 1 res end |
Instance Method Details
#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.
70 71 72 73 |
# File 'lib/gcloud/translate/detection.rb', line 70 def confidence return nil if results.empty? results.first.confidence end |
#language ⇒ String
The most likely language that was detected. This is an [ISO 639-1](en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language code.
81 82 83 84 |
# File 'lib/gcloud/translate/detection.rb', line 81 def language return nil if results.empty? results.first.language end |