Class: VivlioStarter::CLI::IndexCommands::IndexSizeEstimator

Inherits:
Object
  • Object
show all
Defined in:
lib/vivlio_starter/cli/index/index_size_estimator.rb

Overview

索引語数の目安を算出する

Defined Under Namespace

Classes: Estimate

Constant Summary collapse

BETA =

Heaps 則の指数。10 冊の log-log 回帰による実測値(地の文基準)。 3 倍の分量でも索引語は約 2.3 倍にしかならない。

0.749
BASE_TERMS =

5 万字時点の語数。10 冊の実測を密度で 3 群に分けたもの。 65, 88 ┊ 118, 151, 151, 167, 171, 173 ┊ 226, 228 thorough の幅が狭いのは実測が 2 冊しかないためで、 その帯が本当に狭いことを意味しない。

{
  light: (65..90),      # 控えめ: 主要な語だけを拾う
  standard: (120..175), # 標準(既定)
  thorough: (225..230)  # 丁寧: 初学者向けに広く拾う
}.freeze
DEFAULT_PRESET =
:standard
BASE_CHARS =

基準となる分量(BASE_TERMS はこの字数時点の語数)

50_000.0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chars) ⇒ IndexSizeEstimator

Returns a new instance of IndexSizeEstimator.

Parameters:

  • chars (Integer)

    地の文の文字数



90
91
92
# File 'lib/vivlio_starter/cli/index/index_size_estimator.rb', line 90

def initialize(chars)
  @chars = chars
end

Class Method Details

.prose_chars_of(chapters) ⇒ Integer

章の本文から地の文の文字数を数える。 計数の実装は Metrics::Analyzer が唯一の正典——ここで除去処理を書き直すと vs metrics の表示と黙ってずれる(§3.3)。

Parameters:

  • chapters (Array<String>)

    章のベースネームまたはパス

Returns:

  • (Integer)

    地の文の文字数(空白を除く)



73
74
75
76
77
78
# File 'lib/vivlio_starter/cli/index/index_size_estimator.rb', line 73

def self.prose_chars_of(chapters)
  chapters.sum do |chapter|
    path = resolve_path(chapter)
    path ? Metrics::Analyzer.prose_length(File.read(path, encoding: 'utf-8')) : 0
  end
end

Instance Method Details

#all_presetsArray<Estimate>

全プリセットの目安。操作盤の「設定を変えるとこうなります」に使う。

Returns:



107
# File 'lib/vivlio_starter/cli/index/index_size_estimator.rb', line 107

def all_presets = BASE_TERMS.keys.map { estimate(it) }

#estimate(setting) ⇒ Estimate

book.ymlindex.target_terms を解釈して目安を返す。 プリセット名なら Heaps 則で幅を、整数ならその語数を 1 点として返す。

Parameters:

  • setting (String, Symbol, Integer, nil)

    target_terms の値

Returns:



98
99
100
101
102
103
# File 'lib/vivlio_starter/cli/index/index_size_estimator.rb', line 98

def estimate(setting)
  case normalize(setting)
  in Integer => n then Estimate.new(preset: nil, range: (n..n), chars: @chars)
  in Symbol => preset then Estimate.new(preset:, range: range_for(preset), chars: @chars)
  end
end