Created
September 5, 2010 23:26
-
-
Save bkerley/566430 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# wrote it, didn't try it | |
module TWSS | |
class Body | |
def initialize(text) | |
@text = text | |
end | |
def sentences | |
@text.split(/\?|\.|\;/).map{ |s| Sentence.new(s) } | |
end | |
def filtered_sentences | |
sentences.map(&:filtered).join(' ') | |
end | |
end | |
class Sentence < String | |
DIRT = File.read('words.txt').split("\n") | |
THRESHOLD = 0.5 | |
def words | |
split | |
end | |
def cuss_words | |
words.select{|w| DIRT.include? w } | |
end | |
def dirty_ratio | |
cuss_words.length.to_f / words.length.to_f | |
end | |
def dirty? | |
dirty_ratio >= THRESHOLD | |
end | |
def filtered | |
return self unless dirty? | |
"\n#{self} (THAT'S WHAT SHE SAID)\n" | |
end | |
end | |
end | |
body = TWSS::Body.new(File.read(ARGV[0])) | |
puts body.filtered_sentences |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment