Module: Spellchecker::Dictionaries::UsToponyms
- Defined in:
- lib/spellchecker/dictionaries/us_toponyms.rb
Constant Summary collapse
- MUTEX =
Mutex.new
- PATH =
Dictionaries.path.join('us_toponyms.csv')
Class Method Summary collapse
Class Method Details
.all ⇒ Set<String>
13 14 15 16 17 |
# File 'lib/spellchecker/dictionaries/us_toponyms.rb', line 13 def all @all || MUTEX.synchronize do @all ||= load_names end end |
.include?(name) ⇒ Boolean
21 22 23 24 25 |
# File 'lib/spellchecker/dictionaries/us_toponyms.rb', line 21 def include?(name) return false unless name all.include?(Utils.remove_suffix(name)) end |
.load_names ⇒ Set<String>
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/spellchecker/dictionaries/us_toponyms.rb', line 28 def load_names csv = CSV.parse(PATH.read, headers: true, col_sep: '|') csv.each_with_object(Set.new) do |row, set| set.add(row['City']) if row['City'] set.add(row['State full']) if row['State full'] set.add(row['County'].to_s.split(/\s+/).map(&:capitalize).join(' ')) unless row['County'].to_s.empty? set.add(row['City alias']) if row['City alias'] end end |