Module: JLPT::Simplifier

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

Overview

Text Simplifier and Beginner Synonym Recommender.

Scans Japanese text for complex N2/N1 vocabulary and recommends simpler N5/N4/N3 synonym alternatives for Japanese language learners.

Constant Summary collapse

DATA_PATH =
File.expand_path('../data/simplifications.json', __dir__)
MUTEX =
Mutex.new

Class Method Summary collapse

Class Method Details

.simplify(text) ⇒ Array<Hash>

Analyze text and return simplification suggestions for high-level words

Parameters:

  • text (String)

    Japanese text

Returns:

  • (Array<Hash>)

    array of simplification suggestions



21
22
23
24
25
26
27
28
29
# File 'lib/jlpt/analyzers/simplifier.rb', line 21

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

  dataset = load_dataset!
  dataset.filter_map do |word, data|
    build_suggestion(word, data) if cleaned.include?(word)
  end
end