confidential_info_redactor 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ConfidentialInfoRedactor::Hyperlink do
4
+ context '#hyperlink?' do
5
+ it 'returns true if the string is a hyperlink #001' do
6
+ string = "http://www.example.com/this-IS-a_test/hello.html"
7
+ ws = described_class.new(string: string)
8
+ expect(ws.hyperlink?).to eq(true)
9
+ end
10
+
11
+ it 'returns true if the string is a hyperlink #002' do
12
+ string = "http://www.google.co.uk"
13
+ ws = described_class.new(string: string)
14
+ expect(ws.hyperlink?).to eq(true)
15
+ end
16
+
17
+ it 'returns true if the string is a hyperlink #003' do
18
+ string = "https://google.co.uk"
19
+ ws = described_class.new(string: string)
20
+ expect(ws.hyperlink?).to eq(true)
21
+ end
22
+
23
+ it 'returns false if the string is not a hyperlink #004' do
24
+ string = "hello"
25
+ ws = described_class.new(string: string)
26
+ expect(ws.hyperlink?).to eq(false)
27
+ end
28
+
29
+ it 'returns false if the string is not a hyperlink #005' do
30
+ string = "john@gmail.com"
31
+ ws = described_class.new(string: string)
32
+ expect(ws.hyperlink?).to eq(false)
33
+ end
34
+
35
+ it 'returns false if the string is not a hyperlink #006' do
36
+ string = "date:"
37
+ ws = described_class.new(string: string)
38
+ expect(ws.hyperlink?).to eq(false)
39
+ end
40
+
41
+ it 'returns false if the string is not a hyperlink #007' do
42
+ string = 'The file location is c:\Users\johndoe.'
43
+ ws = described_class.new(string: string)
44
+ expect(ws.hyperlink?).to eq(false)
45
+ end
46
+ end
47
+
48
+ context '#replace' do
49
+ it 'replaces the hyperlinks in a string with regular tokens #001' do
50
+ string = "Today the date is: Jan 1. Visit https://www.example.com/hello or http://www.google.co.uk"
51
+ ws = described_class.new(string: string)
52
+ expect(ws.replace).to eq("Today the date is: Jan 1. Visit <redacted> or <redacted> ")
53
+ end
54
+
55
+ it 'replaces the hyperlinks in a string with regular tokens #002' do
56
+ string = 'The file location is c:\Users\johndoe or d:\Users\john\www'
57
+ ws = described_class.new(string: string)
58
+ expect(ws.replace).to eq('The file location is c:\Users\johndoe or d:\Users\john\www')
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,152 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ConfidentialInfoRedactor::Redactor do
4
+ describe '#dates' do
5
+ it 'redacts dates from a text #001' do
6
+ text = 'Coca-Cola announced a merger with Pepsi that will happen on December 15th, 2020 for $200,000,000,000.'
7
+ expect(described_class.new(text: text, language: 'en').dates).to eq('Coca-Cola announced a merger with Pepsi that will happen on <redacted date> for $200,000,000,000.')
8
+ end
9
+
10
+ it 'redacts dates from a text #002' do
11
+ text = 'Coca-Cola announced a merger with Pepsi that will happen on December 15th, 2020.'
12
+ expect(described_class.new(text: text, language: 'en').dates).to eq('Coca-Cola announced a merger with Pepsi that will happen on <redacted date>.')
13
+ end
14
+
15
+ it 'redacts dates from a text #003' do
16
+ text = 'December 5, 2010 - Coca-Cola announced a merger with Pepsi.'
17
+ expect(described_class.new(text: text, language: 'en').dates).to eq('<redacted date> - Coca-Cola announced a merger with Pepsi.')
18
+ end
19
+
20
+ it 'redacts dates from a text #004' do
21
+ text = 'The scavenger hunt ends on Dec. 31st, 2011.'
22
+ expect(described_class.new(text: text, language: 'en').dates).to eq('The scavenger hunt ends on <redacted date>.')
23
+ end
24
+ end
25
+
26
+ describe '#numbers' do
27
+ it 'redacts numbers from a text #001' do
28
+ text = 'Coca-Cola announced a merger with Pepsi that will happen on <redacted date> for $200,000,000,000.'
29
+ expect(described_class.new(text: text, language: 'en').numbers).to eq('Coca-Cola announced a merger with Pepsi that will happen on <redacted date> for <redacted number>.')
30
+ end
31
+
32
+ it 'redacts numbers from a text #002' do
33
+ text = '200 years ago.'
34
+ expect(described_class.new(text: text, language: 'en').numbers).to eq('<redacted number> years ago.')
35
+ end
36
+
37
+ it 'redacts numbers from a text #003' do
38
+ text = 'It was his 1st time, not yet his 10th, not even his 2nd. The wood was 3/4" thick.'
39
+ expect(described_class.new(text: text, language: 'en').numbers).to eq('It was his <redacted number> time, not yet his <redacted number>, not even his <redacted number>. The wood was <redacted number> thick.')
40
+ end
41
+ end
42
+
43
+ describe '#emails' do
44
+ it 'redacts email addresses from a text #001' do
45
+ text = 'His email is john@gmail.com or you can try k.light@tuv.eu.us.'
46
+ expect(described_class.new(text: text, language: 'en').emails).to eq('His email is <redacted> or you can try <redacted>.')
47
+ end
48
+ end
49
+
50
+ describe '#hyperlinks' do
51
+ it 'redacts hyperlinks from a text #001' do
52
+ text = 'Visit https://www.tm-town.com for more info.'
53
+ expect(described_class.new(text: text, language: 'en').hyperlinks).to eq('Visit <redacted> for more info.')
54
+ end
55
+ end
56
+
57
+ describe '#proper_nouns' do
58
+ it 'redacts tokens from a text #001' do
59
+ tokens = ['Coca-Cola', 'Pepsi']
60
+ text = 'Coca-Cola announced a merger with Pepsi that will happen on on December 15th, 2020 for $200,000,000,000.'
61
+ expect(described_class.new(text: text, language: 'en', tokens: tokens).proper_nouns).to eq('<redacted> announced a merger with <redacted> that will happen on on December 15th, 2020 for $200,000,000,000.')
62
+ end
63
+
64
+ it 'redacts tokens from a text #002' do
65
+ tokens = ['Coca-Cola', 'Pepsi']
66
+ text = 'Coca-Cola announced a merger with Pepsi that will happen on on December 15th, 2020 for $200,000,000,000.'
67
+ expect(described_class.new(text: text, language: 'en', tokens: tokens, token_text: '*****').proper_nouns).to eq('***** announced a merger with ***** that will happen on on December 15th, 2020 for $200,000,000,000.')
68
+ end
69
+ end
70
+
71
+ describe '#redact' do
72
+ it 'redacts all confidential information from a text #001' do
73
+ tokens = ['Coca-Cola', 'Pepsi']
74
+ text = 'Coca-Cola announced a merger with Pepsi that will happen on on December 15th, 2020 for $200,000,000,000.'
75
+ expect(described_class.new(text: text, language: 'en', tokens: tokens).redact).to eq('<redacted> announced a merger with <redacted> that will happen on on <redacted date> for <redacted number>.')
76
+ end
77
+
78
+ it 'redacts all confidential information from a text #002' do
79
+ text = <<-EOF
80
+ Putter King Miniature Golf Scavenger Hunt
81
+
82
+ Putter King is hosting the 1st Annual Miniature Golf Scavenger Hunt. So get out your putter and your camera and see if you have what it takes. Are you a King?
83
+
84
+ The Official List:
85
+
86
+ #1) Autographs of 2 professional miniature golfers, each from a different country. (45 points; 5 bonus points if the professional miniature golfers are also from 2 different continents)
87
+
88
+ #2) Picture of yourself next to each obstacle in our list of the Top 10 Nostalgic Miniature Golf Obstacles. (120 points; 20 bonus points for each obstacle that exactly matches the one pictured in the article)
89
+
90
+ #3) Build your own full-size miniature golf hole. (75 points; up to 100 bonus points available depending on the craftsmanship, playability, creativity and fun factor of your hole)
91
+
92
+ #4) Video of yourself making a hole-in-one on two consecutive miniature golf holes. The video must be one continuous shot with no editing. (60 points)
93
+
94
+ #5) Picture of yourself with the Putter King mascot. (50 points; 15 bonus points if you are wearing a Putter King t-shirt)
95
+
96
+ #6) Picture of yourself with the completed Putter King wobblehead. (15 points; 15 bonus points if the picture is taken at a miniature golf course)
97
+
98
+ #7) Picture of a completed scorecard from a round of miniature golf. The round of golf must have taken place after the start of this scavenger hunt. (10 points)
99
+
100
+ #8) Picture of completed scorecards from 5 different miniature golf courses. Each round of golf must have taken place after the start of this scavenger hunt. (35 points)
101
+
102
+ #9) Submit an entry to the 2011 Putter King Hole Design Contest. (60 points; 40 bonus points if your entry gets more than 100 votes)
103
+
104
+ #10) Screenshot from the Putter King app showing a 9-hole score below par. (10 points)
105
+
106
+ #11) Screenshot from the Putter King app showing that you have successfully unlocked all of the holes in the game. (45 points)
107
+
108
+ #12) Picture of the Putter King wobblehead at a World Heritage Site. (55 points)
109
+
110
+ #13) Complete and submit the Putter King ‘Practice Activity’ and ‘Final Project’ for any one of the Putter King math or physics lessons. (40 points; 20 bonus points if you complete two lessons)
111
+
112
+ #14) Picture of yourself with at least 6 different colored miniature golf balls. (10 points; 2 bonus points for each additional color {limit of 10 bonus points})
113
+
114
+ #15) Picture of yourself with a famous golfer or miniature golfer. (15 points; 150 bonus points if the golfer is on the PGA tour AND you are wearing a Putter King t-shirt in the picture)
115
+
116
+ #16) Video of yourself making a hole-in-one on a miniature golf hole with a loop-de-loop obstacle. (30 points)
117
+
118
+ #17) Video of yourself successfully making a trick miniature golf shot. (40 points; up to 100 bonus points available depending on the difficulty and complexity of the trick shot)
119
+
120
+
121
+ Prizes:
122
+
123
+ $100 iTunes Gift Card
124
+
125
+ Putter King Scavenger Hunt Trophy
126
+ (6 3/4" Engraved Crystal Trophy - Picture Coming Soon)
127
+
128
+ The Putter King team will judge the scavenger hunt and all decisions will be final. The U.S. Government is sponsoring it. The scavenger hunt is open to anyone and everyone. The scavenger hunt ends on Dec. 31st, 2011.
129
+
130
+ To enter the scavenger hunt, send an email to info AT putterking DOT com with the subject line: "Putter King Scavenger Hunt Submission". In the email please include links to the pictures and videos you are submitting. You can utilize free photo and video hosting sites such as YouTube, Flickr, Picasa, Photobucket, etc. for your submissions.
131
+
132
+ By entering the Putter King Miniature Golf Scavenger Hunt, you allow Putter King to use or link to any of the pictures or videos you submit for advertisements and promotions.
133
+
134
+ Don’t forget to use your imagination and creativity!
135
+ EOF
136
+ tokens = ConfidentialInfoRedactor::Extractor.new(text: text).extract
137
+ expect(described_class.new(text: text, language: 'en', tokens: tokens).redact).to eq(" <redacted>\n\n <redacted> is hosting the <redacted number> <redacted>. So get out your putter and your camera and see if you have what it takes. Are you a King?\n\n <redacted>: <redacted number>) Autographs of <redacted number> professional miniature golfers, each from a different country. (<redacted number> points; <redacted number> bonus points if the professional miniature golfers are also from <redacted number> different continents) <redacted number>) Picture of yourself next to each obstacle in our list of the Top <redacted number> <redacted>. (<redacted number> points; <redacted number> bonus points for each obstacle that exactly matches the one pictured in the article) <redacted number>) Build your own full-size miniature golf hole. (<redacted number> points; up to <redacted number> bonus points available depending on the craftsmanship, playability, creativity and fun factor of your hole) <redacted number>) Video of yourself making a hole-in-one on two consecutive miniature golf holes. The video must be one continuous shot with no editing. (<redacted number> points) <redacted number>) Picture of yourself with the <redacted> mascot. (<redacted number> points; <redacted number> bonus points if you are wearing a <redacted> t-shirt) <redacted number>) Picture of yourself with the completed <redacted> wobblehead. (<redacted number> points; <redacted number> bonus points if the picture is taken at a miniature golf course) <redacted number>) Picture of a completed scorecard from a round of miniature golf. The round of golf must have taken place after the start of this scavenger hunt. (<redacted number> points) <redacted number>) Picture of completed scorecards from <redacted number> different miniature golf courses. Each round of golf must have taken place after the start of this scavenger hunt. (<redacted number> points) <redacted number>) Submit an entry to the <redacted number> <redacted>. (<redacted number> points; <redacted number> bonus points if your entry gets more than <redacted number> votes) <redacted number>) <redacted> from the <redacted> app showing a 9-hole score below par. (<redacted number> points) <redacted number>) <redacted> from the <redacted> app showing that you have successfully unlocked all of the holes in the game. (<redacted number> points) <redacted number>) Picture of the <redacted> wobblehead at a <redacted>. (<redacted number> points) <redacted number>) Complete and submit the <redacted> ‘Practice Activity’ and ‘Final Project’ for any one of the <redacted> math or physics lessons. (<redacted number> points; <redacted number> bonus points if you complete two lessons) <redacted number>) Picture of yourself with at least <redacted number> different colored miniature golf balls. (<redacted number> points; <redacted number> bonus points for each additional color {limit of <redacted number> bonus points}) <redacted number>) Picture of yourself with a famous golfer or miniature golfer. (<redacted number> points; <redacted number> bonus points if the golfer is on the <redacted> tour AND you are wearing a <redacted> t-shirt in the picture) <redacted number>) Video of yourself making a hole-in-one on a miniature golf hole with a loop-de-loop obstacle. (<redacted number> points) <redacted number>) Video of yourself successfully making a trick miniature golf shot. (<redacted number> points; up to <redacted number> bonus points available depending on the difficulty and complexity of the trick shot)\n\n\n Prizes: <redacted number> <redacted> <redacted>\n\n <redacted>\n (<redacted number> <redacted number> <redacted> - <redacted>)\n\n <redacted> team will judge the scavenger hunt and all decisions will be final. <redacted> is sponsoring it. The scavenger hunt is open to anyone and everyone. The scavenger hunt ends on <redacted date>.\n\n To enter the scavenger hunt, send an email to info AT putterking DOT com with the subject line: \"<redacted>\". In the email please include links to the pictures and videos you are submitting. You can utilize free photo and video hosting sites such as <redacted>, <redacted>, <redacted>, <redacted>, etc. for your submissions.\n\n By entering the <redacted>, you allow <redacted> to use or link to any of the pictures or videos you submit for advertisements and promotions.\n\n Don’t forget to use your imagination and creativity!\n")
138
+ end
139
+
140
+ it 'redacts all confidential information from a text #003' do
141
+ tokens = ['Coca-Cola', 'Pepsi', 'John Smith']
142
+ text = 'Coca-Cola announced a merger with Pepsi that will happen on December 15th, 2020 for $200,000,000,000. Please contact John Smith at j.smith@example.com or visit http://www.super-fake-merger.com.'
143
+ expect(described_class.new(text: text, language: 'en', tokens: tokens).redact).to eq('<redacted> announced a merger with <redacted> that will happen on <redacted date> for <redacted number>. Please contact <redacted> at <redacted> or visit <redacted>.')
144
+ end
145
+
146
+ it 'redacts all confidential information from a text #004' do
147
+ tokens = ['Coca-Cola', 'Pepsi', 'John Smith']
148
+ text = 'Coca-Cola announced a merger with Pepsi that will happen on December 15th, 2020 for $200,000,000,000. Please contact John Smith at j.smith@example.com or visit http://www.super-fake-merger.com.'
149
+ expect(described_class.new(text: text, language: 'en', tokens: tokens, ignore_numbers: true).redact).to eq('<redacted> announced a merger with <redacted> that will happen on <redacted date> for $200,000,000,000. Please contact <redacted> at <redacted> or visit <redacted>.')
150
+ end
151
+ end
152
+ end
@@ -0,0 +1 @@
1
+ require 'confidential_info_redactor'
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: confidential_info_redactor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kevin S. Dias
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pragmatic_segmenter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A Ruby gem to semi-automatically redact confidential information from
70
+ a text
71
+ email:
72
+ - diasks2@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - confidential_info_redactor.gemspec
85
+ - lib/confidential_info_redactor.rb
86
+ - lib/confidential_info_redactor/date.rb
87
+ - lib/confidential_info_redactor/extractor.rb
88
+ - lib/confidential_info_redactor/hyperlink.rb
89
+ - lib/confidential_info_redactor/redactor.rb
90
+ - lib/confidential_info_redactor/version.rb
91
+ - lib/confidential_info_redactor/word_lists.rb
92
+ - spec/confidential_info_redactor/date_spec.rb
93
+ - spec/confidential_info_redactor/extractor_spec.rb
94
+ - spec/confidential_info_redactor/hyperlink_spec.rb
95
+ - spec/confidential_info_redactor/redactor_spec.rb
96
+ - spec/spec_helper.rb
97
+ homepage: https://github.com/diasks2/confidential_info_redactor
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.4.1
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Semi-automatically redact confidential information from a text
121
+ test_files:
122
+ - spec/confidential_info_redactor/date_spec.rb
123
+ - spec/confidential_info_redactor/extractor_spec.rb
124
+ - spec/confidential_info_redactor/hyperlink_spec.rb
125
+ - spec/confidential_info_redactor/redactor_spec.rb
126
+ - spec/spec_helper.rb