Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Possible to run full scan #22

Open
wants to merge 4 commits into from

1 participant

@lasseebert

I use whatlanguage to scan a possibly multi-language text to find out if it is multi-language. (I process_text to find most likely languages)

With this change I get to scan the entire text. Is this inside the scope of whatlanguage?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 2 deletions.
  1. +6 −2 lib/whatlanguage.rb
View
8 lib/whatlanguage.rb
@@ -30,7 +30,11 @@ def languages
# 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, options = {})
+ options = {
+ exit_early: true
+ }.merge options
+
results = Hash.new(0)
it = 0
text.downcase.split.each do |word|
@@ -41,7 +45,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 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..
Something went wrong with that request. Please try again.