Class: Array

Inherits:
Object show all
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/extensions.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-spec-9aa20fb58f9a/lib/rdf/spec/inspects.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-3a340a80c182/lib/rdf/n3/patches/array_hacks.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/json-ld-10f0d539c024/lib/json/ld/extensions.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sxp.rb-77c5073a7739/lib/sxp/writer.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-xsd-0489489cebb4/lib/rdf/xsd/extensions.rb

Overview

REXML C14N

Direct Known Subclasses

RDF::Query::Solutions

Instance Method Summary collapse

Instance Method Details

#aggregate?Boolean

Returns:

  • (Boolean)


94
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/extensions.rb', line 94

def aggregate?; false; 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/2.5.0/bundler/gems/rdf-xsd-0489489cebb4/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)


83
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/extensions.rb', line 83

def constant?; !(variable?); end

#evaluatable?Boolean

Returns:

  • (Boolean)


92
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/extensions.rb', line 92

def evaluatable?; true; end

#evaluate(bindings, options = {}) ⇒ RDF::Term

Evaluates the array using the given variable bindings.

In this case, the Array has two elements, the first of which is an XSD datatype, and the second is the expression to be evaluated. The result is cast as a literal of the appropriate type

Parameters:

  • bindings (RDF::Query::Solution)

    a query solution containing zero or more variable bindings

  • options (Hash{Symbol => Object}) (defaults to: {})

    ({}) options passed from query

Returns:

See Also:

  • Array.{SPARQL{SPARQL::Algebra{SPARQL::Algebra::Expression{SPARQL::Algebra::Expression.evaluate}


56
57
58
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/extensions.rb', line 56

def evaluate(bindings, options = {})
  SPARQL::Algebra::Expression.extension(*self.map {|o| o.evaluate(bindings, options)})
end

#executable?Boolean

Returns:

  • (Boolean)


93
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/extensions.rb', line 93

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:



70
71
72
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/extensions.rb', line 70

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

#inspect_with_formattingObject Also known as: inspect



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-spec-9aa20fb58f9a/lib/rdf/spec/inspects.rb', line 36

def inspect_with_formatting
  if all? { |item| item.is_a?(Hash) }
    string = "[\n"
    each do |item|
      string += "  {\n"
        item.keys.sort_by(&:to_s).each do |key|
          string += "      #{key.inspect}: #{item[key].inspect}\n"
        end
      string += "  },\n"
    end
    string += "]"
    string
  elsif all? { |item| item.is_a?(RDF::Query::Solution)}
    string = "[\n"
    each do |item|
      string += "  {\n"
        item.bindings.keys.sort_by(&:to_s).each do |key|
          string += "      #{key.inspect}: #{item.bindings[key].inspect}\n"
        end
      string += "  },\n"
    end
    string += "]"
    string
  else
    inspect_without_formatting
  end
end

#ndvarsArray<RDF::Query::Variable>

Return the non-destinguished variables contained within this Array



142
143
144
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/extensions.rb', line 142

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

#node?Boolean

Does this contain any nodes?

Returns:

  • (Boolean)


89
90
91
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/extensions.rb', line 89

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

#permute(prefixed = []) ⇒ Object

http://wiki.rubygarden.org/Ruby/page/show/ArrayPermute Permute an array, and call a block for each permutation Author: Paul Battley



5
6
7
8
9
10
11
12
13
14
15
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-3a340a80c182/lib/rdf/n3/patches/array_hacks.rb', line 5

def permute(prefixed=[])
  if (length < 2)
    # there are no elements left to permute
    yield(prefixed + self)
  else
    # recursively permute the remaining elements
    each_with_index do |e, i|
      (self[0,i]+self[(i+1)..-1]).permute(prefixed+[e]) { |a| yield a }
    end
  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:



125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/extensions.rb', line 125

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:



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/extensions.rb', line 104

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

#term_sortObject

Order terms, length first, then lexographically



14
15
16
17
18
19
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/json-ld-10f0d539c024/lib/json/ld/extensions.rb', line 14

def term_sort
  self.sort do |a, b|
    len_diff = a.length <=> b.length
    len_diff == 0 ? a <=> b : len_diff
  end
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/2.5.0/bundler/gems/rdf-xsd-0489489cebb4/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_sentence(options = {}) ⇒ Object

Converts the array to a comma-separated sentence where the last element is joined by the connector word. Options:

  • :words_connector - The sign or word used to join the elements in arrays with two or more elements (default: ", ")
  • :two_words_connector - The sign or word used to join the elements in arrays with two elements (default: " and ")
  • :last_word_connector - The sign or word used to join the last element in arrays with three or more elements (default: ", and ")


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-n3-3a340a80c182/lib/rdf/n3/patches/array_hacks.rb', line 21

def to_sentence(options = {})
  default_words_connector     = ", "
  default_two_words_connector = " and "
  default_last_word_connector = ", and "

  # Try to emulate to_senteces previous to 2.3
  if options.has_key?(:connector) || options.has_key?(:skip_last_comma)
    ::ActiveSupport::Deprecation.warn(":connector has been deprecated. Use :words_connector instead", caller) if options.has_key? :connector
    ::ActiveSupport::Deprecation.warn(":skip_last_comma has been deprecated. Use :last_word_connector instead", caller) if options.has_key? :skip_last_comma

    skip_last_comma = options.delete :skip_last_comma
    if connector = options.delete(:connector)
      options[:last_word_connector] ||= skip_last_comma ? connector : ", #{connector}"
    else
      options[:last_word_connector] ||= skip_last_comma ? default_two_words_connector : default_last_word_connector
    end
  end

#    options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector, :locale)
  options = {words_connector: default_words_connector, two_words_connector: default_two_words_connector, last_word_connector: default_last_word_connector}.merge(options)

  case length
    when 0
      ""
    when 1
      self[0].to_s
    when 2
      "#{self[0]}#{options[:two_words_connector]}#{self[1]}"
    else
      "#{self[0...-1].join(options[:words_connector])}#{options[:last_word_connector]}#{self[-1]}"
  end
end

#to_sxpString

Returns the SXP representation of this object.

Returns:



124
125
126
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sxp.rb-77c5073a7739/lib/sxp/writer.rb', line 124

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

#to_sxp_binString

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

Returns:



39
40
41
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/extensions.rb', line 39

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



157
158
159
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/extensions.rb', line 157

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



165
166
167
168
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/extensions.rb', line 165

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:



80
81
82
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/extensions.rb', line 80

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

#varsArray<RDF::Query::Variable>

Return the variables contained within this Array



149
150
151
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-bb59900f675b/lib/sparql/algebra/extensions.rb', line 149

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