<commit_before>require 'umakadata/sparql_helper'
require 'umakadata/logging/log'

module Umakadata

  module Criteria

    module Liveness
      ##
      # A boolan value whether if the SPARQL endpoint is alive.
      #
      # @param  uri [URI]: the target endpoint
      # @param  args [Hash]:
      # @return [Boolean]
      def alive?(uri, time_out, logger: nil)
        sparql_query = 'SELECT * WHERE {?s ?p ?o} LIMIT 1'

        [:post, :get].each do |method|
          request_log = Umakadata::Logging::Log.new
          logger.push request_log unless logger.nil?
          response = Umakadata::SparqlHelper.query(uri, sparql_query, logger: request_log, options: {method: method})
          unless response.nil?
            request_log.result = "#{method.to_s.capitalize}: 200 HTTP response"
            logger.result = "Alive is true" unless logger.nil?
            return true
          end
          request_log.result = "#{method.to_s.capitalize}: HTTP response error"
        end
        logger.result = "Alive is false" unless logger.nil?
        false
      end

    end

  end

end<commit_msg>Add log message to liveness<commit_after>require 'umakadata/sparql_helper'
require 'umakadata/logging/log'

module Umakadata

  module Criteria

    module Liveness
      ##
      # A boolan value whether if the SPARQL endpoint is alive.
      #
      # @param  uri [URI]: the target endpoint
      # @param  args [Hash]:
      # @return [Boolean]
      def alive?(uri, time_out, logger: nil)
        sparql_query = 'SELECT * WHERE {?s ?p ?o} LIMIT 1'

        [:post, :get].each do |method|
          request_log = Umakadata::Logging::Log.new
          logger.push request_log unless logger.nil?
          response = Umakadata::SparqlHelper.query(uri, sparql_query, logger: request_log, options: {method: method})
          if response.is_a? Net::HTTPOK
            request_log.result = "#{method.to_s.capitalize}: 200 HTTP response"
            logger.result = "The endpoint is alive" unless logger.nil?
            return true
          end
          if response.is_a? Net::HTTPResponse
            request_log.result = "#{method.to_s.capitalize}: #{response.code} HTTP response"
          else
            request_log.result = "#{method.to_s.capitalize}: HTTP connection could not be established"
          end
        end
        logger.result = "The endpoint is down" unless logger.nil?
        false
      end

    end

  end

end
{'fraction_non_alphanumeric': 0.0973017170891251, 'fraction_numerical': 0.003270645952575634, 'mean_word_length': 2.320217096336499, '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': '2273985', 'n_tokens_mistral': 744, 'n_tokens_neox': 722, 'n_words': 209}