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
-
.breakdown(text) ⇒ Hash
Breakdown compounds by character length (2-kanji, 3-kanji, 4-kanji+).
-
.extract(text) ⇒ Array<String>
Extract all kanji compounds from Japanese text.
Class Method Details
.breakdown(text) ⇒ Hash
Breakdown compounds by character length (2-kanji, 3-kanji, 4-kanji+)
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
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 |