Skip to content
Browse files

Support custom list for snowball

  • Loading branch information...
1 parent 97d0b49 commit dc2bbd5ad30bc6d1b7e6056051e10e885ae7dcff @sbeckeriv sbeckeriv committed Dec 20, 2013
Showing with 16 additions and 5 deletions.
  1. +2 −2 lib/stopwords/snowball/filter.rb
  2. +2 −2 lib/stopwords/snowball/wordsieve.rb
  3. +12 −1 spec/lib/snowball_filter_spec.rb
View
4 lib/stopwords/snowball/filter.rb
@@ -4,12 +4,12 @@ class Filter < Stopwords::Filter
attr_reader :locale
attr_reader :locale_filename
- def initialize locale
+ def initialize locale, custom_list = []
@locale = locale
@locale_filename = "#{File.dirname(__FILE__)}/locales/#{locale}.csv"
raise "Unknown locale" unless File.exists?(@locale_filename)
- super File.read(@locale_filename).split(",")
+ super File.read(@locale_filename).split(",") + custom_list
end
end
end
View
4 lib/stopwords/snowball/wordsieve.rb
@@ -1,10 +1,10 @@
module Stopwords
module Snowball
class Stopwords::Snowball::WordSieve
- def initialize
+ def initialize custom_list = []
@filters = Dir[File.dirname(__FILE__) + '/locales/*.csv'].each_with_object({}) do |file, filters|
lang = File.basename(file, '.csv').to_sym
- filters[lang] = Stopwords::Snowball::Filter.new lang
+ filters[lang] = Stopwords::Snowball::Filter.new lang, custom_list
end
end
View
13 spec/lib/snowball_filter_spec.rb
@@ -15,5 +15,16 @@
end
+ context "when custom list" do
-end
+ let (:filter) { Stopwords::Snowball::Filter.new "es", ["Santurce"] }
+
+ subject { filter }
+
+ it("should remove the stopwords for the list of words to be filtered") { filter.filter("desde Santurce a Bilbao".split).should == ["Bilbao"]}
+
+ end
+
+
+
+end

0 comments on commit dc2bbd5

Please sign in to comment.
Something went wrong with that request. Please try again.