lib/sparql/algebra/operator/and.rb in sparql-3.1.8 vs lib/sparql/algebra/operator/and.rb in sparql-3.2.0

- old
+ new

@@ -1,14 +1,27 @@ module SPARQL; module Algebra class Operator ## # The SPARQL logical `and` operator. # - # @example - # (&& ?x ?y) - # (and ?x ?y) + # [112] ConditionalAndExpression::= ValueLogical ( '&&' ValueLogical )* # + # @example SPARQL Grammar + # PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> + # PREFIX : <http://example.org/ns#> + # SELECT ?a + # WHERE { ?a :p ?v . + # FILTER ("true"^^xsd:boolean && ?v) . + # } + # + # @example SSE + # (prefix + # ((xsd: <http://www.w3.org/2001/XMLSchema#>) (: <http://example.org/ns#>)) + # (project (?a) + # (filter (&& true ?v) + # (bgp (triple ?a :p ?v))))) + # # @see https://www.w3.org/TR/sparql11-query/#func-logical-and # @see https://www.w3.org/TR/sparql11-query/#evaluation class And < Operator::Binary include Evaluatable @@ -57,9 +70,18 @@ when left.nil? && right.nil? then raise(TypeError) when left.nil? then right ? raise(TypeError) : RDF::Literal::FALSE when right.nil? then left ? raise(TypeError) : RDF::Literal::FALSE else RDF::Literal(left && right) end + end + + ## + # + # Returns a partial SPARQL grammar for this operator. + # + # @return [String] + def to_sparql(**options) + "(#{operands.first.to_sparql(**options)} && #{operands.last.to_sparql(**options)})" end end # And end # Operator end; end # SPARQL::Algebra