From 3a02fc9519e737fd1cfb13c3a71dcce73b2e03b7 Mon Sep 17 00:00:00 2001 From: Jack Kinsella Date: Wed, 1 Feb 2012 16:37:41 +0100 Subject: [PATCH] made x6 faster --- lib/style_scanner/sentence.rb | 10 +++++++--- lib/style_scanner/string.rb | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/style_scanner/sentence.rb b/lib/style_scanner/sentence.rb index 552bcdf..db22e70 100644 --- a/lib/style_scanner/sentence.rb +++ b/lib/style_scanner/sentence.rb @@ -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 @@ -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 diff --git a/lib/style_scanner/string.rb b/lib/style_scanner/string.rb index bf9d418..3a03d72 100644 --- a/lib/style_scanner/string.rb +++ b/lib/style_scanner/string.rb @@ -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)