module Wordlist::Lexer::StopWords
Stop words for various languages.
@api semipublic
@since 1.0.0
Constants
- DIRECTORY
The directory containing the stop words ‘.txt` files.
Public Class Methods
[](lang)
click to toggle source
Lazy loads the stop words for the given language.
@param [Symbol] lang
The language to load.
@return [Array<String>]
# File lib/wordlist/lexer/stop_words.rb, line 62 def self.[](lang) @mutex.synchronize do @stop_words[lang] ||= read(lang) end end
path_for(lang)
click to toggle source
The path to the stop words ‘.txt` file.
@param [Symbol] lang
The language to load.
@return [String]
# File lib/wordlist/lexer/stop_words.rb, line 25 def self.path_for(lang) ::File.join(DIRECTORY,"#{lang}.txt") end
read(lang)
click to toggle source
Reads the stop words.
@param [Symbol] lang
The language to load.
@return [Array<String>]
@raise [UnsupportedLanguage]
# File lib/wordlist/lexer/stop_words.rb, line 39 def self.read(lang) path = path_for(lang) unless ::File.file?(path) raise(UnsupportedLanguage,"unsupported language: #{lang}") end lines = ::File.readlines(path) lines.each(&:chomp!) lines end