Module: JLPT::Onomatopeia
- Defined in:
- lib/jlpt/analyzers/onomatopeia.rb
Overview
Onomatopoeia (擬音語 Giongo & 擬態語 Gitaito) Extractor.
Identifies Japanese sound-symbolic and mimetic words in Hiragana or Katakana.
Constant Summary collapse
- ONOMATOPOEIA_PATTERNS =
%w[ どきどき わくわく ぺらぺら にこにこ ふわふわ ぎっしり ギリギリ イライラ キラキラ ドキドキ ニコニコ ペラペラ もちもち すらすら どんどん だんだん いろいろ ぴったり すっきり さっぱり のんびり うっとり がっかり しっかり はっきり こっそり ゆっくり びっくり ばっちり めっきり うろうろ ぶらぶら ごちゃごちゃ そわそわ すやすや ぐっすり ].freeze
- REDUPLICATED_REGEX =
Regex for 2-mora repeated reduplicated patterns (ABAB)
/^(\p{Hiragana}{2}|\p{Katakana}{2})\1$/.freeze
Class Method Summary collapse
-
.extract(text) ⇒ Array<String>
Extract onomatopoeia words from Japanese text.
Class Method Details
.extract(text) ⇒ Array<String>
Extract onomatopoeia words from Japanese text
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/jlpt/analyzers/onomatopeia.rb', line 26 def extract(text) cleaned = Preprocessor.clean(text) return [] if cleaned.empty? matches = ONOMATOPOEIA_PATTERNS.select { |word| cleaned.include?(word) } morphemes = Tokenizer.lemmata(cleaned) morphemes.each do |m| matches << m if m.match?(REDUPLICATED_REGEX) && m.length == 4 end matches.uniq end |