Sha256: 4a7d5b056e9848dec9b58a137a03b67cc4d3e417f5d0b0daab93cfab3d5b4a6c

Contents?: true

Size: 1.4 KB

Versions: 28

Compression:

Stored size: 1.4 KB

Contents

module SPARQL; module Algebra
  class Operator
    ##
    # The SPARQL `isNumeric` operator.
    #
    # Note numeric denotes typed literals with datatypes xsd:integer, xsd:decimal, xsd:float, and xsd:double, not derived types.
    #
    # @example
    #   (prefix ((xsd: <http://www.w3.org/2001/XMLSchema#>)
    #            (: <http://example.org/things#>))
    #     (project (?x ?v)
    #       (filter (isNumeric ?v)
    #         (bgp (triple ?x :p ?v)))))
    #
    # @see http://www.w3.org/TR/sparql11-query/#func-isNumeric
    class IsNumeric < Operator::Unary
      include Evaluatable

      NAME = :isnumeric

      ##
      # Returns `true` if the operand is an `RDF::Literal::Numeric`, `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::NonPositiveInteger then RDF::Literal::FALSE
          when RDF::Literal::NonNegativeInteger then RDF::Literal::FALSE
          when RDF::Literal::Long then RDF::Literal::FALSE
          when RDF::Literal::Numeric 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 # IsNumeric
  end # Operator
end; end # SPARQL::Algebra

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
sparql-3.1.0 lib/sparql/algebra/operator/is_numeric.rb
sparql-3.0.2 lib/sparql/algebra/operator/is_numeric.rb
sparql-3.0.1 lib/sparql/algebra/operator/is_numeric.rb
sparql-3.0.0 lib/sparql/algebra/operator/is_numeric.rb
sparql-2.2.2 lib/sparql/algebra/operator/is_numeric.rb
sparql-2.2.1 lib/sparql/algebra/operator/is_numeric.rb
sparql-2.2.0 lib/sparql/algebra/operator/is_numeric.rb
sparql-2.1.0 lib/sparql/algebra/operator/is_numeric.rb
sparql-2.0.0 lib/sparql/algebra/operator/is_numeric.rb
sparql-2.0.0.beta2 lib/sparql/algebra/operator/is_numeric.rb
sparql-1.99.1 lib/sparql/algebra/operator/is_numeric.rb
sparql-2.0.0.beta1 lib/sparql/algebra/operator/is_numeric.rb
sparql-1.1.9.1 lib/sparql/algebra/operator/is_numeric.rb
sparql-1.99.0 lib/sparql/algebra/operator/is_numeric.rb
sparql-1.1.9 lib/sparql/algebra/operator/is_numeric.rb
sparql-1.1.8 lib/sparql/algebra/operator/is_numeric.rb
sparql-1.1.7 lib/sparql/algebra/operator/is_numeric.rb
sparql-1.1.6 lib/sparql/algebra/operator/is_numeric.rb
sparql-1.1.5 lib/sparql/algebra/operator/is_numeric.rb
sparql-1.1.4 lib/sparql/algebra/operator/is_numeric.rb