Class: VivlioStarter::CLI::Metrics::WarningChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/vivlio_starter/cli/metrics/formatter.rb

Overview

章・節の警告判定

Constant Summary collapse

MIN_SENTENCES_FOR_COMPLEXITY =

読解難度(RS)を警告に使うために必要な最小文数。数文しかない章の RS は 平均文長・連長のブレが大きく、難解判定が偶然で振れるため判定しない。

10
PROFESSIONAL_LABEL =

建石式 RS の最難バンド(metrics.readability.standard 未満)のラベル。

'Professional'

Instance Method Summary collapse

Constructor Details

#initialize(config_loader) ⇒ WarningChecker

Returns a new instance of WarningChecker.



443
444
445
446
447
448
# File 'lib/vivlio_starter/cli/metrics/formatter.rb', line 443

def initialize(config_loader)
  @config = config_loader
  @labels = config_loader.labels
  @exclude = config_loader.exclude_chapters
  @mattr_window = Analyzer::DEFAULT_MATTR_WINDOW
end

Instance Method Details

#chapter_warning(chapter_num, chars) ⇒ Object

章の警告を判定する



451
452
453
454
455
# File 'lib/vivlio_starter/cli/metrics/formatter.rb', line 451

def chapter_warning(chapter_num, chars)
  return nil if excluded?(chapter_num)

  check_volume(chars, thresholds[:chapter])
end

#excluded_chapter?(chapter_num) ⇒ Boolean

Returns:

  • (Boolean)


489
490
491
# File 'lib/vivlio_starter/cli/metrics/formatter.rb', line 489

def excluded_chapter?(chapter_num)
  excluded?(chapter_num)
end

#has_warning?(chapter_num, chars, sections, analysis: nil) ⇒ Boolean

警告がある章かどうか。analysis を渡すと品質警告も対象に含める (--warn で「単調・難解と評価された章だけを見る」ため)。

Returns:

  • (Boolean)


482
483
484
485
486
487
# File 'lib/vivlio_starter/cli/metrics/formatter.rb', line 482

def has_warning?(chapter_num, chars, sections, analysis: nil)
  return true if chapter_warning(chapter_num, chars)
  return true if analysis && quality_warnings(analysis).any?

  sections.any? { section_warning(it.chars, chapter_num:) }
end

#quality_warnings(analysis) ⇒ Array<String>

品質警告(語彙多様度・読解難度)を判定する。分量警告と違い ChapterAnalysis(vocab / readability)が要るため章構造体には持たせず、 表示時に毎回導出する(しきい値・ラベルの変更が再解析なしで効く)。 発火条件は詳細分析の評価バンドと完全に同一 (metrics-quality-warnings-spec.md §1.1)。

Parameters:

Returns:

  • (Array<String>)

    該当ラベルの配列(該当なし・除外章は空)



471
472
473
474
475
476
477
478
# File 'lib/vivlio_starter/cli/metrics/formatter.rb', line 471

def quality_warnings(analysis)
  return [] if excluded?(analysis.chapter.chapter_num)

  warnings = []
  warnings << labels[:monotonous] if monotonous?(analysis.vocab)
  warnings << labels[:too_complex] if too_complex?(analysis.readability)
  warnings
end

#section_warning(chars, chapter_num: nil) ⇒ Object

節の警告を判定する



458
459
460
461
462
# File 'lib/vivlio_starter/cli/metrics/formatter.rb', line 458

def section_warning(chars, chapter_num: nil)
  return nil if excluded?(chapter_num)

  check_volume(chars, thresholds[:section])
end