Module: JLPT::Jukugo

Defined in:
lib/jlpt/analyzers/jukugo.rb

Overview

Jukugo (Kanji Compound) Extractor and Classifier.

Identifies multi-kanji compound words (2-kanji, 3-kanji, 4-kanji Yojijukugo) in Japanese text.

Constant Summary collapse

JUKUGO_REGEX =
/[\u4E00-\u9FFF]{2,}/.freeze

Class Method Summary collapse

Class Method Details

.breakdown(text) ⇒ Hash

Breakdown compounds by character length (2-kanji, 3-kanji, 4-kanji+)

Parameters:

  • text (String)

    Japanese text

Returns:

  • (Hash)

    hash with keys :two_char, :three_char, :yojijukugo, :long



28
29
30
31
32
# File 'lib/jlpt/analyzers/jukugo.rb', line 28

def breakdown(text)
  result = { two_char: [], three_char: [], yojijukugo: [], long: [] }
  extract(text).each { |c| categorize_compound(c, result) }
  result
end

.extract(text) ⇒ Array<String>

Extract all kanji compounds from Japanese text

Parameters:

  • text (String)

    Japanese text

Returns:

  • (Array<String>)

    unique array of Jukugo compounds



17
18
19
20
21
22
# File 'lib/jlpt/analyzers/jukugo.rb', line 17

def extract(text)
  cleaned = Preprocessor.clean(text)
  return [] if cleaned.empty?

  cleaned.scan(JUKUGO_REGEX).uniq
end