Class: Decidim::Ai::SpamDetection::Service
- Inherits:
-
Object
- Object
- Decidim::Ai::SpamDetection::Service
- Defined in:
- decidim-ai/lib/decidim/ai/spam_detection/service.rb
Instance Method Summary collapse
- #classification_log ⇒ Object
- #classify(text) ⇒ Object
-
#initialize(registry:) ⇒ Service
constructor
A new instance of Service.
- #reset ⇒ Object
- #score ⇒ Object
- #train(category, text) ⇒ Object
- #untrain(category, text) ⇒ Object
Constructor Details
#initialize(registry:) ⇒ Service
Returns a new instance of Service.
7 8 9 |
# File 'decidim-ai/lib/decidim/ai/spam_detection/service.rb', line 7 def initialize(registry:) @registry = registry end |
Instance Method Details
#classification_log ⇒ Object
50 51 52 53 54 55 56 |
# File 'decidim-ai/lib/decidim/ai/spam_detection/service.rb', line 50 def classification_log @classification_log = [] @registry.each do |strategy| @classification_log << strategy.log end @classification_log.join("\n") end |
#classify(text) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'decidim-ai/lib/decidim/ai/spam_detection/service.rb', line 28 def classify(text) text = formatter.cleanup(text) return if text.blank? @registry.each do |strategy| strategy.classify(text) end end |
#reset ⇒ Object
11 12 13 14 15 16 17 |
# File 'decidim-ai/lib/decidim/ai/spam_detection/service.rb', line 11 def reset @registry.each do |strategy| next unless strategy.respond_to?(:reset) strategy.reset end end |
#score ⇒ Object
46 47 48 |
# File 'decidim-ai/lib/decidim/ai/spam_detection/service.rb', line 46 def score @registry.collect(&:score).inject(0.0, :+) / @registry.size end |
#train(category, text) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'decidim-ai/lib/decidim/ai/spam_detection/service.rb', line 19 def train(category, text) text = formatter.cleanup(text) return if text.blank? @registry.each do |strategy| strategy.train(category, text) end end |
#untrain(category, text) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'decidim-ai/lib/decidim/ai/spam_detection/service.rb', line 37 def untrain(category, text) text = formatter.cleanup(text) return if text.blank? @registry.each do |strategy| strategy.untrain(category, text) end end |