Module: JLPT::Analyzer

Defined in:
lib/jlpt/core/analyzer.rb

Overview

Core Analyzer Engine computing overall text difficulty and JLPT level recommendation.

Constant Summary collapse

LEVEL_WEIGHTS =
{ n5: 1.0, n4: 2.0, n3: 3.0, n2: 4.0, n1: 5.0, non_jlpt: 2.5, out_of_jlpt: 3.5 }.freeze

Class Method Summary collapse

Class Method Details

.analyze(text) ⇒ JLPT::AnalysisResult

Analyze Japanese text and return structured AnalysisResult

Parameters:

  • text (String)

    Japanese text

Returns:



14
15
16
17
18
19
# File 'lib/jlpt/core/analyzer.rb', line 14

def analyze(text)
  cleaned = Preprocessor.clean(text)
  return AnalysisResult.new(text: text.to_s) if cleaned.empty?

  CacheManager.fetch(cleaned) { build_analysis_result(cleaned) }
end