profanalyzer 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ === 0.2.0 / 2009-03-23
2
+
3
+ * Added an options hash to Profanalyzer#filter and Profanalyzer#profane?, letting you change settings but only within the scope of that call - using this hash won't change the global settings.
4
+
1
5
  === 0.1.1 / 2009-03-22
2
6
 
3
7
  * Fixed the link to point to http://profanalyzer.rubyforge.org/
@@ -5,3 +5,4 @@ Rakefile
5
5
  config/list.yml
6
6
  lib/profanalyzer.rb
7
7
  test/test_profanalyzer.rb
8
+ test/test_profanalyzer_advanced.rb
data/README.txt CHANGED
@@ -4,22 +4,13 @@
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
- Profanalyzer has one purpose: analyze a block of text for profanity. It is
8
- able to filter profane words as well.
9
-
10
- What sets it slightly apart from other filters is that it classifies each
11
- blocked word as "profane", "racist", or "sexual" - although right now, each
12
- word is considered "profane". It also rates each word on a scale from 0-5,
13
- which is based on my subjective opinion, as well as whether the word is
14
- commonly used in non-profane situations, such as "ass" in "assess".
15
-
16
- The Profanalyzer will default to a tolerance of of 2, which will kick back
17
- the arguably non-profane words. It will also test against all words,
18
- including racist or sexual words.
19
-
20
- Lastly, it allows for custom substitutions! For example, the filter at the
21
- website http://www.fark.com/ turns the word "fuck" into "fark", and "shit"
22
- into "shiat". You can specify these if you want.
7
+ Profanalyzer has one purpose: analyze a block of text for profanity. It is able to filter profane words as well.
8
+
9
+ What sets it slightly apart from other filters is that it classifies each blocked word as "profane", "racist", or "sexual" - although right now, each word is considered "profane". It also rates each word on a scale from 0-5, which is based on my subjective opinion, as well as whether the word is commonly used in non-profane situations, such as "ass" in "assess".
10
+
11
+ The Profanalyzer will default to a tolerance of of 2, which will kick back the arguably non-profane words. It will also test against all words, including racist or sexual words.
12
+
13
+ Lastly, it allows for custom substitutions! For example, the filter at the website http://www.fark.com/ turns the word "fuck" into "fark", and "shit" into "shiat". You can specify these if you want.
23
14
 
24
15
  == FEATURES/PROBLEMS:
25
16
 
data/Rakefile CHANGED
@@ -8,6 +8,69 @@ Hoe.new('profanalyzer', Profanalyzer::VERSION) do |p|
8
8
  # p.rubyforge_name = 'profanalyzerx' # if different than lowercase project name
9
9
  p.developer('Michael J. Edgar', 'edgar@triqweb.com')
10
10
  p.remote_rdoc_dir = ''
11
+
12
+ desc 'Post your blog announcement to blogger.'
13
+ task :post_blogger do
14
+ require 'net/http'
15
+ require 'net/https'
16
+ p.with_config do |config, path|
17
+ break unless config['blogs']
18
+ subject, title, body, urls = p.announcement
19
+ #body += "\n\n#{urls}"
20
+
21
+ config['blogs'].each do |site|
22
+ next unless site['url'] =~ /www\.blogger\.com/
23
+ google_email = site['user']
24
+ google_passwd = site['password']
25
+ source = 'beforefilter.blogspot.com-rubypost'
26
+
27
+ http = Net::HTTP.new('www.google.com', 443)
28
+ http.use_ssl = true
29
+ login_url = '/accounts/ClientLogin'
30
+
31
+ # Setup HTTPS request post data to obtain authentication token.
32
+ data = 'Email=' + google_email +'&Passwd=' + google_passwd + '&source=' + source + '&service=blogger'
33
+ headers = {
34
+ 'Content-Type' => 'application/x-www-form-urlencoded'
35
+ }
36
+
37
+ # Submit HTTPS post request
38
+ resp, data = http.post(login_url, data, headers)
39
+
40
+ unless resp.code.eql? '200'
41
+ puts "Error during authentication, blog at #{site['url']}, ##{site['blog_id']}: #{resp.message}\n"
42
+ else
43
+
44
+ # Parse for the authentication token.
45
+ authToken = data.split("\n").map {|l| l.split("=")}.assoc("Auth")[1]
46
+
47
+ headers = {
48
+ 'Authorization' => 'GoogleLogin auth=' + authToken,
49
+ 'Content-Type' => 'application/atom+xml'
50
+ }
51
+
52
+ data = <<-EOF
53
+ <entry xmlns='http://www.w3.org/2005/Atom'>
54
+ <title type='text'>#{title}</title>
55
+ <content type='xhtml'>
56
+ <div xmlns="http://www.w3.org/1999/xhtml">
57
+ #{body}
58
+ </div>
59
+ </content>
60
+ #{p.blog_categories.inject("") {|acc,cat| acc + "<category scheme=\"http://www.blogger.com/atom/ns#\" term=\"#{cat}\" />\n"}}
61
+ </entry>
62
+ EOF
63
+
64
+ http = Net::HTTP.new('www.blogger.com')
65
+ path = '/feeds/' + site['blog_id'] + '/posts/default'
66
+
67
+ resp, data = http.post(path, data, headers)
68
+ puts "Error while posting, blog at #{site['url']}, ##{site['blog_id']}: #{resp.message}" unless resp.code == 200
69
+ # Expect resp.code == 200 and resp.message == 'OK' for a successful.
70
+ end
71
+ end
72
+ end
73
+ end
11
74
  end
12
75
 
13
76
  # vim: syntax=Ruby
@@ -98,7 +98,7 @@ require 'yaml'
98
98
  # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
99
99
  class Profanalyzer
100
100
 
101
- VERSION = "0.1.1"
101
+ VERSION = "0.2.0"
102
102
 
103
103
  @@full_list = YAML::load_file(File.dirname(__FILE__)+"/../config/list.yml")
104
104
  @@racist_list = @@full_list.select {|w| w[:racist]}
@@ -125,6 +125,19 @@ class Profanalyzer
125
125
  banned_words
126
126
  end
127
127
 
128
+ def self.update_settings_from_hash(hash)
129
+ self.tolerance = hash[:tolerance] if hash.has_key? :tolerance
130
+ self.check_racist = hash[:racist] if hash.has_key? :racist
131
+ self.check_sexual = hash[:sexual] if hash.has_key? :sexual
132
+ if hash.has_key? :all
133
+ self.check_all = hash[:all]
134
+ elsif hash.has_key?(:sexual) || hash.has_key?(:racist)
135
+ self.check_all = false
136
+ else
137
+ self.check_all = true
138
+ end
139
+ end
140
+
128
141
  # Decides whether the given string is profane, given Profanalyzer's current
129
142
  # settings. Examples:
130
143
  # Profanalyzer.profane?("you're an asshole") #==> true
@@ -134,11 +147,30 @@ class Profanalyzer
134
147
  # Profanalyzer.check_racist = false
135
148
  # Profanalyzer.profane?("you're a mick") #==> false
136
149
  #
137
- def self.profane?(str)
138
- banned_words = Profanalyzer.forbidden_words_from_settings
150
+ # You can pass options to the method itself:
151
+ # Profanalyzer.profane?("you're a mick", :racist => false) #==> false
152
+ #
153
+ # Available options:
154
+ #
155
+ # [:+all+] Set to +true+ or +false+ to specify checking all words in the blacklist
156
+ # [:+sexual+] Set to +true+ or +false+ to specify sexual checking
157
+ # [:+racist+] Set to +true+ or +false+ to specify racial slur checking
158
+ # [:+tolerance+] Sets the tolerance. 0-5.
159
+ #
160
+ def self.profane?(*args)
161
+ str = args[0]
162
+ if (args.size > 1 && args[1].is_a?(Hash))
163
+ oldsettings = @@settings
164
+ self.update_settings_from_hash args[1]
165
+ end
166
+ banned_words = self.forbidden_words_from_settings
139
167
  banned_words.each do |word|
140
- return true if str =~ /#{word}/
168
+ if str =~ /#{word}/
169
+ @@settings = oldsettings if oldsettings
170
+ return true
171
+ end
141
172
  end
173
+ @@settings = oldsettings if oldsettings
142
174
  false
143
175
  end
144
176
 
@@ -153,7 +185,23 @@ class Profanalyzer
153
185
  # Profanalyzer.filter("shit") #==> "shiat"
154
186
  # Profanalyzer.filter("damn") #==> "#!$%"
155
187
  #
156
- def self.filter(str)
188
+ # You can pass options to the method itself:
189
+ # Profanalyzer.filter("you're a mick", :racist => false) #==> "you're a mick"
190
+ #
191
+ # Available options:
192
+ #
193
+ # [:+all+] Set to +true+ or +false+ to specify checking all words in the blacklist
194
+ # [:+sexual+] Set to +true+ or +false+ to specify sexual checking
195
+ # [:+racist+] Set to +true+ or +false+ to specify racial slur checking
196
+ # [:+tolerance+] Sets the tolerance. 0-5.
197
+ #
198
+ def self.filter(*args)
199
+ str = args[0]
200
+ if (args.size > 1 && args[1].is_a?(Hash))
201
+ oldsettings = @@settings
202
+ self.update_settings_from_hash args[1]
203
+ end
204
+
157
205
  retstr = str
158
206
 
159
207
  @@settings[:custom_subs].each do |k,v|
@@ -165,6 +213,7 @@ class Profanalyzer
165
213
  retstr.gsub!(/#{word}/,
166
214
  "#!$%@&!$%@%@&!$#!$%@&!$%@%@&!#!$%@&!$%@%@&!"[0..(word.length-1)])
167
215
  end
216
+ @@settings = oldsettings if oldsettings
168
217
  retstr
169
218
  end
170
219
 
@@ -15,6 +15,7 @@ class TestProfanalyzer < Test::Unit::TestCase
15
15
  Profanalyzer.check_sexual = false
16
16
  Profanalyzer.check_racist = true
17
17
  assert_equal(true, Profanalyzer.profane?("spic"))
18
+ assert_equal(false, Profanalyzer.profane?("pussy"))
18
19
  end
19
20
 
20
21
  def test_single_sexual_word
@@ -23,6 +24,7 @@ class TestProfanalyzer < Test::Unit::TestCase
23
24
  Profanalyzer.check_racist = false
24
25
  Profanalyzer.check_sexual = true
25
26
  assert_equal(true, Profanalyzer.profane?("vagina"))
27
+ assert_equal(false, Profanalyzer.profane?("nigger"))
26
28
  end
27
29
 
28
30
  def test_tolerance
@@ -0,0 +1,53 @@
1
+ require "test/unit"
2
+ require "profanalyzer"
3
+
4
+ class TestProfanalyzer < Test::Unit::TestCase
5
+
6
+ def test_single_word_advanced
7
+ assert_equal(true, Profanalyzer.profane?("asshole", :tolerance => 0, :all => true))
8
+ end
9
+
10
+ def test_single_racist_word_advanced
11
+ assert_equal(true, Profanalyzer.profane?("spic", :tolerance => 0, :racist => true, :sexual => false))
12
+ assert_equal(false, Profanalyzer.profane?("pussy", :tolerance => 0, :racist => true, :sexual => false))
13
+ end
14
+
15
+ def test_single_sexual_word_advanced
16
+ assert_equal(true, Profanalyzer.profane?("vagina", :tolerance => 0, :racist => false, :sexual => true))
17
+ assert_equal(false, Profanalyzer.profane?("nigger", :tolerance => 0, :racist => false, :sexual => true))
18
+ end
19
+
20
+ def test_tolerance_advanced
21
+ assert_equal(false, Profanalyzer.profane?("asskisser", :tolerance => 4, :all => true)) # badness = 3
22
+ assert_equal(true, Profanalyzer.profane?("fuck", :tolerance => 4, :all => true)) # badness = 5
23
+ end
24
+
25
+ def test_sexual_tolerance_advanced
26
+ assert_equal(false, Profanalyzer.profane?("vagina", :tolerance => 4, :racist => false, :sexual => true)) # badness = 3
27
+ assert_equal(true, Profanalyzer.profane?("cunt", :tolerance => 4, :racist => false, :sexual => true)) # badness = 5
28
+ end
29
+
30
+ def test_racist_tolerance_advanced
31
+ assert_equal(false, Profanalyzer.profane?("mick", :tolerance => 4, :racist => true, :sexual => false)) # badness = 3
32
+ assert_equal(true, Profanalyzer.profane?("nigger", :tolerance => 4, :racist => true, :sexual => false)) # badness = 5
33
+ end
34
+
35
+ def test_filter_advanced
36
+ original_string = "You're a cocksucking piece of shit, you mick."
37
+ filtered_string = "You're a #!$%@&!$%@% piece of #!$%, you #!$%."
38
+ assert_equal(filtered_string, Profanalyzer.filter(original_string, :tolerance => 0, :all => true))
39
+ end
40
+
41
+ def test_sexual_filter_advanced
42
+ original_string = "You're a cocksucking piece of shit, you mick."
43
+ filtered_string = "You're a #!$%@&!$%@% piece of shit, you mick."
44
+ assert_equal(filtered_string, Profanalyzer.filter(original_string, :tolerance => 0, :sexual => true, :racist => false))
45
+ end
46
+
47
+ def test_racist_filter_advanced
48
+ original_string = "You're a cocksucking piece of shit, you mick."
49
+ filtered_string = "You're a cocksucking piece of shit, you #!$%."
50
+ assert_equal(filtered_string, Profanalyzer.filter(original_string, :tolerance => 0, :sexual => false, :racist => true))
51
+ end
52
+
53
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: profanalyzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael J. Edgar
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-22 00:00:00 -04:00
12
+ date: 2009-03-23 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,7 +22,7 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 1.11.0
24
24
  version:
25
- description: "Profanalyzer has one purpose: analyze a block of text for profanity. It is able to filter profane words as well. What sets it slightly apart from other filters is that it classifies each blocked word as \"profane\", \"racist\", or \"sexual\" - although right now, each word is considered \"profane\". It also rates each word on a scale from 0-5, which is based on my subjective opinion, as well as whether the word is commonly used in non-profane situations, such as \"ass\" in \"assess\". The Profanalyzer will default to a tolerance of of 2, which will kick back the arguably non-profane words. It will also test against all words, including racist or sexual words. Lastly, it allows for custom substitutions! For example, the filter at the website http://www.fark.com/ turns the word \"fuck\" into \"fark\", and \"shit\" into \"shiat\". You can specify these if you want."
25
+ description: "Profanalyzer has one purpose: analyze a block of text for profanity. It is able to filter profane words as well. What sets it slightly apart from other filters is that it classifies each blocked word as \"profane\", \"racist\", or \"sexual\" - although right now, each word is considered \"profane\". It also rates each word on a scale from 0-5, which is based on my subjective opinion, as well as whether the word is commonly used in non-profane situations, such as \"ass\" in \"assess\". The Profanalyzer will default to a tolerance of of 2, which will kick back the arguably non-profane words. It will also test against all words, including racist or sexual words. Lastly, it allows for custom substitutions! For example, the filter at the website http://www.fark.com/ turns the word \"fuck\" into \"fark\", and \"shit\" into \"shiat\". You can specify these if you want."
26
26
  email:
27
27
  - edgar@triqweb.com
28
28
  executables: []
@@ -41,6 +41,7 @@ files:
41
41
  - config/list.yml
42
42
  - lib/profanalyzer.rb
43
43
  - test/test_profanalyzer.rb
44
+ - test/test_profanalyzer_advanced.rb
44
45
  has_rdoc: true
45
46
  homepage: http://profanalyzer.rubyforge.org/
46
47
  post_install_message:
@@ -70,3 +71,4 @@ specification_version: 2
70
71
  summary: "Profanalyzer has one purpose: analyze a block of text for profanity"
71
72
  test_files:
72
73
  - test/test_profanalyzer.rb
74
+ - test/test_profanalyzer_advanced.rb