Permalink
Browse files

Languages method

  • Loading branch information...
1 parent fd49f99 commit bc717ce1b888030a899dbc485ea790dda9ce449e @lasseebert lasseebert committed Nov 5, 2013
Showing with 12 additions and 7 deletions.
  1. +12 −7 lib/whatlanguage.rb
View
@@ -16,6 +16,17 @@ def initialize(*selection)
@@data[lang[/\w+/].to_sym] ||= BloominSimple.from_dump(File.new(File.join(languages_folder, lang), 'rb').read, &HASHER)
end
end
+
+ def languages
+ @languages ||=
+ begin
+ if @selection.include?(:all)
+ languages = @@data.keys
+ else
+ languages = @@data.keys & @selection # intersection
+ end
+ end
+ end
# Very inefficient method for now.. but still beats the non-Bloom alternatives.
# Change to better bit comparison technique later..
@@ -25,16 +36,10 @@ def process_text(text)
text.downcase.split.each do |word|
it += 1
- if @selection.include?(:all)
- languages = @@data.keys
- else
- languages = @@data.keys & @selection # intersection
- end
-
languages.each do |lang|
results[lang] += 1 if @@data[lang].includes?(word)
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
top_results = results.sort_by{|a,b| -b}[0..1]

0 comments on commit bc717ce

Please sign in to comment.