<commit_before># Represents a query on a datasource, abstract representation of SPARQL features
# is passed to federation/adapter for execution on data
#
# Author:: <NAME>
# Copyright:: (c) 2005-2006
# License:: LGPL
require 'active_rdf'
require 'federation/federation_manager'

# TODO add log for every method which constitues to the query

class Query
  attr_reader :select_clauses, :where_clauses, :keywords, :limits, :offsets
  bool_accessor :distinct, :ask, :select, :count, :keyword

  def initialize
    $log.debug "Query: initializing"
    distinct = false
		limit = nil
		offset = nil
    @select_clauses = []
    @where_clauses = []
		@keywords = []
  end

	def clear_select
    $log.debug "Query: clearing select query"
		@select_clauses = []
		distinct = false
	end

  def select *s
    @select = true
    s.each do |e|
      @select_clauses << parametrise(e) 
    end
		# removing duplicate select clauses
		@select_clauses.uniq!
    $log.debug "Query: the current select clauses are: #{@select_clauses.join(', ')}"
    self
  end

  def ask
    @ask = true
    $log.debug "Query: the current select clauses are: #{@select_clauses.join(', ')}"
    self
  end

  def distinct *s
    @distinct = true
    select(*s)
  end
  alias_method :select_distinct, :distinct

	def count *s
		@count = true
		select(*s)
	end

	def limit(i)
		@limits = i 
		self
	end

	def offset(i)
		@offsets = i
		self
	end

  def where s,p,o
		case p
		when :keyword
			# treat keywords in where-clauses specially
			keyword_where(s,o)
		else
			# remove duplicate variable bindings, e.g.
			# where(:s,type,:o).where(:s,type,:oo) we should remove the second clause, 
			# since it doesn't add anything to the query and confuses the query 
			# generator. 
			# if you construct this query manually, you shouldn't! if your select 
			# variable happens to be in one of the removed clauses: tough luck.

  		unless s.respond_to?(:uri) && p.respond_to?(:uri)
        raise(ActiveRdfError, "cannot add a where clause, in which s/p are not resources")
  		end

			@where_clauses << [s,p,o].collect{|arg| parametrise(arg)}
		end
    self
  end<commit_msg>fixed the checking to first check for responds to uri and then to check .class == Symbol, because otherwise there was a possibility of a loop<commit_after># Represents a query on a datasource, abstract representation of SPARQL features
# is passed to federation/adapter for execution on data
#
# Author:: <NAME>
# Copyright:: (c) 2005-2006
# License:: LGPL
require 'active_rdf'
require 'federation/federation_manager'

# TODO add log for every method which constitues to the query

class Query
  attr_reader :select_clauses, :where_clauses, :keywords, :limits, :offsets
  bool_accessor :distinct, :ask, :select, :count, :keyword

  def initialize
    $log.debug "Query: initializing"
    distinct = false
		limit = nil
		offset = nil
    @select_clauses = []
    @where_clauses = []
		@keywords = []
  end

	def clear_select
    $log.debug "Query: clearing select query"
		@select_clauses = []
		distinct = false
	end

  def select *s
    @select = true
    s.each do |e|
      @select_clauses << parametrise(e) 
    end
		# removing duplicate select clauses
		@select_clauses.uniq!
    $log.debug "Query: the current select clauses are: #{@select_clauses.join(', ')}"
    self
  end

  def ask
    @ask = true
    $log.debug "Query: the current select clauses are: #{@select_clauses.join(', ')}"
    self
  end

  def distinct *s
    @distinct = true
    select(*s)
  end
  alias_method :select_distinct, :distinct

	def count *s
		@count = true
		select(*s)
	end

	def limit(i)
		@limits = i 
		self
	end

	def offset(i)
		@offsets = i
		self
	end

  def where s,p,o
		case p
		when :keyword
			# treat keywords in where-clauses specially
			keyword_where(s,o)
		else
			# remove duplicate variable bindings, e.g.
			# where(:s,type,:o).where(:s,type,:oo) we should remove the second clause, 
			# since it doesn't add anything to the query and confuses the query 
			# generator. 
			# if you construct this query manually, you shouldn't! if your select 
			# variable happens to be in one of the removed clauses: tough luck.
			
      unless s.respond_to?(:uri)
    		unless s.class == Symbol
          raise(ActiveRdfError, "cannot add a where clause, in which s is not a resource and not a variable")
    		end
      end
      unless s.respond_to?(:uri)
    		unless p.class == Symbol
          raise(ActiveRdfError, "cannot add a where clause, in which s is not a resource and not a variable")
    		end
      end
      
			@where_clauses << [s,p,o].collect{|arg| parametrise(arg)}
		end
    self
  end
{'fraction_non_alphanumeric': 0.0970727507533362, 'fraction_numerical': 0.0034438226431338786, 'mean_word_length': 3.201627486437613, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, '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': '4105366', 'n_tokens_mistral': 1647, 'n_tokens_neox': 1500, 'n_words': 528}