Skip to content

Commit

Permalink
Merge branch '9feet-fix/wordsieve'
Browse files Browse the repository at this point in the history
  • Loading branch information
brenes committed Dec 19, 2021
2 parents 9908cc3 + 1b69a34 commit 82652fb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
master:
* Fixed Wordiseve class [@hmaack] [#19]

0.6.0:
* Added support for: [@bettysteger] [#16]
* Afrikaans (af)
Expand Down
18 changes: 9 additions & 9 deletions lib/stopwords/snowball/wordsieve.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module Stopwords
module Snowball
class Stopwords::Snowball::WordSieve
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, custom_list
class WordSieve
def initialize(custom_list = [])
@filters = Dir["#{File.dirname(__FILE__)}/locales/*.csv"].each_with_object({}) do |file, filters|
lang = File.basename(file, '.csv')
filters[lang.to_sym] = Stopwords::Snowball::Filter.new lang, custom_list
end
end

def stopword? args={}
args[:lang] ? @filters[args[:lang]].stopword?(args[:word] ) : false
def stopword?(args = {})
args[:lang] ? @filters[args[:lang]].stopword?(args[:word]) : false
end

def filter args={}
args[:lang] ? @filters[args[:lang]].filter(args[:words] ) : args[:words]
def filter(args = {})
args[:lang] ? @filters[args[:lang]].filter(args[:words]) : args[:words]
end
end
end
Expand Down
20 changes: 20 additions & 0 deletions spec/lib/wordsieve_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# encoding: utf-8

require_relative('../spec_helper')

describe Stopwords::Snowball::WordSieve do
subject { Stopwords::Snowball::WordSieve.new }
let(:words) { 'guide by douglas adams'.split }

describe '#filter' do
it('should remove the stopwords from the list of words') do
expect(subject.filter(lang: :en, words: words)).to eq(%w[guide douglas adams])
end
end

describe '#stopwords' do
it('should return true for stopwords') do
expect(subject.stopword?(lang: :en, word: 'by')).to be_truthy
end
end
end

0 comments on commit 82652fb

Please sign in to comment.