Sha256: 0425413df1451d3fea23635a49e2f26fb590388257e87c846dfc52236539a24b

Contents?: true

Size: 1.05 KB

Versions: 11

Compression:

Stored size: 1.05 KB

Contents

module SPARQL; module Algebra
  class Operator
    ##
    # The SPARQL `isLiteral` operator.
    #
    # @example
    #   (prefix ((xsd: <http://www.w3.org/2001/XMLSchema#>)
    #            (: <http://example.org/things#>))
    #     (project (?x ?v)
    #       (filter (isLiteral ?v)
    #         (bgp (triple ?x :p ?v)))))
    #
    # @see http://www.w3.org/TR/sparql11-query/#func-isLiteral
    class IsLiteral < Operator::Unary
      include Evaluatable

      NAME = :isLiteral

      ##
      # Returns `true` if the operand is an `RDF::Literal`, `false`
      # otherwise.
      #
      # @param  [RDF::Term] term
      #   an RDF term
      # @return [RDF::Literal::Boolean] `true` or `false`
      # @raise  [TypeError] if the operand is not an RDF term
      def apply(term)
        case term
          when RDF::Literal then RDF::Literal::TRUE
          when RDF::Term    then RDF::Literal::FALSE
          else raise TypeError, "expected an RDF::Term, but got #{term.inspect}"
        end
      end
    end # IsLiteral
  end # Operator
end; end # SPARQL::Algebra

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
sparql-3.1.0 lib/sparql/algebra/operator/is_literal.rb
sparql-3.0.2 lib/sparql/algebra/operator/is_literal.rb
sparql-3.0.1 lib/sparql/algebra/operator/is_literal.rb
sparql-3.0.0 lib/sparql/algebra/operator/is_literal.rb
sparql-2.2.2 lib/sparql/algebra/operator/is_literal.rb
sparql-2.2.1 lib/sparql/algebra/operator/is_literal.rb
sparql-2.2.0 lib/sparql/algebra/operator/is_literal.rb
sparql-2.1.0 lib/sparql/algebra/operator/is_literal.rb
sparql-2.0.0 lib/sparql/algebra/operator/is_literal.rb
sparql-2.0.0.beta2 lib/sparql/algebra/operator/is_literal.rb
sparql-2.0.0.beta1 lib/sparql/algebra/operator/is_literal.rb