Skip to content

Commit

Permalink
made x6 faster
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkinsella committed Feb 1, 2012
1 parent 8732c4f commit 3a02fc9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/style_scanner/sentence.rb
Expand Up @@ -23,11 +23,11 @@ def adverbs
part_of_speech("RB")
end

def contains?(word, options = {})
options = {:strip_case=> true}.merge(options)
def contains?(word, option_modifications = {})
options = {:strip_case => true}.merge(option_modifications)
text_to_scan = text
text_to_scan = text_to_scan.downcase if options[:strip_case]
text_to_scan = text_to_scan.stem_verbs if options[:stem_verbs]
text_to_scan = stemmed_verbs(text_to_scan) if options[:stem_verbs]
text_to_scan.match /\b#{word}\b/
end

Expand All @@ -53,6 +53,10 @@ def part_of_speech(pos)
tagged_words.select {|tagged_word| tagged_word.tag == pos }.map(&:word)
end

def stemmed_verbs(text)
@stemmed_verbs ||= text.stem_verbs
end

def tagger
@tagger ||= Tagger.new(text)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/style_scanner/string.rb
Expand Up @@ -16,6 +16,10 @@ def titlecase
scan(/[A-Z][a-z]*/).join(" ")
end

def stemmed_verbs?
@stemmed_verbs
end

private

def is_a_verb?(word)
Expand Down

0 comments on commit 3a02fc9

Please sign in to comment.