Class: SPARQL::Algebra::Operator::Describe

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

Overview

The SPARQL GraphPattern describe operator.

Generages a graph across specified terms using RDF::Queryable#concise_bounded_description.

[11] DescribeQuery ::= ‘DESCRIBE’ ( VarOrIri+ | ‘’ ) DatasetClause WhereClause? SolutionModifier ValuesClause

Examples:

SPARQL Grammar

BASE <http://example.org/>
DESCRIBE <u> ?u WHERE { <x> <q> ?u . }

SSE

(base <http://example.org/>
 (describe (<u> ?u)
  (bgp (triple <x> <q> ?u))))

See Also:

Constant Summary collapse

NAME =
[:describe]

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_boolean?, #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, #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, #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) {|statement| ... } ⇒ RDF::Graph

Executes this query on the given RDF::Queryable object. Generates a graph containing the Concise Bounded Description variables and URIs listed in the first operand.

Examples:

(describe (<http://example/>))
(prefix ((foaf: <http://xmlns.com/foaf/0.1/>))
  (describe (?x)
    (bgp (triple ?x foaf:mbox <mailto:alice@org>))))

Parameters:

  • queryable (RDF::Queryable)

    the graph or repository to query

  • options (Hash{Symbol => Object})

    any additional keyword options

Yields:

  • (statement)

    each matching statement

Yield Parameters:

Yield Returns:

  • (void)

    ignored

Returns:

  • (RDF::Graph)

    containing the constructed triples

See Also:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/sparql/algebra/operator/describe.rb', line 49

def execute(queryable, **options, &block)
  debug(options) {"Describe #{operands.first}, #{options.inspect}"}

  # Describe any constand URIs
  to_describe = operands.first.select {|t| t.uri?}
  
  to_describe.each {|t| debug(options) {"=> describe #{t}"}}

  queryable.query(operands.last) do |solution|
    solution.each_variable do |v|
      if operands.first.any? {|bound| v.eql?(bound)}
        debug(options) {"(describe)=> #{v}"}
        to_describe << v.value
      end
    end
  end

  # Return Concise Bounded Description
  queryable.concise_bounded_description(*to_describe.uniq, &block)
end

#query_yields_statements?Boolean

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

Returns:

  • (Boolean)


72
73
74
# File 'lib/sparql/algebra/operator/describe.rb', line 72

def query_yields_statements?
  true
end

#to_sparql(**options) ⇒ String

Returns a partial SPARQL grammar for this term.

Returns:

  • (String)


81
82
83
84
85
86
87
88
89
90
91
# File 'lib/sparql/algebra/operator/describe.rb', line 81

def to_sparql(**options)
  str = "DESCRIBE "
  str << if operands[0].empty?
    "*"
  else
    operands[0].map { |e| e.to_sparql(**options) }.join(" ")
  end

  str << "\n"
  str << operands[1].to_sparql(top_level: true, project: nil, **options)
end