Class: SPARQL::Algebra::Operator::StrUUID

Inherits:
Operator::Nullary
  • Object
show all
Includes:
Evaluatable
Defined in:
lib/sparql/algebra/operator/struuid.rb

Overview

[121] BuiltInCall ::= ... | 'STRUUID' NIL

Examples:

SPARQL Grammar

PREFIX : <http://example.org/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT (STRLEN(?uuid) AS ?length)
WHERE {
  BIND(STRUUID() AS ?uuid)
  FILTER(ISLITERAL(?uuid) && REGEX(?uuid, "^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$", "i"))
}

SSE

(prefix ((: <http://example.org/>) (xsd: <http://www.w3.org/2001/XMLSchema#>))
 (project (?length)
  (extend ((?length (strlen ?uuid)))
   (filter
    (&&
     (isLiteral ?uuid)
     (regex ?uuid "^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$" "i"))
    (extend ((?uuid (struuid)))
     (bgp))))))

See Also:

Constant Summary collapse

NAME =
:struuid

Instance Method Summary collapse

Methods included from Evaluatable

#evaluate, #memoize, #replace_aggregate!, #replace_vars!

Instance Method Details

#apply(**options) ⇒ RDF::URI

Return a string that is the scheme specific part of UUID. That is, as a simple literal, the result of generating a UUID, converting to a simple literal and removing the initial urn:uuid:.

Returns:

  • (RDF::URI)


38
39
40
# File 'lib/sparql/algebra/operator/struuid.rb', line 38

def apply(**options)
  RDF::Literal(SecureRandom.uuid)
end

#to_sparql(**options) ⇒ String

Returns a partial SPARQL grammar for this operator.

Returns:

  • (String)


47
48
49
# File 'lib/sparql/algebra/operator/struuid.rb', line 47

def to_sparql(**options)
  "STRUUID(" + operands.to_sparql(delimiter: ', ', **options) + ")"
end