Class: Kotoshu::Languages::Japanese

Inherits:
Kotoshu::Language::Base show all
Defined in:
lib/kotoshu/languages/ja/language.rb

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' => {
    # Japanese dictionaries are in custom formats
    # Suika uses its own dictionary format
  }
}.freeze
VARIANT_NAMES =
{
  'JP' => 'Japan'
}.freeze

Instance Attribute Summary

Attributes inherited from Kotoshu::Language::Base

#code, #name, #region, #variant

Instance Method Summary collapse

Methods inherited from Kotoshu::Language::Base

#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 ||= extract_region_code(code)
  super
end

Instance Method Details

#create_pos_taggerObject



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_checkerObject



448
449
450
451
452
453
454
# File 'lib/kotoshu/languages/ja/language.rb', line 448

def create_spell_checker
  # Japanese uses custom dictionary, not Hunspell format
  SpellChecker.new(
    dic_path: default_dictionary_paths.first,
    script: :cjk
  )
end

#create_tokenizerObject



456
457
458
# File 'lib/kotoshu/languages/ja/language.rb', line 456

def create_tokenizer
  Tokenizer.new
end

#default_dictionary_pathsObject



440
441
442
# File 'lib/kotoshu/languages/ja/language.rb', line 440

def default_dictionary_paths
  ["/usr/share/dict/words"]
end

#descriptionObject



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_classObject



436
437
438
# File 'lib/kotoshu/languages/ja/language.rb', line 436

def dictionary_class
  Dictionary::UnixWords
end

#normalizerObject



432
433
434
# File 'lib/kotoshu/languages/ja/language.rb', line 432

def normalizer
  @normalizer ||= Language::Normalizer::Base.new
end

#script_typeObject



444
445
446
# File 'lib/kotoshu/languages/ja/language.rb', line 444

def script_type
  :cjk
end

#tokenizerObject



428
429
430
# File 'lib/kotoshu/languages/ja/language.rb', line 428

def tokenizer
  @tokenizer ||= Tokenizer.new
end