decidim-ai 0.31.5 → 0.32.0.rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/decidim/ai/engine.rb +0 -12
- data/lib/decidim/ai/language/language.rb +9 -4
- data/lib/decidim/ai/spam_detection/spam_detection.rb +45 -64
- data/lib/decidim/ai/version.rb +1 -1
- data/lib/decidim/ai.rb +0 -2
- metadata +14 -18
- data/lib/decidim/ai/spam_detection/resource/collaborative_draft.rb +0 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c8dabdb284ecb4f688c0cfcf066792305078d53e3310c34696fb9c20760eabb9
|
|
4
|
+
data.tar.gz: 7d468c46a29acfe3fff5e9050b55e9ff146fcf5f791fffc622173cdd041dbf8e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bed4d933716c506861b6526df75a7ec904cb9a1a9b91421c4f3ae81c281c489af4a008b52151609b198e10a9015dfbc885ceeed01f062256528e6b1dc64f2913
|
|
7
|
+
data.tar.gz: 8c7bda3fda0e6ee33be80832532439e9232a215c543ac9d404fcb69c001b6f4360ec5bb05b21ded7de159635505a5dbab608925bd0ebffda8a41bc74c68e88e4
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# decidim-ai
|
|
2
2
|
|
|
3
3
|
The Decidim::Ai is a library that aims to provide Artificial Intelligence tools for Decidim. This plugin has been initially developed aiming to analyze the content and provide spam classification using Naive Bayes algorithm.
|
|
4
4
|
All AI related functionality provided by Decidim should be included in this same module.
|
data/lib/decidim/ai/engine.rb
CHANGED
|
@@ -117,18 +117,6 @@ module Decidim
|
|
|
117
117
|
.perform_later(data[:resource],
|
|
118
118
|
data.dig(:extra, :event_author), data.dig(:extra, :locale), [:body, :title])
|
|
119
119
|
end
|
|
120
|
-
ActiveSupport::Notifications.subscribe("decidim.proposals.create_collaborative_draft:after") do |_event_name, data|
|
|
121
|
-
Decidim::Ai::SpamDetection::GenericSpamAnalyzerJob
|
|
122
|
-
.set(wait: Decidim::Ai::SpamDetection.spam_detection_delay)
|
|
123
|
-
.perform_later(data[:resource],
|
|
124
|
-
data.dig(:extra, :event_author), data.dig(:extra, :locale), [:body, :title])
|
|
125
|
-
end
|
|
126
|
-
ActiveSupport::Notifications.subscribe("decidim.proposals.update_collaborative_draft:after") do |_event_name, data|
|
|
127
|
-
Decidim::Ai::SpamDetection::GenericSpamAnalyzerJob
|
|
128
|
-
.set(wait: Decidim::Ai::SpamDetection.spam_detection_delay)
|
|
129
|
-
.perform_later(data[:resource],
|
|
130
|
-
data.dig(:extra, :event_author), data.dig(:extra, :locale), [:body, :title])
|
|
131
|
-
end
|
|
132
120
|
end
|
|
133
121
|
end
|
|
134
122
|
|
|
@@ -4,7 +4,14 @@ module Decidim
|
|
|
4
4
|
module Ai
|
|
5
5
|
module Language
|
|
6
6
|
autoload :Formatter, "decidim/ai/language/formatter"
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
class << self
|
|
9
|
+
def config = self
|
|
10
|
+
|
|
11
|
+
def configure
|
|
12
|
+
yield self
|
|
13
|
+
end
|
|
14
|
+
end
|
|
8
15
|
|
|
9
16
|
# Text cleanup service
|
|
10
17
|
#
|
|
@@ -15,9 +22,7 @@ module Decidim
|
|
|
15
22
|
# # your code
|
|
16
23
|
# end
|
|
17
24
|
# end
|
|
18
|
-
|
|
19
|
-
Decidim::Env.new("DECIDIM_AI_LANGUAGE_FORMATTER", "Decidim::Ai::Language::Formatter").value
|
|
20
|
-
end
|
|
25
|
+
mattr_accessor :formatter, default: Decidim::Env.new("DECIDIM_AI_LANGUAGE_FORMATTER", "Decidim::Ai::Language::Formatter").value
|
|
21
26
|
end
|
|
22
27
|
end
|
|
23
28
|
end
|
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
module Decidim
|
|
4
4
|
module Ai
|
|
5
5
|
module SpamDetection
|
|
6
|
-
include ActiveSupport::Configurable
|
|
7
|
-
|
|
8
6
|
autoload :Service, "decidim/ai/spam_detection/service"
|
|
9
7
|
|
|
10
8
|
module Resource
|
|
@@ -13,7 +11,6 @@ module Decidim
|
|
|
13
11
|
autoload :Debate, "decidim/ai/spam_detection/resource/debate"
|
|
14
12
|
autoload :Initiative, "decidim/ai/spam_detection/resource/initiative"
|
|
15
13
|
autoload :Proposal, "decidim/ai/spam_detection/resource/proposal"
|
|
16
|
-
autoload :CollaborativeDraft, "decidim/ai/spam_detection/resource/collaborative_draft"
|
|
17
14
|
autoload :Meeting, "decidim/ai/spam_detection/resource/meeting"
|
|
18
15
|
autoload :UserBaseEntity, "decidim/ai/spam_detection/resource/user_base_entity"
|
|
19
16
|
end
|
|
@@ -28,31 +25,31 @@ module Decidim
|
|
|
28
25
|
autoload :Bayes, "decidim/ai/spam_detection/strategy/bayes"
|
|
29
26
|
end
|
|
30
27
|
|
|
28
|
+
class << self
|
|
29
|
+
def config = self
|
|
30
|
+
|
|
31
|
+
def configure
|
|
32
|
+
yield self
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
31
36
|
# When the engine is consistently marking spam content without errors,
|
|
32
37
|
# you can skip human intervention by enabling this functionality
|
|
33
|
-
|
|
34
|
-
Decidim::Env.new("DECIDIM_SPAM_HIDE_REPORTED_RESOURCES_AUTOMATICALLY", false).present?
|
|
35
|
-
end
|
|
38
|
+
mattr_accessor :hide_reported_resources_automatically, default: Decidim::Env.new("DECIDIM_SPAM_HIDE_REPORTED_RESOURCES_AUTOMATICALLY", false).present?
|
|
36
39
|
|
|
37
40
|
# This is the email address used by the spam engine to
|
|
38
41
|
# properly identify the user that will report users and content
|
|
39
|
-
|
|
40
|
-
Decidim::Env.new("DECIDIM_SPAM_REPORTING_USER", "decidim-reporting-user@example.org").value
|
|
41
|
-
end
|
|
42
|
+
mattr_accessor :reporting_user_email, default: Decidim::Env.new("DECIDIM_SPAM_REPORTING_USER", "decidim-reporting-user@example.org").value
|
|
42
43
|
|
|
43
44
|
# You can configure the spam threshold for the spam detection service.
|
|
44
45
|
# The threshold is a float value between 0 and 1.
|
|
45
46
|
# The default value is 0.75
|
|
46
47
|
# Any value below the threshold will be considered spam.
|
|
47
|
-
|
|
48
|
-
Decidim::Env.new("DECIDIM_SPAM_DETECTION_RESOURCE_SCORE_THRESHOLD", 0.75).to_f
|
|
49
|
-
end
|
|
48
|
+
mattr_accessor :resource_score_threshold, default: Decidim::Env.new("DECIDIM_SPAM_DETECTION_RESOURCE_SCORE_THRESHOLD", 0.75).to_f
|
|
50
49
|
|
|
51
50
|
# You can configure the spam delay for the spam detection service.
|
|
52
51
|
# The default value is 30 seconds
|
|
53
|
-
|
|
54
|
-
Decidim::Env.new("DECIDIM_SPAM_DETECTION_DELAY_IN_SECONDS", 30).to_i.seconds
|
|
55
|
-
end
|
|
52
|
+
mattr_accessor :spam_detection_delay, default: Decidim::Env.new("DECIDIM_SPAM_DETECTION_DELAY_IN_SECONDS", 30).to_i.seconds
|
|
56
53
|
|
|
57
54
|
# Registered analyzers.
|
|
58
55
|
# You can register your own analyzer by adding a new entry to this array.
|
|
@@ -71,49 +68,41 @@ module Decidim
|
|
|
71
68
|
# }
|
|
72
69
|
# }
|
|
73
70
|
# }
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
params: { url: ENV.fetch("DECIDIM_SPAM_DETECTION_BACKEND_RESOURCE_URL", "redis://localhost:6379/2") }
|
|
82
|
-
}
|
|
71
|
+
mattr_accessor :resource_analyzers, default: [
|
|
72
|
+
{
|
|
73
|
+
name: :bayes,
|
|
74
|
+
strategy: Decidim::Ai::SpamDetection::Strategy::Bayes,
|
|
75
|
+
options: {
|
|
76
|
+
adapter: ENV.fetch("DECIDIM_SPAM_DETECTION_BACKEND_RESOURCE", "redis"),
|
|
77
|
+
params: { url: ENV.fetch("DECIDIM_SPAM_DETECTION_BACKEND_RESOURCE_URL", "redis://localhost:6379/2") }
|
|
83
78
|
}
|
|
84
|
-
|
|
85
|
-
|
|
79
|
+
}
|
|
80
|
+
]
|
|
86
81
|
|
|
87
|
-
# This
|
|
82
|
+
# This setting allows the implementers to change the class being used by the classifier,
|
|
88
83
|
# in order to change the finder method. or even define own resource visibility criteria.
|
|
89
84
|
# This is the place where new resources can be registered following the pattern
|
|
90
85
|
# Resource => Handler
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
models
|
|
101
|
-
end
|
|
86
|
+
mattr_accessor :resource_models
|
|
87
|
+
self.resource_models ||= begin
|
|
88
|
+
models = {}
|
|
89
|
+
models["Decidim::Comments::Comment"] = "Decidim::Ai::SpamDetection::Resource::Comment" if Decidim.module_installed?("comments")
|
|
90
|
+
models["Decidim::Debates::Debate"] = "Decidim::Ai::SpamDetection::Resource::Debate" if Decidim.module_installed?("debates")
|
|
91
|
+
models["Decidim::Initiative"] = "Decidim::Ai::SpamDetection::Resource::Initiative" if Decidim.module_installed?("initiatives")
|
|
92
|
+
models["Decidim::Meetings::Meeting"] = "Decidim::Ai::SpamDetection::Resource::Meeting" if Decidim.module_installed?("meetings")
|
|
93
|
+
models["Decidim::Proposals::Proposal"] = "Decidim::Ai::SpamDetection::Resource::Proposal" if Decidim.module_installed?("proposals")
|
|
94
|
+
models
|
|
102
95
|
end
|
|
103
96
|
|
|
104
97
|
# Spam detection service class.
|
|
105
98
|
# If you want to use a different spam detection service, you can use a class service having the following contract
|
|
106
|
-
|
|
107
|
-
Decidim::Env.new("DECIDIM_SPAM_DETECTION_RESOURCE_SERVICE", "Decidim::Ai::SpamDetection::Service").value
|
|
108
|
-
end
|
|
99
|
+
mattr_accessor :resource_detection_service, default: Decidim::Env.new("DECIDIM_SPAM_DETECTION_RESOURCE_SERVICE", "Decidim::Ai::SpamDetection::Service").value
|
|
109
100
|
|
|
110
101
|
# You can configure the spam threshold for the spam detection service.
|
|
111
102
|
# The threshold is a float value between 0 and 1.
|
|
112
103
|
# The default value is 0.75
|
|
113
104
|
# Any value below the threshold will be considered spam.
|
|
114
|
-
|
|
115
|
-
Decidim::Env.new("DECIDIM_SPAM_DETECTION_USER_SCORE_THRESHOLD", 0.75).to_f
|
|
116
|
-
end
|
|
105
|
+
mattr_accessor :user_score_threshold, default: Decidim::Env.new("DECIDIM_SPAM_DETECTION_USER_SCORE_THRESHOLD", 0.75).to_f
|
|
117
106
|
|
|
118
107
|
# Registered analyzers.
|
|
119
108
|
# You can register your own analyzer by adding a new entry to this array.
|
|
@@ -132,32 +121,24 @@ module Decidim
|
|
|
132
121
|
# }
|
|
133
122
|
# }
|
|
134
123
|
# }
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
params: { url: ENV.fetch("DECIDIM_SPAM_DETECTION_BACKEND_USER_REDIS_URL", "redis://localhost:6379/3") }
|
|
143
|
-
}
|
|
124
|
+
mattr_accessor :user_analyzers, default: [
|
|
125
|
+
{
|
|
126
|
+
name: :bayes,
|
|
127
|
+
strategy: Decidim::Ai::SpamDetection::Strategy::Bayes,
|
|
128
|
+
options: {
|
|
129
|
+
adapter: ENV.fetch("DECIDIM_SPAM_DETECTION_BACKEND_USER", "redis"),
|
|
130
|
+
params: { url: ENV.fetch("DECIDIM_SPAM_DETECTION_BACKEND_USER_REDIS_URL", "redis://localhost:6379/3") }
|
|
144
131
|
}
|
|
145
|
-
|
|
146
|
-
|
|
132
|
+
}
|
|
133
|
+
]
|
|
147
134
|
|
|
148
|
-
# This
|
|
135
|
+
# This setting allows the implementers to change the class being used by the classifier,
|
|
149
136
|
# in order to change the finder method or what a hidden user really is.
|
|
150
|
-
|
|
151
|
-
{
|
|
152
|
-
"Decidim::User" => "Decidim::Ai::SpamDetection::Resource::UserBaseEntity"
|
|
153
|
-
}
|
|
154
|
-
end
|
|
137
|
+
mattr_accessor :user_models, default: { "Decidim::User" => "Decidim::Ai::SpamDetection::Resource::UserBaseEntity" }
|
|
155
138
|
|
|
156
139
|
# Spam detection service class.
|
|
157
140
|
# If you want to use a different spam detection service, you can use a class service having the following contract
|
|
158
|
-
|
|
159
|
-
Decidim::Env.new("DECIDIM_SPAM_DETECTION_USER_SERVICE", "Decidim::Ai::SpamDetection::Service").value
|
|
160
|
-
end
|
|
141
|
+
mattr_accessor :user_detection_service, default: Decidim::Env.new("DECIDIM_SPAM_DETECTION_USER_SERVICE", "Decidim::Ai::SpamDetection::Service").value
|
|
161
142
|
|
|
162
143
|
# this is the generic resource classifier class. If you need to change your own class, please change the
|
|
163
144
|
# configuration of `Decidim::Ai::SpamDetection.detection_service` variable.
|
data/lib/decidim/ai/version.rb
CHANGED
data/lib/decidim/ai.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: decidim-ai
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.32.0.rc2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexandru-Emil Lupu
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: classifier-reborn
|
|
@@ -30,70 +29,70 @@ dependencies:
|
|
|
30
29
|
requirements:
|
|
31
30
|
- - '='
|
|
32
31
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: 0.
|
|
32
|
+
version: 0.32.0.rc2
|
|
34
33
|
type: :runtime
|
|
35
34
|
prerelease: false
|
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
36
|
requirements:
|
|
38
37
|
- - '='
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: 0.
|
|
39
|
+
version: 0.32.0.rc2
|
|
41
40
|
- !ruby/object:Gem::Dependency
|
|
42
41
|
name: decidim-debates
|
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
|
44
43
|
requirements:
|
|
45
44
|
- - '='
|
|
46
45
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: 0.
|
|
46
|
+
version: 0.32.0.rc2
|
|
48
47
|
type: :development
|
|
49
48
|
prerelease: false
|
|
50
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
50
|
requirements:
|
|
52
51
|
- - '='
|
|
53
52
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: 0.
|
|
53
|
+
version: 0.32.0.rc2
|
|
55
54
|
- !ruby/object:Gem::Dependency
|
|
56
55
|
name: decidim-initiatives
|
|
57
56
|
requirement: !ruby/object:Gem::Requirement
|
|
58
57
|
requirements:
|
|
59
58
|
- - '='
|
|
60
59
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: 0.
|
|
60
|
+
version: 0.32.0.rc2
|
|
62
61
|
type: :development
|
|
63
62
|
prerelease: false
|
|
64
63
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
64
|
requirements:
|
|
66
65
|
- - '='
|
|
67
66
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: 0.
|
|
67
|
+
version: 0.32.0.rc2
|
|
69
68
|
- !ruby/object:Gem::Dependency
|
|
70
69
|
name: decidim-meetings
|
|
71
70
|
requirement: !ruby/object:Gem::Requirement
|
|
72
71
|
requirements:
|
|
73
72
|
- - '='
|
|
74
73
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: 0.
|
|
74
|
+
version: 0.32.0.rc2
|
|
76
75
|
type: :development
|
|
77
76
|
prerelease: false
|
|
78
77
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
78
|
requirements:
|
|
80
79
|
- - '='
|
|
81
80
|
- !ruby/object:Gem::Version
|
|
82
|
-
version: 0.
|
|
81
|
+
version: 0.32.0.rc2
|
|
83
82
|
- !ruby/object:Gem::Dependency
|
|
84
83
|
name: decidim-proposals
|
|
85
84
|
requirement: !ruby/object:Gem::Requirement
|
|
86
85
|
requirements:
|
|
87
86
|
- - '='
|
|
88
87
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: 0.
|
|
88
|
+
version: 0.32.0.rc2
|
|
90
89
|
type: :development
|
|
91
90
|
prerelease: false
|
|
92
91
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
92
|
requirements:
|
|
94
93
|
- - '='
|
|
95
94
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: 0.
|
|
95
|
+
version: 0.32.0.rc2
|
|
97
96
|
description: A module that aims to provide Artificial Intelligence tools for Decidim.
|
|
98
97
|
email:
|
|
99
98
|
- contact@alecslupu.ro
|
|
@@ -114,7 +113,6 @@ files:
|
|
|
114
113
|
- lib/decidim/ai/spam_detection/importer/database.rb
|
|
115
114
|
- lib/decidim/ai/spam_detection/importer/file.rb
|
|
116
115
|
- lib/decidim/ai/spam_detection/resource/base.rb
|
|
117
|
-
- lib/decidim/ai/spam_detection/resource/collaborative_draft.rb
|
|
118
116
|
- lib/decidim/ai/spam_detection/resource/comment.rb
|
|
119
117
|
- lib/decidim/ai/spam_detection/resource/debate.rb
|
|
120
118
|
- lib/decidim/ai/spam_detection/resource/initiative.rb
|
|
@@ -138,7 +136,6 @@ metadata:
|
|
|
138
136
|
funding_uri: https://opencollective.com/decidim
|
|
139
137
|
homepage_uri: https://decidim.org
|
|
140
138
|
source_code_uri: https://github.com/decidim/decidim
|
|
141
|
-
post_install_message:
|
|
142
139
|
rdoc_options: []
|
|
143
140
|
require_paths:
|
|
144
141
|
- lib
|
|
@@ -146,15 +143,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
146
143
|
requirements:
|
|
147
144
|
- - "~>"
|
|
148
145
|
- !ruby/object:Gem::Version
|
|
149
|
-
version: 3.
|
|
146
|
+
version: 3.4.0
|
|
150
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
148
|
requirements:
|
|
152
149
|
- - ">="
|
|
153
150
|
- !ruby/object:Gem::Version
|
|
154
151
|
version: '0'
|
|
155
152
|
requirements: []
|
|
156
|
-
rubygems_version: 3.
|
|
157
|
-
signing_key:
|
|
153
|
+
rubygems_version: 3.6.9
|
|
158
154
|
specification_version: 4
|
|
159
155
|
summary: A Decidim module with AI tools
|
|
160
156
|
test_files: []
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Decidim
|
|
4
|
-
module Ai
|
|
5
|
-
module SpamDetection
|
|
6
|
-
module Resource
|
|
7
|
-
class CollaborativeDraft < Base
|
|
8
|
-
def fields = [:body, :title]
|
|
9
|
-
|
|
10
|
-
protected
|
|
11
|
-
|
|
12
|
-
def query = Decidim::Proposals::CollaborativeDraft.includes(:moderation)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|