<commit_before>require 'spec/spec_helper'

module KDL
  class SolrMaker
    def initialize(output, access_package, solrs_directory)
      @output = output
      @access_package = access_package
      @solrs_directory = solrs_directory
      unless @access_package.nil?
        @solr_directory = File.join(@solrs_directory, @access_package.identifier)
      end
    end

    def help
      @output.puts "Usage: solrmaker <DIP directory> <SOLR exports directory>"
    end

    def build
      if paged?
        pages.each do |page|
          page.save @solr_directory
        end
      else
        save
      end
    end

    def save
      FileUtils.mkdir_p(@solr_directory)
      solr_file = File.join(@solr_directory, identifier)
      File.open(solr_file, 'w') { |f|
        hash = solr_doc.dup
        f.write hash.to_json
      }
    end

    def paged?
      not(@access_package.hasOralHistory)
    end

    def solr_doc
      hash = {}
      [
        :author_t,
        :author_display,
        :title_t,
        :title_display,
        :title_sort,
        :title_processed_s,
        :description_t,
        :description_display,
        :subject_topic_facet,
        :pub_date,
        :full_date_s,
        :language_display,
        :usage_display,
        :publisher_t,
        :publisher_display,
        :repository_facet,
        :repository_display,
        :date_digitized_display,
        :format,
        :type_display,
        :relation_display,
        :mets_url_display,
        :coverage_s,
        :source_s,
        :contributor_s,
      ].each do |solr_field|
        hash[solr_field] = send(solr_field)
      end
      if @access_package.hasOralHistory
        hash.merge! oral_history_fields
      end
      if @access_package.hasFindingAid
        hash.merge! finding_aid_fields
      end
      unless paged?
        hash[:id] = identifier
        hash[:unpaged_display] = '1'
      end
      hash[:digital_content_available_s] = @access_package.hasDigitizedContent
      hash
    end

    def oral_history_fields
      hash = {}
      hash[:synchronization_url_s] = @access_package.synchronization_url
      hash[:reference_audio_url_s] = @access_package.reference_audio_url
      hash[:text] = oral_history_text
      hash[:text_s] = oral_history_text
      hash
    end

    def finding_aid_fields<commit_msg>add object_id identifier<commit_after>require 'spec/spec_helper'

module KDL
  class SolrMaker
    def initialize(output, access_package, solrs_directory)
      @output = output
      @access_package = access_package
      @solrs_directory = solrs_directory
      unless @access_package.nil?
        @solr_directory = File.join(@solrs_directory, @access_package.identifier)
      end
    end

    def help
      @output.puts "Usage: solrmaker <DIP directory> <SOLR exports directory>"
    end

    def build
      if paged?
        pages.each do |page|
          page.save @solr_directory
        end
      else
        save
      end
    end

    def save
      FileUtils.mkdir_p(@solr_directory)
      solr_file = File.join(@solr_directory, identifier)
      File.open(solr_file, 'w') { |f|
        hash = solr_doc.dup
        f.write hash.to_json
      }
    end

    def paged?
      not(@access_package.hasOralHistory)
    end

    def solr_doc
      hash = {}
      [
        :author_t,
        :author_display,
        :title_t,
        :title_display,
        :title_sort,
        :title_processed_s,
        :description_t,
        :description_display,
        :subject_topic_facet,
        :pub_date,
        :full_date_s,
        :language_display,
        :usage_display,
        :publisher_t,
        :publisher_display,
        :repository_facet,
        :repository_display,
        :date_digitized_display,
        :format,
        :type_display,
        :relation_display,
        :mets_url_display,
        :coverage_s,
        :source_s,
        :contributor_s,
      ].each do |solr_field|
        hash[solr_field] = send(solr_field)
      end
      if @access_package.hasOralHistory
        hash.merge! oral_history_fields
      end
      if @access_package.hasFindingAid
        hash.merge! finding_aid_fields
      end
      unless paged?
        hash[:id] = identifier
        hash[:unpaged_display] = '1'
      end
      hash[:object_id_s] = @access_package.identifier
      hash[:digital_content_available_s] = @access_package.hasDigitizedContent
      hash
    end

    def oral_history_fields
      hash = {}
      hash[:synchronization_url_s] = @access_package.synchronization_url
      hash[:reference_audio_url_s] = @access_package.reference_audio_url
      hash[:text] = oral_history_text
      hash[:text_s] = oral_history_text
      hash
    end

    def finding_aid_fields
{'fraction_non_alphanumeric': 0.0782993054093875, 'fraction_numerical': 0.0004209640075773521, 'mean_word_length': 2.1914036265950303, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3267657', 'n_tokens_mistral': 1522, 'n_tokens_neox': 1495, 'n_words': 275}