phonetics
Phonetics
Phonetic matching (sounds-like) matching can be done with the SoundEx or Metaphone algorithms
Installation
-
Add the dependency to your
shard.yml
:dependencies: cadmium_phonetics: github: cadmiumcr/phonetics
-
Run
shards install
Usage
require "cadmium_phonetics"
sound_ex = Cadmium.sound_ex
metaphone = Cadmium.metaphone
sound_ex.process("phonetics")
# => "P532"
sound_ex.tokenize_and_phoneticize("Ruby aint got nothing on Crystal")
# => ["R100", "A530", "G300", "C234"]
# Keep word stops
sound_ex.tokenize_and_phoneticize("Ruby aint got nothing on Crystal", true)
# => ["R100", "A530", "G300", "N352", "O000", "C234"]
sound_ex.compare("phonetix", "phonetics")
# => true
metaphone.process("phonetics")
# => "FNTKS"
metaphone.tokenize_and_phoneticize("Ruby aint got nothing on Crystal")
# => ["RB", "ANT", "KT", "KRSTL"]
# Keep word stops
metaphone.tokenize_and_phoneticize("Ruby aint got nothing on Crystal", true)
# => ["RB", "ANT", "KT", "N0NK", "ON", "KRSTL"]
metaphone.compare("phonetix", "phonetics")
# => true
Both classes can also be used with attached String methods. The default class for String methods is Metaphone
. The attached methods are phonetics
, sounds_like
, and tokenize_and_phoneticize
.
"Crystal".phonetics
# => "KRSTL"
"Crystal".sounds_like("Krystal")
# => true
"Crystal".phonetics(nil, Cadmium::SoundEx)
# => "C234"
# Using a max length
"Constitution".phonetics(6, Cadmium::SoundEx)
# => "C52333"
Contributing
- Fork it (https://github.com/cadmiumcr/phonetics/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Chris Watson - creator and maintainer
Repository
phonetics
Owner
Statistic
- 0
- 1
- 0
- 1
- 1
- over 5 years ago
- August 29, 2019
License
MIT License
Links
Synced at
Sun, 22 Dec 2024 14:20:21 GMT
Languages