<commit_before># Copyright (c) 2008-2020 <NAME>, <NAME>, <NAME>,
#                         <NAME>
#
# This program is free software.
# You can distribute or modify this program under the terms of
# the GNU LGPL, Lesser General Public License version 2.1.
#

require 'review/book/index'
require 'review/exception'
require 'review/builder'
require 'review/sec_counter'

module ReVIEW
  class IndexBuilder < Builder
    attr_reader :list_index, :table_index, :equation_index, :footnote_index,
                :numberless_image_index, :image_index, :icon_index, :indepimage_index,
                :headline_index, :column_index, :bibpaper_index

    def initialize(strict = false, *args)
      super
    end

    def pre_paragraph
      ''
    end

    def post_paragraph
      ''
    end

    def bind(compiler, chapter, location)
      @compiler = compiler
      @chapter = chapter
      @location = location
      @output = StringIO.new
      if @chapter.present?
        @book = @chapter.book
      end
      builder_init_file
    end

    def builder_init_file
      @sec_counter = SecCounter.new(5, @chapter)

      @headline_stack = []

      @list_index = ReVIEW::Book::ListIndex.new
      @table_index = ReVIEW::Book::TableIndex.new
      @equation_index = ReVIEW::Book::EquationIndex.new
      @footnote_index = ReVIEW::Book::FootnoteIndex.new
      @headline_index = ReVIEW::Book::HeadlineIndex.new(@chapter)
      @column_index = ReVIEW::Book::ColumnIndex.new
      @chapter_index = ReVIEW::Book::ChapterIndex.new
      @bibpaper_index = ReVIEW::Book::BibpaperIndex.new

      if @book
        @image_index = ReVIEW::Book::ImageIndex.new(@chapter)
        @icon_index = ReVIEW::Book::IconIndex.new(@chapter)
        @numberless_image_index = ReVIEW::Book::NumberlessImageIndex.new(@chapter)
        @indepimage_index = ReVIEW::Book::IndepImageIndex.new(@chapter)
      end
    end
    private :builder_init_file

    def result
      nil
    end

    def target_name
      'index'
    end

    def headline(level, label, caption)
      @sec_counter.inc(level)
      return if level < 2

      cursor = level - 2

      if label
        @headline_stack[cursor] = label
      else
        @headline_stack[cursor] = caption
      end
      if @headline_stack.size > cursor + 1
        @headline_stack = @headline_stack.take(cursor + 1)
      end

      item_id = @headline_stack.join('|')

      item = ReVIEW::Book::Index::Item.new(item_id, @sec_counter.number_list, caption)
      @headline_index.add_item(item)
    end

    def nonum_begin(level, label, caption)
      cursor = level - 2

      if label
        @headline_stack[cursor] = label
      else
        @headline_stack[cursor] = caption
      end
      if @headline_stack.size > cursor + 1
        @headline_stack = @headline_stack.take(cursor + 1)
      end

      item_id = @headline_stack.join('|')

      item = ReVIEW::Book::Index::Item.new(item_id, nil, caption)
      @headline_index.add_item(item)
    end

    def nonum_end(_level)
    end

    def notoc_begin(level, label, caption)
      cursor = level - 2

      if label
        @headline_stack[cursor] = label
      else
        @headline_stack[cursor] = caption
      end
      if @headline_stack.size > cursor + 1
        @headline_stack = @headline_stack.take(cursor + 1)
      end

      item_id = @headline_stack.join('|')

      item = ReVIEW::Book::Index::Item.new(item_id, nil, caption)
      @headline_index.add_item(item)
    end

    def notoc_end(_level)
    end

    def nodisp_begin(level, label, caption)
      cursor = level - 2<commit_msg>skip level 1 on nodisp and notoc as same as headline. Closes: #1566<commit_after># Copyright (c) 2008-2020 <NAME>, <NAME>, <NAME>,
#                         <NAME>
#
# This program is free software.
# You can distribute or modify this program under the terms of
# the GNU LGPL, Lesser General Public License version 2.1.
#

require 'review/book/index'
require 'review/exception'
require 'review/builder'
require 'review/sec_counter'

module ReVIEW
  class IndexBuilder < Builder
    attr_reader :list_index, :table_index, :equation_index, :footnote_index,
                :numberless_image_index, :image_index, :icon_index, :indepimage_index,
                :headline_index, :column_index, :bibpaper_index

    def initialize(strict = false, *args)
      super
    end

    def pre_paragraph
      ''
    end

    def post_paragraph
      ''
    end

    def bind(compiler, chapter, location)
      @compiler = compiler
      @chapter = chapter
      @location = location
      @output = StringIO.new
      if @chapter.present?
        @book = @chapter.book
      end
      builder_init_file
    end

    def builder_init_file
      @sec_counter = SecCounter.new(5, @chapter)

      @headline_stack = []

      @list_index = ReVIEW::Book::ListIndex.new
      @table_index = ReVIEW::Book::TableIndex.new
      @equation_index = ReVIEW::Book::EquationIndex.new
      @footnote_index = ReVIEW::Book::FootnoteIndex.new
      @headline_index = ReVIEW::Book::HeadlineIndex.new(@chapter)
      @column_index = ReVIEW::Book::ColumnIndex.new
      @chapter_index = ReVIEW::Book::ChapterIndex.new
      @bibpaper_index = ReVIEW::Book::BibpaperIndex.new

      if @book
        @image_index = ReVIEW::Book::ImageIndex.new(@chapter)
        @icon_index = ReVIEW::Book::IconIndex.new(@chapter)
        @numberless_image_index = ReVIEW::Book::NumberlessImageIndex.new(@chapter)
        @indepimage_index = ReVIEW::Book::IndepImageIndex.new(@chapter)
      end
    end
    private :builder_init_file

    def result
      nil
    end

    def target_name
      'index'
    end

    def headline(level, label, caption)
      @sec_counter.inc(level)
      return if level < 2

      cursor = level - 2

      if label
        @headline_stack[cursor] = label
      else
        @headline_stack[cursor] = caption
      end
      if @headline_stack.size > cursor + 1
        @headline_stack = @headline_stack.take(cursor + 1)
      end

      item_id = @headline_stack.join('|')

      item = ReVIEW::Book::Index::Item.new(item_id, @sec_counter.number_list, caption)
      @headline_index.add_item(item)
    end

    def nonum_begin(level, label, caption)
      return if level < 2

      cursor = level - 2

      if label
        @headline_stack[cursor] = label
      else
        @headline_stack[cursor] = caption
      end
      if @headline_stack.size > cursor + 1
        @headline_stack = @headline_stack.take(cursor + 1)
      end

      item_id = @headline_stack.join('|')

      item = ReVIEW::Book::Index::Item.new(item_id, nil, caption)
      @headline_index.add_item(item)
    end

    def nonum_end(_level)
    end

    def notoc_begin(level, label, caption)
      return if level < 2

      cursor = level - 2

      if label
        @headline_stack[cursor] = label
      else
        @headline_stack[cursor] = caption
      end
      if @headline_stack.size > cursor + 1
        @headline_stack = @headline_stack.take(cursor + 1)
      end

      item_id = @headline_stack.join('|')

      item = ReVIEW::Book::Index::Item.new(item_id, nil, caption)
      @headline_index.add_item(item)
    end

    def notoc_end(_level)
    end

    def nodisp_begin(level, label, caption)
      return if level < 2

      cursor = level - 2
{'fraction_non_alphanumeric': 0.10203802489399535, 'fraction_numerical': 0.007112570099849542, 'mean_word_length': 2.630585898709037, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3800023', 'n_tokens_mistral': 2417, 'n_tokens_neox': 2260, 'n_words': 511}