Module: Wordlist::Lexer::StopWords
- Defined in:
- lib/wordlist/lexer/stop_words.rb
Overview
Stop words for various languages.
Constant Summary collapse
- DIRECTORY =
The directory containing the stop words
.txt
files. ::File.(::File.join(__dir__,'..','..','..','data','stop_words'))
Class Method Summary collapse
-
.[](lang) ⇒ Array<String>
Lazy loads the stop words for the given language.
-
.path_for(lang) ⇒ String
The path to the stop words
.txt
file. -
.read(lang) ⇒ Array<String>
Reads the stop words.
Class Method Details
.[](lang) ⇒ Array<String>
Lazy loads the stop words for the given language.
62 63 64 65 66 |
# 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) ⇒ String
The path to the stop words .txt
file.
25 26 27 |
# File 'lib/wordlist/lexer/stop_words.rb', line 25 def self.path_for(lang) ::File.join(DIRECTORY,"#{lang}.txt") end |
.read(lang) ⇒ Array<String>
Reads the stop words.
39 40 41 42 43 44 45 46 47 48 49 |
# 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 |