Class: Kotoshu::Languages::Japanese
Overview
Japanese language implementation.
Supports ja-JP with full CJK script support.
Uses morphological analysis via Suika gem for tokenization and POS tagging.
Japanese spell checking uses dictionary lookup with CJK character support.
Defined Under Namespace
Modules: GrammarRules
Classes: POSTagger, SpellChecker, Tokenizer
Constant Summary
collapse
- HUNSPELL_DICTIONARIES =
{
'ja-JP' => {
}
}.freeze
- VARIANT_NAMES =
{
'JP' => 'Japan'
}.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: "ja", name: "Japanese", variant: nil) ⇒ Japanese
Returns a new instance of Japanese.
416
417
418
419
|
# File 'lib/kotoshu/languages/ja/language.rb', line 416
def initialize(code: "ja", name: "Japanese", variant: nil)
variant ||= (code)
super
end
|
Instance Method Details
#create_pos_tagger ⇒ Object
460
461
462
463
464
465
|
# File 'lib/kotoshu/languages/ja/language.rb', line 460
def create_pos_tagger
POSTagger.new(
dictionary_path: default_dictionary_paths.first,
flag_mapping: POSTagger::FLAG_TO_POS
)
end
|
#create_spell_checker ⇒ Object
448
449
450
451
452
453
454
|
# File 'lib/kotoshu/languages/ja/language.rb', line 448
def create_spell_checker
SpellChecker.new(
dic_path: default_dictionary_paths.first,
script: :cjk
)
end
|
#create_tokenizer ⇒ Object
456
457
458
|
# File 'lib/kotoshu/languages/ja/language.rb', line 456
def create_tokenizer
Tokenizer.new
end
|
#default_dictionary_paths ⇒ Object
440
441
442
|
# File 'lib/kotoshu/languages/ja/language.rb', line 440
def default_dictionary_paths
["/usr/share/dict/words"]
end
|
#description ⇒ Object
421
422
423
424
425
426
|
# File 'lib/kotoshu/languages/ja/language.rb', line 421
def description
return name unless variant
variant_name = VARIANT_NAMES[variant] || variant
"#{name} (#{variant_name})"
end
|
#dictionary_class ⇒ Object
436
437
438
|
# File 'lib/kotoshu/languages/ja/language.rb', line 436
def dictionary_class
Dictionary::UnixWords
end
|
#normalizer ⇒ Object
432
433
434
|
# File 'lib/kotoshu/languages/ja/language.rb', line 432
def normalizer
@normalizer ||= Language::Normalizer::Base.new
end
|
#script_type ⇒ Object
444
445
446
|
# File 'lib/kotoshu/languages/ja/language.rb', line 444
def script_type
:cjk
end
|
#tokenizer ⇒ Object
428
429
430
|
# File 'lib/kotoshu/languages/ja/language.rb', line 428
def tokenizer
@tokenizer ||= Tokenizer.new
end
|