<commit_before>module DarwinCore
  class SimpleMultimedia

    TERMS = [
      ['id', 'id', nil, 'core_id'],
      ['type', 'http://purl.org/dc/terms/type', nil, 'dwc_type'],
      %w(format http://purl.org/dc/terms/format),
      %w(identifier http://purl.org/dc/terms/identifier),
      %w(references http://purl.org/dc/terms/references),
      %w(created http://purl.org/dc/terms/created),
      %w(creator http://purl.org/dc/terms/creator),
      %w(publisher http://purl.org/dc/terms/publisher),
      ['license', 'http://purl.org/dc/terms/license', nil, 'dwc_license'],
      %w(rightsHolder http://purl.org/dc/terms/rightsHolder)
    ]
    TERM_NAMES = TERMS.map{|name, uri| name}

    def self.adapt(record, options = {})
      record.extend(InstanceMethods)
      record.observation = options[:observation]
      record.core = options[:core]
      record
    end
    
    module InstanceMethods
      attr_accessor :observation
      attr_accessor :core

      def core_id
        if core == 'taxon'
          observation.taxon_id
        else
          observation.id
        end
      end

      def dwc_type
        "StillImage"
      end

      def format
        file_content_type
      end

      def identifier
        original_url
      end

      def references
        native_page_url
      end

      def created
        if metadata && metadata[:date_time_original]
          metadata[:date_time_original].iso8601
        elsif observation.time_observed_at
          observation.time_observed_at.iso8601
        elsif observation.observed_on
          observation.observed_on.to_s
        end
      end

      def creator
        dwc_user_name
      end

      def publisher
        if is_a?(LocalPhoto)
          "iNaturalist"
        else
          self.class.name.sub(/Photo$/, '').underscore.titleize
        end
      end<commit_msg>Bugfix: handle bogus date_time_original values.<commit_after>module DarwinCore
  class SimpleMultimedia

    TERMS = [
      ['id', 'id', nil, 'core_id'],
      ['type', 'http://purl.org/dc/terms/type', nil, 'dwc_type'],
      %w(format http://purl.org/dc/terms/format),
      %w(identifier http://purl.org/dc/terms/identifier),
      %w(references http://purl.org/dc/terms/references),
      %w(created http://purl.org/dc/terms/created),
      %w(creator http://purl.org/dc/terms/creator),
      %w(publisher http://purl.org/dc/terms/publisher),
      ['license', 'http://purl.org/dc/terms/license', nil, 'dwc_license'],
      %w(rightsHolder http://purl.org/dc/terms/rightsHolder)
    ]
    TERM_NAMES = TERMS.map{|name, uri| name}

    def self.adapt(record, options = {})
      record.extend(InstanceMethods)
      record.observation = options[:observation]
      record.core = options[:core]
      record
    end
    
    module InstanceMethods
      attr_accessor :observation
      attr_accessor :core

      def core_id
        if core == 'taxon'
          observation.taxon_id
        else
          observation.id
        end
      end

      def dwc_type
        "StillImage"
      end

      def format
        file_content_type
      end

      def identifier
        original_url
      end

      def references
        native_page_url
      end

      def created
        if metadata && metadata[:date_time_original]
          t = begin
            Time.parse(metadata[:date_time_original]).iso8601
          rescue
            metadata[:date_time_original].iso8601
          rescue
            nil
          end
        end
        t ||= observation.time_observed_at.iso8601 if observation.time_observed_at
        t ||= observation.observed_on.to_s if observation.observed_on
        t
      end

      def creator
        dwc_user_name
      end

      def publisher
        if is_a?(LocalPhoto)
          "iNaturalist"
        else
          self.class.name.sub(/Photo$/, '').underscore.titleize
        end
      end
{'fraction_non_alphanumeric': 0.10785824345146379, 'fraction_numerical': 0.005136106831022085, 'mean_word_length': 1.9984603541185528, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7642403', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1194, 'n_words': 223}