Class: SPARQL::Algebra::Operator::Prefix

Inherits:
Binary show all
Includes:
Query
Defined in:
lib/sparql/algebra/operator/prefix.rb

Overview

The SPARQL GraphPattern prefix operator.

[6] PrefixDecl ::= ‘PREFIX’ PNAME_NS IRIREF

Examples:

SPARQL Grammar

PREFIX : <http://example/>
SELECT * { :s :p :o }

SSE

(prefix ((: <http://example/>))
 (bgp (triple :s :p :o)))

See Also:

Constant Summary collapse

NAME =
[:prefix]

Constants inherited from Binary

Binary::ARITY

Constants inherited from SPARQL::Algebra::Operator

ARITY, IsURI, URI

Constants included from Expression

Expression::PATTERN_PARENTS

Instance Attribute Summary

Attributes included from Query

#solutions

Attributes inherited from SPARQL::Algebra::Operator

#operands

Instance Method Summary collapse

Methods included from Query

#each_solution, #empty?, #failed?, #graph_name=, #matched?, #query_yields_solutions?, #unshift, #variables

Methods inherited from Binary

#initialize

Methods inherited from SPARQL::Algebra::Operator

#aggregate?, arity, #base_uri, base_uri, base_uri=, #bind, #boolean, #constant?, #deep_dup, #each_descendant, #eql?, #evaluatable?, evaluate, #executable?, #first_ancestor, for, #initialize, #inspect, #ndvars, #node?, #operand, #optimize!, #parent, #parent=, #prefixes, prefixes, prefixes=, #rewrite, #to_binary, to_sparql, #to_sxp, #to_sxp_bin, #validate!, #variable?, #variables, #vars

Methods included from Expression

cast, #constant?, #evaluate, extension, extension?, extensions, for, #invalid?, new, #node?, open, #optimize!, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?

Constructor Details

This class inherits a constructor from SPARQL::Algebra::Operator::Binary

Instance Method Details

#execute(queryable, **options) {|solution| ... } ⇒ RDF::Query::Solutions

Executes this query on the given queryable graph or repository. Really a pass-through, as this is a syntactic object used for providing graph_name for URIs.

Parameters:

  • queryable (RDF::Queryable)

    the graph or repository to query

  • options (Hash{Symbol => Object})

    any additional keyword options

Yields:

  • (solution)

    each matching solution, statement or boolean

Yield Parameters:

Yield Returns:

  • (void)

    ignored

Returns:

See Also:



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

def execute(queryable, **options, &block)
  debug(options) {"Prefix"}
  @solutions = queryable.query(operands.last, **options.merge(depth: options[:depth].to_i + 1), &block)
end

#merge!(other) ⇒ Prefix

Combine two prefix definitions, merging their definitions

Parameters:

Returns:



57
58
59
60
# File 'lib/sparql/algebra/operator/prefix.rb', line 57

def merge!(other)
  operands[0] += other.operands[0]
  self
end

#optimize(**options) ⇒ Prefix

Returns an optimized version of this query.

Replace with the query with URIs having their lexical shortcut removed

Returns:

See Also:



50
51
52
# File 'lib/sparql/algebra/operator/prefix.rb', line 50

def optimize(**options)
  operands.last.optimize(**options)
end

#query_yields_boolean?Boolean

Query results in a boolean result (e.g., ASK)

Returns:

  • (Boolean)


64
65
66
# File 'lib/sparql/algebra/operator/prefix.rb', line 64

def query_yields_boolean?
  operands.last.query_yields_boolean?
end

#query_yields_statements?Boolean

Query results statements (e.g., CONSTRUCT, DESCRIBE, CREATE)

Returns:

  • (Boolean)


70
71
72
# File 'lib/sparql/algebra/operator/prefix.rb', line 70

def query_yields_statements?
  operands.last.query_yields_statements?
end

#to_sparql(**options) ⇒ String

Returns a partial SPARQL grammar for this term.

Returns:

  • (String)


79
80
81
82
83
84
85
86
87
88
# File 'lib/sparql/algebra/operator/prefix.rb', line 79

def to_sparql(**options)
  prefixes = {}
  str = operands.first.map do |(pfx, sfx)|
    pfx = pfx.to_s.chomp(':').to_sym
    prefixes[pfx] = sfx
    "PREFIX #{pfx}: #{sfx.to_sparql}\n"
  end.join("")

  str << operands.last.to_sparql(prefixes: prefixes, **options)
end