Module: JLPT::Dictionary
- Defined in:
- lib/jlpt/core/dictionary.rb
Overview
Thread-safe In-Memory Dictionary Manager for JLPT Vocabulary and Kanji Datasets.
Loaded from Bluskyo JLPT_Vocabulary datasets (N5 to N1).
Constant Summary collapse
- DATA_DIR =
File.('../data', __dir__)
- MUTEX =
Mutex.new
Class Method Summary collapse
-
.kanji_exists?(char) ⇒ Boolean
Check if a kanji exists in the JLPT kanji dataset.
-
.kanji_level(char) ⇒ Symbol?
Look up the JLPT level of a single Kanji character.
-
.reading_for(word) ⇒ String?
Look up reading (furigana) for a vocabulary word.
-
.vocab_exists?(word) ⇒ Boolean
Check if a word exists in the JLPT vocabulary dataset.
-
.vocab_level(word) ⇒ Symbol?
Look up the JLPT level of a vocabulary word (dictionary form or lemma).
Class Method Details
.kanji_exists?(char) ⇒ Boolean
Check if a kanji exists in the JLPT kanji dataset
62 63 64 |
# File 'lib/jlpt/core/dictionary.rb', line 62 def kanji_exists?(char) !kanji_level(char).nil? end |
.kanji_level(char) ⇒ Symbol?
Look up the JLPT level of a single Kanji character
42 43 44 45 46 47 48 |
# File 'lib/jlpt/core/dictionary.rb', line 42 def kanji_level(char) ensure_loaded! return nil if char.nil? || char.to_s.strip.empty? kanji_char = char.to_s.strip[0] @kanji_index[kanji_char] end |
.reading_for(word) ⇒ String?
Look up reading (furigana) for a vocabulary word
31 32 33 34 35 36 |
# File 'lib/jlpt/core/dictionary.rb', line 31 def reading_for(word) ensure_loaded! return nil if word.nil? || word.to_s.strip.empty? @readings_index[word.to_s.strip] end |
.vocab_exists?(word) ⇒ Boolean
Check if a word exists in the JLPT vocabulary dataset
54 55 56 |
# File 'lib/jlpt/core/dictionary.rb', line 54 def vocab_exists?(word) !vocab_level(word).nil? end |
.vocab_level(word) ⇒ Symbol?
Look up the JLPT level of a vocabulary word (dictionary form or lemma)
20 21 22 23 24 25 |
# File 'lib/jlpt/core/dictionary.rb', line 20 def vocab_level(word) ensure_loaded! return nil if word.nil? || word.to_s.strip.empty? @vocab_index[word.to_s.strip] end |