Sha256: 27c0ad65e7ce038611c5659b3e4a7538eb322a39ffb91cc7765e22aa410f0d1c

Contents?: true

Size: 1.09 KB

Versions: 64

Compression:

Stored size: 1.09 KB

Contents

# encoding: utf-8

module XapianDb
  module Repositories

    # The stopper is a repository that manages stoppers for the supported
    # languges
    # @author Gernot Kogler
    class Stopper

      class << self

        # Get or build the stopper for a language
        # @param [Symbol, String] iso_cd The iso code for the language (:en, :de ...)
        # @return [Xapian::SimpleStopper] The Stopper for this lanugage
        def stopper_for(iso_cd)
          @stoppers ||= {}
          return nil if iso_cd.nil?
          key = iso_cd.to_sym

          # Do we already have a stopper for this language?
          return @stoppers[key] unless @stoppers[key].nil?

          # build the stopper
          stopper = Xapian::SimpleStopper.new
          stopwords_file = File.join(File.dirname(__FILE__), '../stopwords', "#{iso_cd}.txt")

          return nil unless File.exist? stopwords_file

          open(stopwords_file, "r") do |file|
            file.each do |word|
              stopper.add word.chomp
            end
          end
          @stoppers[key] = stopper
        end

      end

    end

  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
xapian_db-1.3.3 lib/xapian_db/repositories/stopper.rb
xapian_db-1.3.2 lib/xapian_db/repositories/stopper.rb
xapian_db-1.3.1 lib/xapian_db/repositories/stopper.rb
xapian_db-1.3 lib/xapian_db/repositories/stopper.rb
xapian_db-1.2.5.1 lib/xapian_db/repositories/stopper.rb
xapian_db-1.2.5 lib/xapian_db/repositories/stopper.rb
xapian_db-1.2.4.7 lib/xapian_db/repositories/stopper.rb
xapian_db-1.2.4.6 lib/xapian_db/repositories/stopper.rb
xapian_db-1.2.4.5 lib/xapian_db/repositories/stopper.rb
xapian_db-1.2.4.4 lib/xapian_db/repositories/stopper.rb
xapian_db-1.2.4.3 lib/xapian_db/repositories/stopper.rb
xapian_db-1.2.4.2 lib/xapian_db/repositories/stopper.rb
xapian_db-1.2.4.1 lib/xapian_db/repositories/stopper.rb
xapian_db-1.2.4 lib/xapian_db/repositories/stopper.rb
xapian_db-1.2.3 lib/xapian_db/repositories/stopper.rb
xapian_db-1.2.2.2 lib/xapian_db/repositories/stopper.rb
xapian_db-1.2.2.1 lib/xapian_db/repositories/stopper.rb
xapian_db-1.2.2 lib/xapian_db/repositories/stopper.rb
xapian_db-1.2.1.1 lib/xapian_db/repositories/stopper.rb
xapian_db-1.2.1 lib/xapian_db/repositories/stopper.rb