Class: GooglePerspective::CommentAnalyzer
- Inherits:
-
Object
- Object
- GooglePerspective::CommentAnalyzer
- Defined in:
- lib/google_perspective/comment_analizer.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#score ⇒ Object
Returns the value of attribute score.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
- #body ⇒ Object
-
#initialize(text:, score: 0.5) ⇒ CommentAnalyzer
constructor
A new instance of CommentAnalyzer.
- #response ⇒ Object
- #result_score ⇒ Object
- #result_scores ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(text:, score: 0.5) ⇒ CommentAnalyzer
Returns a new instance of CommentAnalyzer.
5 6 7 8 9 |
# File 'lib/google_perspective/comment_analizer.rb', line 5 def initialize(text:, score: 0.5) @client = Client.new @text = text @score = score end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
3 4 5 |
# File 'lib/google_perspective/comment_analizer.rb', line 3 def client @client end |
#score ⇒ Object
Returns the value of attribute score.
3 4 5 |
# File 'lib/google_perspective/comment_analizer.rb', line 3 def score @score end |
#text ⇒ Object
Returns the value of attribute text.
3 4 5 |
# File 'lib/google_perspective/comment_analizer.rb', line 3 def text @text end |
Instance Method Details
#body ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/google_perspective/comment_analizer.rb', line 29 def body { comment: { text: text, type: 'PLAIN_TEXT' }, requestedAttributes: { TOXICITY: {}, SEVERE_TOXICITY: {} } } end |
#response ⇒ Object
25 26 27 |
# File 'lib/google_perspective/comment_analizer.rb', line 25 def response @response ||= client.post(body) end |
#result_score ⇒ Object
15 16 17 |
# File 'lib/google_perspective/comment_analizer.rb', line 15 def result_score result_scores.min end |
#result_scores ⇒ Object
19 20 21 22 23 |
# File 'lib/google_perspective/comment_analizer.rb', line 19 def result_scores @result_scores ||= response['attributeScores'].map do |_model, model_score| model_score.dig('summaryScore', 'value') end end |
#valid? ⇒ Boolean
11 12 13 |
# File 'lib/google_perspective/comment_analizer.rb', line 11 def valid? result_score <= score end |