Class: SPARQL::Algebra::Operator Abstract
- Inherits:
-
Object
- Object
- SPARQL::Algebra::Operator
- Defined in:
- lib/sparql/algebra/operator.rb,
lib/sparql/algebra/operator/str.rb,
lib/sparql/algebra/operator/not.rb,
lib/sparql/algebra/operator/plus.rb,
lib/sparql/algebra/operator/lang.rb,
lib/sparql/algebra/operator/minus.rb,
lib/sparql/algebra/operator/bound.rb,
lib/sparql/algebra/operator/is_iri.rb,
lib/sparql/algebra/operator/is_blank.rb,
lib/sparql/algebra/operator/datatype.rb,
lib/sparql/algebra/operator/is_literal.rb
Overview
A SPARQL operator.
Direct Known Subclasses
Operator::Binary, Operator::Nullary, Operator::Ternary, Operator::Unary
Defined Under Namespace
Classes: Binary, Bound, Datatype, IsBlank, IsIRI, IsLiteral, Lang, Minus, Not, Nullary, Plus, Str, Ternary, Unary
Instance Attribute Summary (collapse)
-
- (Array) operands
readonly
The operands to this operator.
-
- (Hash) options
readonly
Any additional options for this operator.
Class Method Summary (collapse)
Instance Method Summary (collapse)
-
- (RDF::Literal::Boolean) boolean(literal)
protected
Returns the effective boolean value (EBV) of the given
literal. -
- (Boolean) constant?
Returns
trueif none of the operands are variables,falseotherwise. - - (RDF::Term) evaluate(solution) Abstract
-
- (Operator) initialize(options = {})
constructor
A new instance of Operator.
-
- (RDF::Term) operand(index, bindings = {})
Returns the operand at the given
index. -
- (Array) to_sse
Returns the SPARQL S-Expression (SSE) representation of this operator.
-
- (Boolean) variable?
Returns
trueif any of the operands are variables,falseotherwise.
Constructor Details
- (Operator) initialize(options = {})
A new instance of Operator
30 31 32 33 |
# File 'lib/sparql/algebra/operator.rb', line 30 def initialize( = {}) raise ArgumentError, "expected Hash, but got #{.inspect}" unless .is_a?(Hash) @options = .dup end |
Instance Attribute Details
- (Array) operands (readonly)
The operands to this operator.
45 46 47 |
# File 'lib/sparql/algebra/operator.rb', line 45 def operands @operands end |
- (Hash) options (readonly)
Any additional options for this operator.
39 40 41 |
# File 'lib/sparql/algebra/operator.rb', line 39 def @options end |
Class Method Details
+ (RDF::Term) evaluate(*args)
23 24 25 |
# File 'lib/sparql/algebra/operator.rb', line 23 def self.evaluate(*args) self.new(*args).evaluate(RDF::Query::Solution.new) end |
Instance Method Details
- (RDF::Literal::Boolean) boolean(literal) (protected)
Returns the effective boolean value (EBV) of the given literal.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/sparql/algebra/operator.rb', line 111 def boolean(literal) case literal when FalseClass then RDF::Literal::FALSE when TrueClass then RDF::Literal::TRUE # If the argument is a typed literal with a datatype of # `xsd:boolean`, the EBV is the value of that argument. # However, the EBV of any literal whose type is `xsd:boolean` is # false if the lexical form is not valid for that datatype. when RDF::Literal::Boolean RDF::Literal(literal.valid? && literal.true?) # If the argument is a numeric type or a typed literal with a # datatype derived from a numeric type, the EBV is false if the # operand value is NaN or is numerically equal to zero; otherwise # the EBV is true. # However, the EBV of any literal whose type is numeric is # false if the lexical form is not valid for that datatype. when RDF::Literal::Numeric RDF::Literal(literal.valid? && !(literal.zero?) && !(literal.respond_to?(:nan?) && literal.nan?)) # If the argument is a plain literal or a typed literal with a # datatype of `xsd:string`, the EBV is false if the operand value # has zero length; otherwise the EBV is true. else case when literal.plain? || literal.datatype.eql?(RDF::XSD.string) RDF::Literal(!(literal.value.empty?)) # All other arguments, including unbound arguments, produce a type error. else raise TypeError, "could not coerce #{literal.inspect} to an RDF::Literal::Boolean" end end end |
- (Boolean) constant?
Returns true if none of the operands are variables, false
otherwise.
79 80 81 |
# File 'lib/sparql/algebra/operator.rb', line 79 def constant? !(variable?) end |
- (RDF::Term) evaluate(solution)
88 89 90 |
# File 'lib/sparql/algebra/operator.rb', line 88 def evaluate(solution) raise NotImplementedError, "#{self.class}#evaluate" end |
- (RDF::Term) operand(index, bindings = {})
Returns the operand at the given index.
If the optional bindings argument is provided, it is used for
performing variable lookup in case the operand is a variable.
58 59 60 61 |
# File 'lib/sparql/algebra/operator.rb', line 58 def operand(index, bindings = {}) operand = operands[index] operand.is_a?(RDF::Query::Variable) ? bindings[operand.to_sym] : operand end |
- (Array) to_sse
Returns the SPARQL S-Expression (SSE) representation of this operator.
97 98 99 100 |
# File 'lib/sparql/algebra/operator.rb', line 97 def to_sse operator = [self.class.const_get(:NAME)].flatten.first [operator, *(operands || [])] end |
- (Boolean) variable?
Returns true if any of the operands are variables, false
otherwise.
69 70 71 |
# File 'lib/sparql/algebra/operator.rb', line 69 def variable? operands.any? { |operand| operand.is_a?(RDF::Query::Variable) } end |