Class: Array

Inherits:
Object show all
Defined in:
lib/sparql/algebra/extensions.rb

Overview

Extensions for Ruby’s Array class.

Instance Method Summary collapse

Instance Method Details

#aggregate?Boolean

Returns:

  • (Boolean)


144
# File 'lib/sparql/algebra/extensions.rb', line 144

def aggregate?; false; end

#bind(solution) ⇒ self

Binds the pattern to a solution, making it no longer variable if all variables are resolved to bound variables

Parameters:

Returns:

  • (self)


109
110
111
112
113
114
# File 'lib/sparql/algebra/extensions.rb', line 109

def bind(solution)
  map! do |op|
    op.respond_to?(:bind) ? op.bind(solution) : op
  end
  self
end

#constant?Boolean

Returns:

  • (Boolean)


125
# File 'lib/sparql/algebra/extensions.rb', line 125

def constant?; !(variable?); end

#deep_dupObject

Deep duplicate



222
223
224
# File 'lib/sparql/algebra/extensions.rb', line 222

def deep_dup
  map(&:deep_dup)
end

#evaluatable?Boolean

Returns:

  • (Boolean)


142
# File 'lib/sparql/algebra/extensions.rb', line 142

def evaluatable?; true; end

#executable?Boolean

Returns:

  • (Boolean)


143
# File 'lib/sparql/algebra/extensions.rb', line 143

def executable?; false; end

#execute(queryable, **options) ⇒ Object

If #execute is invoked, it implies that a non-implemented Algebra operator is being invoked

Parameters:

Raises:

  • (NotImplementedError)

    If an attempt is made to perform an unsupported operation

See Also:



89
90
91
# File 'lib/sparql/algebra/extensions.rb', line 89

def execute(queryable, **options)
  raise NotImplementedError, "SPARQL::Algebra '#{first}' operator not implemented"
end

#ndvarsArray<RDF::Query::Variable>

Return the non-destinguished variables contained within this Array



192
193
194
# File 'lib/sparql/algebra/extensions.rb', line 192

def ndvars
  vars.reject(&:distinguished?)
end

#node?Boolean

Does this contain any nodes?

Returns:

  • (Boolean)


139
140
141
# File 'lib/sparql/algebra/extensions.rb', line 139

def node?
  any?(&:node?)
end

#optimize(**options) ⇒ Array

Return an optimized version of this array.

Returns:

  • (Array)

    a copy of self

See Also:



98
99
100
101
102
# File 'lib/sparql/algebra/extensions.rb', line 98

def optimize(**options)
  self.map do |op|
    op.optimize(**options) if op.respond_to?(:optimize)
  end
end

#replace_aggregate! {|agg| ... } ⇒ SPARQL::Algebra::Evaluatable, RDF::Query::Variable

Recursively re-map operators to replace aggregates with temporary variables returned from the block

Yields:

  • agg

Yield Parameters:

Yield Returns:

Returns:



175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/sparql/algebra/extensions.rb', line 175

def replace_aggregate!(&block)
  map! do |op|
    case
    when op.respond_to?(:aggregate?) && op.aggregate?
      yield op
    when op.respond_to?(:replace_aggregate!)
      op.replace_aggregate!(&block) 
    else
      op
    end
  end
  self
end

#replace_vars! {|var| ... } ⇒ SPARQL::Algebra::Evaluatable

Replace operators which are variables with the result of the block descending into operators which are also evaluatable

Yields:

  • var

Yield Parameters:

Yield Returns:

Returns:



154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/sparql/algebra/extensions.rb', line 154

def replace_vars!(&block)
  map! do |op|
    case
    when op.respond_to?(:variable?) && op.variable?
      yield op
    when op.respond_to?(:replace_vars!)
      op.replace_vars!(&block) 
    else
      op
    end
  end
  self
end

#to_sparql(delimiter: " ", **options) ⇒ String

Returns a partial SPARQL grammar for this array.

Parameters:

  • delimiter (String) (defaults to: " ")

    (“ ”) If the first element is an IRI, treat it as an extension function

Returns:

  • (String)


75
76
77
# File 'lib/sparql/algebra/extensions.rb', line 75

def to_sparql(delimiter: " ",  **options)
  map {|e| e.to_sparql(**options)}.join(delimiter)
end

#to_sxp_binString

Returns the SXP representation of this object, defaults to self.

Returns:

  • (String)


64
65
66
# File 'lib/sparql/algebra/extensions.rb', line 64

def to_sxp_bin
  map {|x| x.to_sxp_bin}
end

#valid?Boolean

Is this value composed only of valid components?

Returns:

  • (Boolean)

    true or false



207
208
209
# File 'lib/sparql/algebra/extensions.rb', line 207

def valid?
  all? {|e| e.respond_to?(:valid?) ? e.valid? : true}
end

#validate!Array

Validate all components.

Returns:

Raises:

  • (ArgumentError)

    if the value is invalid



215
216
217
218
# File 'lib/sparql/algebra/extensions.rb', line 215

def validate!
  each {|e| e.validate! if e.respond_to?(:validate!)}
  self
end

#variable?Boolean

Returns true if any of the operands are variables, false otherwise.

Returns:

  • (Boolean)

    true or false

See Also:



122
123
124
# File 'lib/sparql/algebra/extensions.rb', line 122

def variable?
  any? {|op| op.respond_to?(:variable?) && op.variable?}
end

#variablesHash{Symbol => RDF::Query::Variable}

The variables used in this array.

Returns:



131
132
133
# File 'lib/sparql/algebra/extensions.rb', line 131

def variables
  self.inject({}) {|hash, o| o.respond_to?(:variables) ? hash.merge(o.variables) : hash}
end

#varsArray<RDF::Query::Variable>

Return the variables contained within this Array



199
200
201
# File 'lib/sparql/algebra/extensions.rb', line 199

def vars
  select {|o| o.respond_to?(:vars)}.map(&:vars).flatten.compact
end