Class: Kotoshu::Languages::Russian
Overview
Russian language implementation.
Supports multiple dialects: ru-RU, ru-BY, ru-KZ, ru-KG, ru-MD
Full Hunspell integration with spell checking, POS tagging, and grammar rules
specifically handling Russian Cyrillic script and case system.
Defined Under Namespace
Modules: GrammarRules
Classes: POSTagger, SpellChecker, Tokenizer
Constant Summary
collapse
- HUNSPELL_DICTIONARIES =
{
'ru-RU' => {
aff: 'spec/integrational/fixtures/ru_RU.aff',
dic: 'spec/integrational/fixtures/ru_RU.dic'
}
}.freeze
- VARIANT_NAMES =
{
'RU' => 'Russian',
'BY' => 'Belarusian',
'KZ' => 'Kazakh',
'KG' => 'Kyrgyz',
'MD' => 'Moldovan'
}.freeze
Instance Attribute Summary
#code, #name, #region, #variant
Instance Method Summary
collapse
#base_code, #base_language?, #compatible_with?, #encoding, #full_name, #info, instance, #matches_code?, #normalize, #normalize_word, #region_code, register, registered_codes, #rtl?, #tokenize, #valid_word?
Constructor Details
#initialize(code: "ru", name: "Russian", variant: nil) ⇒ Russian
Returns a new instance of Russian.
344
345
346
347
348
|
# File 'lib/kotoshu/languages/ru/language.rb', line 344
def initialize(code: "ru", name: "Russian", variant: nil)
variant ||= (code)
super
@hunspell_paths = resolve_hunspell_paths(code)
end
|
Instance Method Details
#create_pos_tagger ⇒ Object
394
395
396
397
398
399
400
401
|
# File 'lib/kotoshu/languages/ru/language.rb', line 394
def create_pos_tagger
POSTagger.new(
aff_path: @hunspell_paths[:aff],
dic_path: @hunspell_paths[:dic],
script: :cyrillic,
flag_mapping: POSTagger::FLAG_TO_POS
)
end
|
#create_spell_checker ⇒ Object
382
383
384
385
386
387
388
|
# File 'lib/kotoshu/languages/ru/language.rb', line 382
def create_spell_checker
SpellChecker.new(
aff_path: @hunspell_paths[:aff],
dic_path: @hunspell_paths[:dic],
script: :cyrillic
)
end
|
#create_tokenizer ⇒ Object
390
391
392
|
# File 'lib/kotoshu/languages/ru/language.rb', line 390
def create_tokenizer
Tokenizer.new
end
|
#default_dictionary_paths ⇒ Object
369
370
371
372
373
374
375
376
|
# File 'lib/kotoshu/languages/ru/language.rb', line 369
def default_dictionary_paths
case code
when "ru-RU"
["/usr/share/dict/russian"]
else
["/usr/share/dict/words"]
end
end
|
#description ⇒ Object
350
351
352
353
354
355
|
# File 'lib/kotoshu/languages/ru/language.rb', line 350
def description
return name unless variant
variant_name = VARIANT_NAMES[variant] || variant
"#{name} (#{variant_name})"
end
|
#dictionary_class ⇒ Object
365
366
367
|
# File 'lib/kotoshu/languages/ru/language.rb', line 365
def dictionary_class
Dictionary::UnixWords
end
|
#normalizer ⇒ Object
361
362
363
|
# File 'lib/kotoshu/languages/ru/language.rb', line 361
def normalizer
@normalizer ||= Language::Normalizer::Base.new
end
|
#script_type ⇒ Object
378
379
380
|
# File 'lib/kotoshu/languages/ru/language.rb', line 378
def script_type
:cyrillic
end
|
#tokenizer ⇒ Object
357
358
359
|
# File 'lib/kotoshu/languages/ru/language.rb', line 357
def tokenizer
@tokenizer ||= Tokenizer.new
end
|