Class: Decidim::Ai::SpamDetection::GenericSpamAnalyzerJob
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- Decidim::ApplicationJob
- ApplicationJob
- ApplicationJob
- Decidim::Ai::SpamDetection::GenericSpamAnalyzerJob
- Includes:
- TranslatableAttributes
- Defined in:
- decidim-ai/app/jobs/decidim/ai/spam_detection/generic_spam_analyzer_job.rb
Direct Known Subclasses
Instance Method Summary collapse
Methods included from TranslatableAttributes
#attachment?, #default_locale?
Instance Method Details
#perform(reportable, author, locale, fields) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'decidim-ai/app/jobs/decidim/ai/spam_detection/generic_spam_analyzer_job.rb', line 9 def perform(reportable, , locale, fields) @author = overall_score = I18n.with_locale(locale) do fields.map do |field| classifier.classify(translated_attribute(reportable.send(field))) classifier.score end end overall_score = overall_score.inject(0.0, :+) / overall_score.size return unless overall_score >= Decidim::Ai::SpamDetection.resource_score_threshold Decidim::CreateReport.call(form, reportable) end |