From c4ecc2f9671b2f023a57ee6cac266ce894a4e4fd Mon Sep 17 00:00:00 2001 From: Lasse Skindstad Ebert Date: Tue, 5 Nov 2013 12:04:36 +0100 Subject: [PATCH 1/3] Can turn off early exit --- lib/whatlanguage.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/whatlanguage.rb b/lib/whatlanguage.rb index 07760cf..8b566c6 100644 --- a/lib/whatlanguage.rb +++ b/lib/whatlanguage.rb @@ -19,7 +19,7 @@ def initialize(*selection) # Very inefficient method for now.. but still beats the non-Bloom alternatives. # Change to better bit comparison technique later.. - def process_text(text) + def process_text(text, break_early = true) results = Hash.new(0) it = 0 text.downcase.split.each do |word| @@ -36,7 +36,7 @@ def process_text(text) end # Every now and then check to see if we have a really convincing result.. if so, exit early. - if it % 4 == 0 && results.size > 1 + if break_early && it % 4 == 0 && results.size > 1 top_results = results.sort_by{|a,b| -b}[0..1] # Next line may need some tweaking one day.. From 76ca512184732101f4c255c517af2c999688cf82 Mon Sep 17 00:00:00 2001 From: Lasse Skindstad Ebert Date: Tue, 5 Nov 2013 12:10:03 +0100 Subject: [PATCH 2/3] Changed to use options --- lib/whatlanguage.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/whatlanguage.rb b/lib/whatlanguage.rb index 8b566c6..8bc0923 100644 --- a/lib/whatlanguage.rb +++ b/lib/whatlanguage.rb @@ -19,7 +19,11 @@ def initialize(*selection) # Very inefficient method for now.. but still beats the non-Bloom alternatives. # Change to better bit comparison technique later.. - def process_text(text, break_early = true) + def process_text(text, options) + options = { + exit_early: true + }.merge options + results = Hash.new(0) it = 0 text.downcase.split.each do |word| @@ -36,7 +40,7 @@ def process_text(text, break_early = true) end # Every now and then check to see if we have a really convincing result.. if so, exit early. - if break_early && it % 4 == 0 && results.size > 1 + if options[:exit_early] && break_early && it % 4 == 0 && results.size > 1 top_results = results.sort_by{|a,b| -b}[0..1] # Next line may need some tweaking one day.. From c93e8593c645f7b424eec7390b7cdc3873f3d63f Mon Sep 17 00:00:00 2001 From: Lasse Skindstad Ebert Date: Tue, 5 Nov 2013 12:15:26 +0100 Subject: [PATCH 3/3] Fixed errors --- lib/whatlanguage.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/whatlanguage.rb b/lib/whatlanguage.rb index 8bc0923..87a122a 100644 --- a/lib/whatlanguage.rb +++ b/lib/whatlanguage.rb @@ -19,7 +19,7 @@ def initialize(*selection) # Very inefficient method for now.. but still beats the non-Bloom alternatives. # Change to better bit comparison technique later.. - def process_text(text, options) + def process_text(text, options = {}) options = { exit_early: true }.merge options @@ -40,7 +40,7 @@ def process_text(text, options) end # Every now and then check to see if we have a really convincing result.. if so, exit early. - if options[:exit_early] && break_early && it % 4 == 0 && results.size > 1 + if options[:exit_early] && it % 4 == 0 && results.size > 1 top_results = results.sort_by{|a,b| -b}[0..1] # Next line may need some tweaking one day..