Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Modify algorithm to provide a bias for the first word in the name

  • Loading branch information...
commit 6b0ffc18012f99cf4223dee96b3854ba326b3b1b 1 parent 87d9f96
@kyledrake kyledrake authored
Showing with 15 additions and 12 deletions.
  1. +15 −12 app.rb
View
27 app.rb
@@ -29,32 +29,35 @@
COMPANIES = []
- # filter_criteria = /^The |, Inc\.?| Corporation| Incorporated| Ltd\.|, Ltd| Inc\.| Inc| Corp.| Corp| Company \(The\)| Company| Bancorp| Enterprises/i
+ filter_criteria = /^The |, Inc\.?| Corporation| Incorporated| Ltd\.|, Ltd| Inc\.| Inc| Corp.| Corp| Company \(The\)| Company| Bancorp| Enterprises/i
first_row = false
CSV.foreach('./companylist.csv') do |row|
first_row = true and next if first_row
- # name = CGI.unescapeHTML row[1]
- # name.gsub!(filter_criteria, '')
- # name.strip!
- # COMPANIES << {symbol: row[0], name: name}
- COMPANIES << { name: row[1], symbol: row[0] }
+ filtered_name = CGI.unescapeHTML row[1]
+ filtered_name.gsub!(filter_criteria, '')
+ filtered_name.strip!
+ COMPANIES << { name: row[1], symbol: row[0], filtered_name: filtered_name }
end
- FUZZ = FuzzyMatch.new( COMPANIES, :read => :name )
+ FUZZ = FuzzyMatch.new( COMPANIES, :read => :filtered_name )
end
def get_quote_for_name(name)
fuzz = FUZZ.dup
- result = fuzz.find(name, :gather_last_result => true)
- return nil if result.nil?
+ # Start with first word, require it to have a high percentage
+ first_word_result = fuzz.find name.split(' ').first, :gather_last_result => true
- return nil if fuzz.last_result.score < 0.5
+ return nil if first_word_result.nil? || fuzz.last_result.score < 0.7
- quote = get_quote result[:symbol]
- quote[:name] = result[:name]
+ all_words_result = fuzz.find(name, :gather_last_result => true)
+
+ return nil if all_words_result.nil? || fuzz.last_result.score < 0.4 || first_word_result != all_words_result
+
+ quote = get_quote all_words_result[:symbol]
+ quote[:name] = all_words_result[:filtered_name]
quote
end
Please sign in to comment.
Something went wrong with that request. Please try again.