From be6f73a406b86f53f38b4b4ab7b5889f2c4743d5 Mon Sep 17 00:00:00 2001 From: Brian Hempel Date: Tue, 17 Jul 2012 00:37:28 -0400 Subject: [PATCH] Fuzzy -> FuzzyTools --- Gemfile | 2 +- Rakefile | 2 +- accuracy/test_accuracy.rb | 6 +-- fuzzy.gemspec => fuzzy_tools.gemspec | 8 ++-- lib/fuzzy.rb | 4 -- lib/fuzzy/tokenizers.rb | 30 ------------- lib/fuzzy_tools.rb | 4 ++ .../core_ext/enumerable.rb | 4 +- lib/{fuzzy => fuzzy_tools}/helpers.rb | 2 +- lib/{fuzzy => fuzzy_tools}/index.rb | 6 +-- lib/{fuzzy => fuzzy_tools}/tf_idf_index.rb | 8 ++-- lib/fuzzy_tools/tokenizers.rb | 30 +++++++++++++ lib/{fuzzy => fuzzy_tools}/version.rb | 2 +- .../weighted_document_tokens.rb | 6 +-- performance/profile.rb | 6 +-- spec/enumerable_spec.rb | 12 ++--- spec/helpers_spec.rb | 20 ++++----- spec/spec_helper.rb | 2 +- spec/tf_idf_index_spec.rb | 44 +++++++++---------- 19 files changed, 99 insertions(+), 99 deletions(-) rename fuzzy.gemspec => fuzzy_tools.gemspec (81%) delete mode 100644 lib/fuzzy.rb delete mode 100644 lib/fuzzy/tokenizers.rb create mode 100644 lib/fuzzy_tools.rb rename lib/{fuzzy => fuzzy_tools}/core_ext/enumerable.rb (91%) rename lib/{fuzzy => fuzzy_tools}/helpers.rb (99%) rename lib/{fuzzy => fuzzy_tools}/index.rb (91%) rename lib/{fuzzy => fuzzy_tools}/tf_idf_index.rb (95%) create mode 100644 lib/fuzzy_tools/tokenizers.rb rename lib/{fuzzy => fuzzy_tools}/version.rb (57%) rename lib/{fuzzy => fuzzy_tools}/weighted_document_tokens.rb (94%) diff --git a/Gemfile b/Gemfile index 3ae3d2a..c2cf192 100644 --- a/Gemfile +++ b/Gemfile @@ -5,5 +5,5 @@ gem 'nokogiri' gem 'perftools.rb', :require => false gem 'rake' -# Specify your gem's dependencies in fuzzy.gemspec +# Specify your gem's dependencies in fuzzy_tools.gemspec gemspec diff --git a/Rakefile b/Rakefile index 32a2f3c..dfcd8ac 100644 --- a/Rakefile +++ b/Rakefile @@ -16,7 +16,7 @@ desc "Launch an IRB session with the gem required" task :console do $:.unshift(File.dirname(__FILE__) + '/../lib') - require 'fuzzy' + require 'fuzzy_tools' require 'irb' IRB.setup(nil) diff --git a/accuracy/test_accuracy.rb b/accuracy/test_accuracy.rb index 68b4a7f..85749a5 100644 --- a/accuracy/test_accuracy.rb +++ b/accuracy/test_accuracy.rb @@ -1,7 +1,7 @@ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__) $LOAD_PATH.unshift File.expand_path("../support", __FILE__) -require 'fuzzy' +require 'fuzzy_tools' require 'accuracy_test_case' require 'histogram' require 'rubygems' @@ -19,10 +19,10 @@ class Failure < Struct.new(:given, :expected, :actual) ENV['CPUPROFILE_REALTIME'] = "1" ENV['CPUPROFILE_FREQUENCY=500'] = "50" # default is 100 require 'perftools' -PerfTools::CpuProfiler.start("/tmp/fuzzy_ruby_profile") +PerfTools::CpuProfiler.start("/tmp/fuzzy_tools_ruby_profile") at_exit do PerfTools::CpuProfiler.stop - puts `pprof.rb --text /tmp/fuzzy_ruby_profile` + puts `pprof.rb --text /tmp/fuzzy_tools_ruby_profile` end total_time = Benchmark.realtime do diff --git a/fuzzy.gemspec b/fuzzy_tools.gemspec similarity index 81% rename from fuzzy.gemspec rename to fuzzy_tools.gemspec index 8fdfad5..68758b0 100644 --- a/fuzzy.gemspec +++ b/fuzzy_tools.gemspec @@ -1,14 +1,14 @@ # -*- encoding: utf-8 -*- $:.push File.expand_path("../lib", __FILE__) -require "fuzzy/version" +require "fuzzy_tools/version" Gem::Specification.new do |s| - s.name = "fuzzy" - s.version = Fuzzy::VERSION + s.name = "fuzzy_tools_tools" + s.version = FuzzyTools::VERSION s.platform = Gem::Platform::RUBY s.authors = ["Brian Hempel"] s.email = ["plasticchicken@gmail.com"] - s.homepage = "" + s.homepage = "https://github.com/brianhempel/fuzzy_tools" s.summary = %q{High quality fuzzy search and string matching in Ruby.} s.description = %q{High quality fuzzy search and string matching in Ruby.} diff --git a/lib/fuzzy.rb b/lib/fuzzy.rb deleted file mode 100644 index 40ee53a..0000000 --- a/lib/fuzzy.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'fuzzy/helpers' -require 'fuzzy/index' -require 'fuzzy/tf_idf_index' -require 'fuzzy/core_ext/enumerable' diff --git a/lib/fuzzy/tokenizers.rb b/lib/fuzzy/tokenizers.rb deleted file mode 100644 index c7cffc5..0000000 --- a/lib/fuzzy/tokenizers.rb +++ /dev/null @@ -1,30 +0,0 @@ -module Fuzzy - module Tokenizers - - CHARACTERS = lambda { |str| str.chars } - CHARACTERS_DOWNCASED = lambda { |str| str.downcase.chars } - BIGRAMS = lambda { |str| Fuzzy::Helpers.ngrams(str, 2) } - BIGRAMS_DOWNCASED = lambda { |str| Fuzzy::Helpers.ngrams(str.downcase, 2) } - TRIGRAMS = lambda { |str| Fuzzy::Helpers.ngrams(str, 3) } - TRIGRAMS_DOWNCASED = lambda { |str| Fuzzy::Helpers.ngrams(str.downcase, 3) } - TETRAGRAMS = lambda { |str| Fuzzy::Helpers.ngrams(str, 4) } - TETRAGRAMS_DOWNCASED = lambda { |str| Fuzzy::Helpers.ngrams(str.downcase, 4) } - PENTAGRAMS = lambda { |str| Fuzzy::Helpers.ngrams(str, 5) } - PENTAGRAMS_DOWNCASED = lambda { |str| Fuzzy::Helpers.ngrams(str.downcase, 5) } - HEXAGRAMS = lambda { |str| Fuzzy::Helpers.ngrams(str, 6) } - HEXAGRAMS_DOWNCASED = lambda { |str| Fuzzy::Helpers.ngrams(str.downcase, 6) } - - WORDS = lambda { |str| str.split } - WORDS_DOWNCASED = lambda { |str| str.downcase.split } - - HYBRID = lambda do |str| - str = str.downcase - words = str.split - words.map { |word| Fuzzy::Helpers.soundex(word) } + - Fuzzy::Helpers.ngrams(str.downcase, 2) + - words.map { |word| word.gsub(/[aeiou]/, '') } + - words - end - - end -end \ No newline at end of file diff --git a/lib/fuzzy_tools.rb b/lib/fuzzy_tools.rb new file mode 100644 index 0000000..8be8737 --- /dev/null +++ b/lib/fuzzy_tools.rb @@ -0,0 +1,4 @@ +require 'fuzzy_tools/helpers' +require 'fuzzy_tools/index' +require 'fuzzy_tools/tf_idf_index' +require 'fuzzy_tools/core_ext/enumerable' diff --git a/lib/fuzzy/core_ext/enumerable.rb b/lib/fuzzy_tools/core_ext/enumerable.rb similarity index 91% rename from lib/fuzzy/core_ext/enumerable.rb rename to lib/fuzzy_tools/core_ext/enumerable.rb index 7d071a4..3b073cd 100644 --- a/lib/fuzzy/core_ext/enumerable.rb +++ b/lib/fuzzy_tools/core_ext/enumerable.rb @@ -1,4 +1,4 @@ -require 'fuzzy/index' +require 'fuzzy_tools/index' module Enumerable def fuzzy_find(*args) @@ -13,7 +13,7 @@ def fuzzy_find_all(*args) def fuzzy_index(options = {}) options = options.merge(:source => self) - Fuzzy::TfIdfIndex.new(options) + FuzzyTools::TfIdfIndex.new(options) end private diff --git a/lib/fuzzy/helpers.rb b/lib/fuzzy_tools/helpers.rb similarity index 99% rename from lib/fuzzy/helpers.rb rename to lib/fuzzy_tools/helpers.rb index db9efb5..8af8977 100644 --- a/lib/fuzzy/helpers.rb +++ b/lib/fuzzy_tools/helpers.rb @@ -1,6 +1,6 @@ require 'inline' -module Fuzzy +module FuzzyTools module Helpers extend self diff --git a/lib/fuzzy/index.rb b/lib/fuzzy_tools/index.rb similarity index 91% rename from lib/fuzzy/index.rb rename to lib/fuzzy_tools/index.rb index 970d871..11c1d23 100644 --- a/lib/fuzzy/index.rb +++ b/lib/fuzzy_tools/index.rb @@ -1,7 +1,7 @@ -require 'fuzzy/helpers' -require 'fuzzy/tokenizers' +require 'fuzzy_tools/helpers' +require 'fuzzy_tools/tokenizers' -module Fuzzy +module FuzzyTools class Index attr_reader :source, :indexed_attribute diff --git a/lib/fuzzy/tf_idf_index.rb b/lib/fuzzy_tools/tf_idf_index.rb similarity index 95% rename from lib/fuzzy/tf_idf_index.rb rename to lib/fuzzy_tools/tf_idf_index.rb index c55e08e..2759f94 100644 --- a/lib/fuzzy/tf_idf_index.rb +++ b/lib/fuzzy_tools/tf_idf_index.rb @@ -1,8 +1,8 @@ require 'set' -require 'fuzzy/index' -require 'fuzzy/weighted_document_tokens' +require 'fuzzy_tools/index' +require 'fuzzy_tools/weighted_document_tokens' -module Fuzzy +module FuzzyTools class TfIdfIndex < Index class Token attr_accessor :documents, :idf @@ -13,7 +13,7 @@ def initialize end def self.default_tokenizer - Fuzzy::Tokenizers::HYBRID + FuzzyTools::Tokenizers::HYBRID end attr_reader :tokenizer diff --git a/lib/fuzzy_tools/tokenizers.rb b/lib/fuzzy_tools/tokenizers.rb new file mode 100644 index 0000000..2d1cfd6 --- /dev/null +++ b/lib/fuzzy_tools/tokenizers.rb @@ -0,0 +1,30 @@ +module FuzzyTools + module Tokenizers + + CHARACTERS = lambda { |str| str.chars } + CHARACTERS_DOWNCASED = lambda { |str| str.downcase.chars } + BIGRAMS = lambda { |str| FuzzyTools::Helpers.ngrams(str, 2) } + BIGRAMS_DOWNCASED = lambda { |str| FuzzyTools::Helpers.ngrams(str.downcase, 2) } + TRIGRAMS = lambda { |str| FuzzyTools::Helpers.ngrams(str, 3) } + TRIGRAMS_DOWNCASED = lambda { |str| FuzzyTools::Helpers.ngrams(str.downcase, 3) } + TETRAGRAMS = lambda { |str| FuzzyTools::Helpers.ngrams(str, 4) } + TETRAGRAMS_DOWNCASED = lambda { |str| FuzzyTools::Helpers.ngrams(str.downcase, 4) } + PENTAGRAMS = lambda { |str| FuzzyTools::Helpers.ngrams(str, 5) } + PENTAGRAMS_DOWNCASED = lambda { |str| FuzzyTools::Helpers.ngrams(str.downcase, 5) } + HEXAGRAMS = lambda { |str| FuzzyTools::Helpers.ngrams(str, 6) } + HEXAGRAMS_DOWNCASED = lambda { |str| FuzzyTools::Helpers.ngrams(str.downcase, 6) } + + WORDS = lambda { |str| str.split } + WORDS_DOWNCASED = lambda { |str| str.downcase.split } + + HYBRID = lambda do |str| + str = str.downcase + words = str.split + words.map { |word| FuzzyTools::Helpers.soundex(word) } + + FuzzyTools::Helpers.ngrams(str.downcase, 2) + + words.map { |word| word.gsub(/[aeiou]/, '') } + + words + end + + end +end \ No newline at end of file diff --git a/lib/fuzzy/version.rb b/lib/fuzzy_tools/version.rb similarity index 57% rename from lib/fuzzy/version.rb rename to lib/fuzzy_tools/version.rb index aab1eec..9261c44 100644 --- a/lib/fuzzy/version.rb +++ b/lib/fuzzy_tools/version.rb @@ -1,3 +1,3 @@ -module Fuzzy +module FuzzyTools VERSION = "0.0.1" end diff --git a/lib/fuzzy/weighted_document_tokens.rb b/lib/fuzzy_tools/weighted_document_tokens.rb similarity index 94% rename from lib/fuzzy/weighted_document_tokens.rb rename to lib/fuzzy_tools/weighted_document_tokens.rb index 4dee344..2122f06 100644 --- a/lib/fuzzy/weighted_document_tokens.rb +++ b/lib/fuzzy_tools/weighted_document_tokens.rb @@ -1,7 +1,7 @@ -require 'fuzzy/helpers' +require 'fuzzy_tools/helpers' require 'inline' -module Fuzzy +module FuzzyTools class WeightedDocumentTokens attr_reader :weights @@ -57,7 +57,7 @@ def tokens def set_token_weights(tokens, &block) @weights = {} - counts = Fuzzy::Helpers.term_counts(tokens) + counts = FuzzyTools::Helpers.term_counts(tokens) counts.each do |token, n| @weights[token] = yield(token, n) end diff --git a/performance/profile.rb b/performance/profile.rb index 7a2631b..ab2e993 100644 --- a/performance/profile.rb +++ b/performance/profile.rb @@ -1,7 +1,7 @@ require 'csv' $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__) -require 'fuzzy' +require 'fuzzy_tools' TEST_FILE_PATH = File.expand_path("../query_tests/bible_verses_daniel_kjv.csv", __FILE__) @@ -24,10 +24,10 @@ ENV['CPUPROFILE_REALTIME'] = "1" ENV['CPUPROFILE_FREQUENCY=500'] = "200" # default is 100 require 'perftools' -PerfTools::CpuProfiler.start("/tmp/fuzzy_ruby_profile") +PerfTools::CpuProfiler.start("/tmp/fuzzy_tools_ruby_profile") at_exit do PerfTools::CpuProfiler.stop - puts `pprof.rb --text /tmp/fuzzy_ruby_profile` + puts `pprof.rb --text /tmp/fuzzy_tools_ruby_profile` end index = targets.fuzzy_index diff --git a/spec/enumerable_spec.rb b/spec/enumerable_spec.rb index a4f42c7..6a0b188 100644 --- a/spec/enumerable_spec.rb +++ b/spec/enumerable_spec.rb @@ -27,7 +27,7 @@ before(:each) { @letter_count_tokenizer = lambda { |str| str.size.to_s } } it "passes :tokenizer through to the index with simple query syntax" do - Fuzzy::TfIdfIndex.should_receive(:new).with(:source => @books, :tokenizer => @letter_count_tokenizer) + FuzzyTools::TfIdfIndex.should_receive(:new).with(:source => @books, :tokenizer => @letter_count_tokenizer) begin @books.fuzzy_find("the", :tokenizer => @letter_count_tokenizer) rescue @@ -35,7 +35,7 @@ end it "passes :tokenizer through to the index with :attribute => query syntax" do - Fuzzy::TfIdfIndex.should_receive(:new).with(:source => @books, :tokenizer => @letter_count_tokenizer, :attribute => :title) + FuzzyTools::TfIdfIndex.should_receive(:new).with(:source => @books, :tokenizer => @letter_count_tokenizer, :attribute => :title) begin @books.fuzzy_find(:title => "the", :tokenizer => @letter_count_tokenizer) rescue @@ -57,7 +57,7 @@ before(:each) { @letter_count_tokenizer = lambda { |str| str.size.to_s } } it "passes :tokenizer through to the index with simple query syntax" do - Fuzzy::TfIdfIndex.should_receive(:new).with(:source => @books, :tokenizer => @letter_count_tokenizer) + FuzzyTools::TfIdfIndex.should_receive(:new).with(:source => @books, :tokenizer => @letter_count_tokenizer) begin @books.fuzzy_find_all("the", :tokenizer => @letter_count_tokenizer) rescue @@ -65,7 +65,7 @@ end it "passes :tokenizer through to the index with :attribute => query syntax" do - Fuzzy::TfIdfIndex.should_receive(:new).with(:source => @books, :tokenizer => @letter_count_tokenizer, :attribute => :title) + FuzzyTools::TfIdfIndex.should_receive(:new).with(:source => @books, :tokenizer => @letter_count_tokenizer, :attribute => :title) begin @books.fuzzy_find_all(:title => "the", :tokenizer => @letter_count_tokenizer) rescue @@ -76,12 +76,12 @@ describe "#fuzzy_index" do it "returns an TfIdfIndex" do - @books.fuzzy_index.class.should == Fuzzy::TfIdfIndex + @books.fuzzy_index.class.should == FuzzyTools::TfIdfIndex end it "passes options along to the index" do letter_count_tokenizer = lambda { |str| str.size.to_s } - Fuzzy::TfIdfIndex.should_receive(:new).with(:source => @books, :tokenizer => letter_count_tokenizer, :attribute => :title) + FuzzyTools::TfIdfIndex.should_receive(:new).with(:source => @books, :tokenizer => letter_count_tokenizer, :attribute => :title) @books.fuzzy_index(:attribute => :title, :tokenizer => letter_count_tokenizer) end end diff --git a/spec/helpers_spec.rb b/spec/helpers_spec.rb index 9d44a73..03676fe 100644 --- a/spec/helpers_spec.rb +++ b/spec/helpers_spec.rb @@ -1,10 +1,10 @@ require 'spec_helper' -describe Fuzzy::Helpers do +describe FuzzyTools::Helpers do describe ".ngrams" do it "should do trigrams" do - Fuzzy::Helpers.trigrams("hello").should == %w{ + FuzzyTools::Helpers.trigrams("hello").should == %w{ __h _he hel @@ -16,7 +16,7 @@ end it "should do bigrams" do - Fuzzy::Helpers.bigrams("hello").should == %w{ + FuzzyTools::Helpers.bigrams("hello").should == %w{ _h he el @@ -27,7 +27,7 @@ end it "should do 1-grams" do - Fuzzy::Helpers.ngrams("hello", 1).should == %w{ + FuzzyTools::Helpers.ngrams("hello", 1).should == %w{ h e l @@ -37,7 +37,7 @@ end it "should do x-grams" do - Fuzzy::Helpers.ngrams("hello", 4).should == %w{ + FuzzyTools::Helpers.ngrams("hello", 4).should == %w{ ___h __he _hel @@ -53,11 +53,11 @@ describe ".soundex" do it "works" do - Fuzzy::Helpers.soundex("Robert").should == "R163" - Fuzzy::Helpers.soundex("Rubin").should == "R150" - Fuzzy::Helpers.soundex("Washington").should == "W252" - Fuzzy::Helpers.soundex("Lee").should == "L000" - Fuzzy::Helpers.soundex("Gutierrez").should == "G362" + FuzzyTools::Helpers.soundex("Robert").should == "R163" + FuzzyTools::Helpers.soundex("Rubin").should == "R150" + FuzzyTools::Helpers.soundex("Washington").should == "W252" + FuzzyTools::Helpers.soundex("Lee").should == "L000" + FuzzyTools::Helpers.soundex("Gutierrez").should == "G362" end end end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 667f0b2..c7733b8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,5 @@ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib")) -require 'fuzzy' +require 'fuzzy_tools' Book = Struct.new(:title, :author) diff --git a/spec/tf_idf_index_spec.rb b/spec/tf_idf_index_spec.rb index 2f93d62..c3f6917 100644 --- a/spec/tf_idf_index_spec.rb +++ b/spec/tf_idf_index_spec.rb @@ -1,25 +1,25 @@ require 'spec_helper' -describe Fuzzy::TfIdfIndex do +describe FuzzyTools::TfIdfIndex do it "takes a source" do vegetables = ["mushroom", "olive", "tomato"] - index = Fuzzy::TfIdfIndex.new(:source => vegetables) + index = FuzzyTools::TfIdfIndex.new(:source => vegetables) index.source.should == vegetables end it "indexes on to_s by default" do - index = Fuzzy::TfIdfIndex.new(:source => 1..3) + index = FuzzyTools::TfIdfIndex.new(:source => 1..3) index.find("2").should == 2 end - it "defaults tokenizer to Fuzzy::Tokenizers::HYBRID" do - Fuzzy::TfIdfIndex.new(:source => []).tokenizer.should == Fuzzy::Tokenizers::HYBRID + it "defaults tokenizer to FuzzyTools::Tokenizers::HYBRID" do + FuzzyTools::TfIdfIndex.new(:source => []).tokenizer.should == FuzzyTools::Tokenizers::HYBRID end it "takes any proc as a tokenizer" do foods = ["muffins", "pancakes"] letter_count_tokenizer = lambda { |str| str.size.to_s } - index = Fuzzy::TfIdfIndex.new(:source => foods, :tokenizer => letter_count_tokenizer) + index = FuzzyTools::TfIdfIndex.new(:source => foods, :tokenizer => letter_count_tokenizer) index.tokenizer.should == letter_count_tokenizer index.find("octoword").should == "pancakes" @@ -39,12 +39,12 @@ end it "indexes on the method specified in :attribute" do - index = Fuzzy::TfIdfIndex.new(:source => @books, :attribute => :title) + index = FuzzyTools::TfIdfIndex.new(:source => @books, :attribute => :title) index.find("ecklestica").should == @ecclesiates end it "indexes the proc result if a proc is given for :attribute" do - index = Fuzzy::TfIdfIndex.new(:source => @books, :attribute => lambda { |book| book.title + " " + book.author }) + index = FuzzyTools::TfIdfIndex.new(:source => @books, :attribute => lambda { |book| book.title + " " + book.author }) index.find("prodigy").should == @the_prodigal_god index.find("LEWIS").should == @till_we_have_faces end @@ -64,12 +64,12 @@ end it "indexes on the hash key specified in :attribute" do - index = Fuzzy::TfIdfIndex.new(:source => @books, :attribute => :title) + index = FuzzyTools::TfIdfIndex.new(:source => @books, :attribute => :title) index.find("ecklestica").should == @ecclesiates end it "indexes the proc result if a proc is given for :attribute" do - index = Fuzzy::TfIdfIndex.new(:source => @books, :attribute => lambda { |book| book[:title] + " " + book[:author] }) + index = FuzzyTools::TfIdfIndex.new(:source => @books, :attribute => lambda { |book| book[:title] + " " + book[:author] }) index.find("prodigy").should == @the_prodigal_god index.find("LEWIS").should == @till_we_have_faces end @@ -79,18 +79,18 @@ describe "#find" do it "returns the best result" do mushy_stuff = ["mushrooms", "mushroom", "mushy pit", "ABC"] - index = Fuzzy::TfIdfIndex.new(:source => mushy_stuff) + index = FuzzyTools::TfIdfIndex.new(:source => mushy_stuff) index.find("ushr").should == "mushroom" end it "calls to_s on input" do - index = Fuzzy::TfIdfIndex.new(:source => 1..3) + index = FuzzyTools::TfIdfIndex.new(:source => 1..3) index.find(2).should == 2 end it "returns nil if no results" do - index = Fuzzy::TfIdfIndex.new(:source => 1..3) + index = FuzzyTools::TfIdfIndex.new(:source => 1..3) index.find("bubble").should be_nil end end @@ -98,7 +98,7 @@ describe "#all" do it "returns all results, from best to worst" do mushy_stuff = ["mushrooms", "mushroom", "mushy pit", "ABC"] - index = Fuzzy::TfIdfIndex.new(:source => mushy_stuff) + index = FuzzyTools::TfIdfIndex.new(:source => mushy_stuff) index.all("ushr").should == [ "mushroom", @@ -108,12 +108,12 @@ end it "calls to_s on input" do - index = Fuzzy::TfIdfIndex.new(:source => 1..3) + index = FuzzyTools::TfIdfIndex.new(:source => 1..3) index.all(2).first.should == 2 end it "returns an empty array if no results" do - index = Fuzzy::TfIdfIndex.new(:source => 1..3) + index = FuzzyTools::TfIdfIndex.new(:source => 1..3) index.all("bubble").should == [] end end @@ -122,7 +122,7 @@ describe "#all" do it "returns all results, from best to worst" do mushy_stuff = ["mushrooms", "mushroom", "mushy pit", "ABC"] - index = Fuzzy::TfIdfIndex.new(:source => mushy_stuff) + index = FuzzyTools::TfIdfIndex.new(:source => mushy_stuff) index.all("ushr").should == [ "mushroom", @@ -132,12 +132,12 @@ end it "calls to_s on input" do - index = Fuzzy::TfIdfIndex.new(:source => 1..3) + index = FuzzyTools::TfIdfIndex.new(:source => 1..3) index.all(2).first.should == 2 end it "returns an empty array if no results" do - index = Fuzzy::TfIdfIndex.new(:source => 1..3) + index = FuzzyTools::TfIdfIndex.new(:source => 1..3) index.all("bubble").should == [] end end @@ -145,7 +145,7 @@ describe "#all_with_scores" do it "returns ordered array of arrays of score and results" do mushy_stuff = ["mushrooms", "mushroom", "mushy pit", "ABC"] - index = Fuzzy::TfIdfIndex.new(:source => mushy_stuff) + index = FuzzyTools::TfIdfIndex.new(:source => mushy_stuff) results = index.all_with_scores("ushr") @@ -164,12 +164,12 @@ end it "calls to_s on input" do - index = Fuzzy::TfIdfIndex.new(:source => 1..3) + index = FuzzyTools::TfIdfIndex.new(:source => 1..3) index.all_with_scores(2).first.should == [1.0, 2] end it "returns an empty array if no results" do - index = Fuzzy::TfIdfIndex.new(:source => 1..3) + index = FuzzyTools::TfIdfIndex.new(:source => 1..3) index.all_with_scores("bubble").should == [] end end