class GooglePerspective::CommentAnalyzer

Attributes

client[RW]
score[RW]
text[RW]

Public Class Methods

new(text:, score: 0.5) click to toggle source
# File lib/google_perspective/comment_analizer.rb, line 7
def initialize(text:, score: 0.5)
  @client = Client.new
  @text = text
  @score = score
end

Public Instance Methods

body() click to toggle source
# File lib/google_perspective/comment_analizer.rb, line 31
def body
  {
    comment: {
      text: text,
      type: 'PLAIN_TEXT'
    },
    requestedAttributes: {
      TOXICITY: {},
      SEVERE_TOXICITY: {}
    }
  }
end
response() click to toggle source
# File lib/google_perspective/comment_analizer.rb, line 27
def response
  @response ||= client.post(body)
end
result_score() click to toggle source
# File lib/google_perspective/comment_analizer.rb, line 17
def result_score
  result_scores.min
end
result_scores() click to toggle source
# File lib/google_perspective/comment_analizer.rb, line 21
def result_scores
  @result_scores ||= response['attributeScores'].map do |_model, model_score|
    model_score.dig('summaryScore', 'value')
  end
end
valid?() click to toggle source
# File lib/google_perspective/comment_analizer.rb, line 13
def valid?
  result_score <= score
end