Class: Array

Inherits:
Object show all
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/extensions.rb,
vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/extensions.rb,
vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/extensions.rb,
vendor/bundler/ruby/3.3.0/bundler/gems/rdf-xsd-1663b6f0e598/lib/rdf/xsd/extensions.rb

Overview

REXML C14N

Direct Known Subclasses

RDF::Query::Solutions, SHACL::Shapes

Instance Method Summary collapse

Instance Method Details

#aggregate?Boolean

Returns:

  • (Boolean)


144
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/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 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/extensions.rb', line 109

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

#c14nxl(options = {}) ⇒ Object

Canonicalize the NodeSet. Return a new NodeSet marked as being canonical with all child nodes canonicalized.

Parameters:



136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-xsd-1663b6f0e598/lib/rdf/xsd/extensions.rb', line 136

def c14nxl(options = {})
  # Create a new NodeSet
  set = []
  set.instance_variable_set(:@c14nxl, true)

  # Unless passed a set of namespaces, figure them out from namespace_scopes
  #options[:namespaces] ||= first.parent.namespace_scopes.compact.inject({}) do |memo, ns|
  #  memo[ns.prefix] = ns.href.to_s
  #  memo
  #end

  self.each {|c| set << (c.respond_to?(:c14nxl) ? c.c14nxl(options) : c)}
  set
end

#constant?Boolean

Returns:

  • (Boolean)


125
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/extensions.rb', line 125

def constant?; !(variable?); end

#deep_dupObject

Deep duplicate



222
223
224
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/extensions.rb', line 222

def deep_dup
  map(&:deep_dup)
end

#evaluatable?Boolean

Returns:

  • (Boolean)


142
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/extensions.rb', line 142

def evaluatable?; true; end

#executable?Boolean

Returns:

  • (Boolean)


143
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/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 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/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 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/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 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/extensions.rb', line 139

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

#opt_sort(ordered: false) ⇒ Array

Optionally order items

Parameters:

  • ordered (Boolean) (defaults to: false)

Returns:



51
52
53
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/extensions.rb', line 51

def opt_sort(ordered: false)
  ordered ? sort : self
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 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/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 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/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 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/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_s_with_c14nxlObject Also known as: to_s

Serialize a canonicalized Node or NodeSet to XML

Override standard #to_s implementation to output in c14n representation if the Node or NodeSet is marked as having been canonicalized



156
157
158
159
160
161
162
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-xsd-1663b6f0e598/lib/rdf/xsd/extensions.rb', line 156

def to_s_with_c14nxl
  if instance_variable_defined?(:@c14nxl)
    map {|c| c.to_s}.join("")
  else
    to_s_without_c14nxl
  end
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:



75
76
77
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/extensions.rb', line 75

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

#to_sxpString

Returns the SXP representation of this object.

Returns:



165
166
167
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/extensions.rb', line 165

def to_sxp()
  '(' << map { |x| x.to_sxp(**options) }.join(' ') << ')'
end

#to_sxp_binString

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

Returns:



64
65
66
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/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 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/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 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/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 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/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.



131
132
133
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/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 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/extensions.rb', line 199

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