Class: Array
Overview
Extensions for Ruby’s Array
class.
Instance Method Summary collapse
- #aggregate? ⇒ Boolean
-
#bind(solution) ⇒ self
Binds the pattern to a solution, making it no longer variable if all variables are resolved to bound variables.
- #constant? ⇒ Boolean
-
#deep_dup ⇒ Object
Deep duplicate.
- #evaluatable? ⇒ Boolean
- #executable? ⇒ Boolean
-
#execute(queryable, **options) ⇒ Object
If
#execute
is invoked, it implies that a non-implemented Algebra operator is being invoked. -
#ndvars ⇒ Array<RDF::Query::Variable>
Return the non-destinguished variables contained within this Array.
-
#node? ⇒ Boolean
Does this contain any nodes?.
-
#optimize(**options) ⇒ Array
Return an optimized version of this array.
-
#replace_aggregate! {|agg| ... } ⇒ SPARQL::Algebra::Evaluatable, RDF::Query::Variable
Recursively re-map operators to replace aggregates with temporary variables returned from the block.
-
#replace_vars! {|var| ... } ⇒ SPARQL::Algebra::Evaluatable
Replace operators which are variables with the result of the block descending into operators which are also evaluatable.
-
#to_sparql(delimiter: " ", **options) ⇒ String
Returns a partial SPARQL grammar for this array.
-
#to_sxp_bin ⇒ String
Returns the SXP representation of this object, defaults to
self
. -
#valid? ⇒ Boolean
Is this value composed only of valid components?.
-
#validate! ⇒ Array
Validate all components.
-
#variable? ⇒ Boolean
Returns
true
if any of the operands are variables,false
otherwise. -
#variables ⇒ Hash{Symbol => RDF::Query::Variable}
The variables used in this array.
-
#vars ⇒ Array<RDF::Query::Variable>
Return the variables contained within this Array.
Instance Method Details
#aggregate? ⇒ 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
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
125 |
# File 'lib/sparql/algebra/extensions.rb', line 125 def constant?; !(variable?); end |
#deep_dup ⇒ Object
Deep duplicate
222 223 224 |
# File 'lib/sparql/algebra/extensions.rb', line 222 def deep_dup map(&:deep_dup) end |
#evaluatable? ⇒ Boolean
142 |
# File 'lib/sparql/algebra/extensions.rb', line 142 def evaluatable?; true; end |
#executable? ⇒ 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
89 90 91 |
# File 'lib/sparql/algebra/extensions.rb', line 89 def execute(queryable, **) raise NotImplementedError, "SPARQL::Algebra '#{first}' operator not implemented" end |
#ndvars ⇒ Array<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?
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.
98 99 100 101 102 |
# File 'lib/sparql/algebra/extensions.rb', line 98 def optimize(**) self.map do |op| op.optimize(**) 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
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
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.
75 76 77 |
# File 'lib/sparql/algebra/extensions.rb', line 75 def to_sparql(delimiter: " ", **) map {|e| e.to_sparql(**)}.join(delimiter) end |
#to_sxp_bin ⇒ String
Returns the SXP representation of this object, defaults to self
.
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?
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.
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.
122 123 124 |
# File 'lib/sparql/algebra/extensions.rb', line 122 def variable? any? {|op| op.respond_to?(:variable?) && op.variable?} end |
#variables ⇒ Hash{Symbol => RDF::Query::Variable}
The variables used in this array.
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 |
#vars ⇒ Array<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 |