Module: Spellchecker::DetectTypo
- Defined in:
- lib/spellchecker/detect_typo.rb
Constant Summary collapse
- PROPER_NAME_REGEXP =
/\A(?:[a-z]+[A-Z])|(?:[A-Z]+.+[A-Z]+)|(?:[A-Z]{2,}[^A-Z]+)/.freeze
- ABBREVIATION_REGEXP =
/\A(?:[A-Z]{2,4})|(?:[A-Z][a-z])\z/.freeze
- LENGTH_LIMIT =
2
Class Method Summary collapse
Class Method Details
.call(token) ⇒ Spellchecker::Mistake?
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/spellchecker/detect_typo.rb', line 14 def call(token) word = token.text return if word.length < LENGTH_LIMIT correction = Dictionaries::TyposList.match_token(token) return unless correction return if PROPER_NAME_REGEXP.match?(word) return if ABBREVIATION_REGEXP.match?(word) return if Dictionaries::EnglishWords.include?(Utils.replace_quote(word)) return if token.capital? && proper_noun?(word) correction = correction.sub(/\S/, &:upcase) if token.capital? Mistake.new(text: word, correction: correction, position: token.position, type: MistakeTypes::SPELLING) end |
.proper_noun?(word) ⇒ Boolean
36 37 38 39 40 |
# File 'lib/spellchecker/detect_typo.rb', line 36 def proper_noun?(word) Dictionaries::HumanNames.include?(word) || Dictionaries::CompanyNames.include?(word) || Dictionaries::UsToponyms.include?(word) end |