Last active
December 17, 2015 13:09
-
-
Save dirtyhenry/5614761 to your computer and use it in GitHub Desktop.
Proof of concept of the jaccard gem for String comparisons, including benchmark for a set of 100 names (fake band names generated by http://www.bandnamemaker.com/ with an exception for "The Strokes"). Type names on the standard input and find out the closest match.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'jaccard' | |
require 'benchmark' | |
artists = [ | |
"The Strokes", | |
"Brilliant herb", | |
"Sparse refuge", | |
"Shrieking dagger", | |
"Twelve Haunted Homes", | |
"Wise crypt", | |
"Shining Shore", | |
"Hobbitwight", | |
"Dim Man", | |
"Outer freebooter", | |
"Two Black Armors", | |
"Tree and Ship Inn", | |
"Plaindawn", | |
"Seventh fang", | |
"Big Lightning", | |
"Walking Prince", | |
"Waterthief", | |
"Bow of Mouthes", | |
"Dwarrow Duke", | |
"Lonepoint", | |
"Lone Half Amulets", | |
"Unicorns of Folk", | |
"Blacklibrary", | |
"Rainbow unicorn", | |
"Monster of the Ships", | |
"Ten Heart Dukes", | |
"Emeralds of Bridge", | |
"Dale and Swan Inn", | |
"Riven pit", | |
"Realm and Tree", | |
"Eight sage", | |
"Revenge Suicide", | |
"Reaction Funny", | |
"Inflatable Avalanche", | |
"Justin Into Incognito", | |
"Club Grizzly", | |
"Solid Scorn", | |
"Equilibrium Despite Thought", | |
"Storm Spectacle", | |
"Hydroponic Drake", | |
"Upon Junky", | |
"Untamed Of The Silky", | |
"Even Wisdom", | |
"Gentle Labia Of The Hooked Destiny", | |
"Vacuous Force And The Poke", | |
"Underground Delivery", | |
"Creamy Boner", | |
"Panic Dune", | |
"Quik Of Dreamy", | |
"Searching Downs", | |
"Foolish Shop And The Stance", | |
"Groove Puffin", | |
"Thirsty Angel", | |
"Greasy Shack", | |
"Horrid Opus", | |
"Area Asteroid", | |
"Rocky Coach", | |
"Blazed Antique", | |
"Censored Vacation", | |
"Sweet Army", | |
"Challenge Stereotype", | |
"Sterling Angel", | |
"Diner Spring", | |
"Coaster Of The Whack", | |
"Contrast Of Lifeless", | |
"Reverent Shower", | |
"Purifying Conclusion Of The Inside Wicked", | |
"Republican Paradox", | |
"Secret Of The Fiery", | |
"Dolphin Of Tramp", | |
"Fractured Of The Pointy", | |
"Overnight Deal And The Emergency", | |
"Circus Season", | |
"Valid Form", | |
"Neat Epiphany", | |
"Static Scrap", | |
"Postal Laconic And The Last Appeal", | |
"Moon Erection", | |
"Lobotomized Mourning", | |
"Never Charcoal", | |
"Among Island", | |
"Conference Advantage", | |
"Common Bingo", | |
"Raspberry Godfather", | |
"Dollar Adrenalin", | |
"Conflicting Fusion Of The Part Onslaught", | |
"Carbonated Vanity", | |
"Erectile Greed", | |
"Republic Prairie", | |
"Calcium Of Liquor", | |
"Luscious Smile", | |
"Last Callous", | |
"Slapping Quibble", | |
"Show Bean", | |
"Frenzy Of Yellow", | |
"Struggle Of The Scaffold", | |
"Catatonic Crutch", | |
"Psycho Teen", | |
"Sanctity Funeral", | |
"Metro Of The Flogging", | |
"Aqueous Eyes" | |
] | |
# Transform the Strings into Arrays of characters | |
artists.map! do |artist| | |
artist.chars | |
end | |
# Read the input | |
ARGF.each_line do |e| | |
# Find the closest match | |
input_name = e.chars | |
best_match = nil | |
puts Benchmark.measure { best_match = Jaccard.closest_to(input_name, artists) } | |
distance = Jaccard.distance(input_name, best_match) | |
puts "Best match of #{input_name.join} is: #{best_match.join} (#{distance})" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment