Sha256: d1db2e2b163dd754b650dabef652b03fa53a83345a8f63c7130931f616c2bbba

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

module SPARQL; module Algebra
  class Operator
    ##
    # The SPARQL `strlang` operator.
    #
    # @example
    #     (prefix ((: <http://example.org/>))
    #       (project (?s ?s2)
    #         (extend ((?s2 (strlang ?str "en-US")))
    #           (filter (langMatches (lang ?str) "en")
    #             (bgp (triple ?s :str ?str))))))
    #
    # @see http://www.w3.org/TR/sparql11-query/#func-strlang
    class StrLang < Operator::Binary
      include Evaluatable

      NAME = :strlang

      ##
      # Constructs a literal with lexical form and type as specified by the arguments.
      #
      # @param  [RDF::Literal] value
      #   a literal
      # @param  [RDF::Literal] datatypeIRI
      #   datatype
      # @return [RDF::Literal] a datatyped literal
      # @see http://www.w3.org/TR/sparql11-query/#func-strlang
      def apply(value, langTag)
        raise TypeError, "Literal #{value.inspect} is not simple" unless value.simple?
        RDF::Literal.new(value.to_s, :language => langTag.to_s)
      end
    end # StrLang
  end # Operator
end; end # SPARQL::Algebra

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sparql-1.0.8 lib/sparql/algebra/operator/strlang.rb
sparql-1.0.7 lib/sparql/algebra/operator/strlang.rb