Class: RDF::Query
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Equivalence for Queries: Same Patterns Same Context.
-
#bind(solution) ⇒ self
Binds the pattern to a solution, making it no longer variable if all variables are resolved to bound variables.
-
#executable? ⇒ Boolean
Returns
true
as this is executable. -
#ndvars ⇒ Array<RDF::Query::Variable>
Return the non-destinguished variables contained within patterns and graph name.
-
#optimize!(**options) ⇒ self
Optimize the query, removing lexical shortcuts in URIs.
- #optimize_without_expression! ⇒ Object
-
#query_yields_boolean? ⇒ Boolean
Query results in a boolean result (e.g., ASK).
-
#query_yields_solutions? ⇒ Boolean
Query results solutions (e.g., SELECT).
-
#query_yields_statements? ⇒ Boolean
Query results statements (e.g., CONSTRUCT, DESCRIBE, CREATE).
-
#rewrite(&block) ⇒ SPARQL::Algebra::Expression
Don’t do any more rewriting.
-
#to_sparql(top_level: true, filter_ops: [], **options) ⇒ String
Returns a partial SPARQL grammar for this query.
-
#to_sxp_bin ⇒ Array
Transform Query into an Array form of an SSE.
-
#vars ⇒ Array<RDF::Query::Variable>
Return the variables contained within patterns and graph name.
Instance Method Details
#==(other) ⇒ Boolean
Equivalence for Queries: Same Patterns Same Context
404 405 406 407 |
# File 'lib/sparql/algebra/extensions.rb', line 404 def ==(other) # FIXME: this should be graph_name == other.graph_name other.is_a?(RDF::Query) && patterns == other.patterns && graph_name == graph_name end |
#bind(solution) ⇒ self
Binds the pattern to a solution, making it no longer variable if all variables are resolved to bound variables
471 472 473 474 |
# File 'lib/sparql/algebra/extensions.rb', line 471 def bind(solution) patterns.each {|p| p.bind(solution)} self end |
#executable? ⇒ Boolean
Returns true
as this is executable.
532 |
# File 'lib/sparql/algebra/extensions.rb', line 532 def executable?; true; end |
#ndvars ⇒ Array<RDF::Query::Variable>
Return the non-destinguished variables contained within patterns and graph name
497 498 499 |
# File 'lib/sparql/algebra/extensions.rb', line 497 def ndvars vars.reject(&:distinguished?) end |
#optimize!(**options) ⇒ self
Optimize the query, removing lexical shortcuts in URIs
514 515 516 517 518 519 520 521 522 523 524 525 526 |
# File 'lib/sparql/algebra/extensions.rb', line 514 def optimize!(**) @patterns = @patterns.map do |pattern| components = pattern.to_quad.map do |term| #if term.respond_to?(:lexical=) # term.dup.instance_eval {@lexical = nil; self} #else term #end end RDF::Query::Pattern.from(components, **pattern.) end self.optimize_without_expression!(**) end |
#optimize_without_expression! ⇒ Object
508 |
# File 'lib/sparql/algebra/extensions.rb', line 508 alias_method :optimize_without_expression!, :optimize! |
#query_yields_boolean? ⇒ Boolean
Query results in a boolean result (e.g., ASK)
478 479 480 |
# File 'lib/sparql/algebra/extensions.rb', line 478 def query_yields_boolean? false end |
#query_yields_solutions? ⇒ Boolean
Query results solutions (e.g., SELECT)
490 491 492 |
# File 'lib/sparql/algebra/extensions.rb', line 490 def query_yields_solutions? true end |
#query_yields_statements? ⇒ Boolean
Query results statements (e.g., CONSTRUCT, DESCRIBE, CREATE)
484 485 486 |
# File 'lib/sparql/algebra/extensions.rb', line 484 def query_yields_statements? false end |
#rewrite(&block) ⇒ SPARQL::Algebra::Expression
Don’t do any more rewriting
412 413 414 |
# File 'lib/sparql/algebra/extensions.rb', line 412 def rewrite(&block) self end |
#to_sparql(top_level: true, filter_ops: [], **options) ⇒ String
Returns a partial SPARQL grammar for this query.
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 |
# File 'lib/sparql/algebra/extensions.rb', line 441 def to_sparql(top_level: true, filter_ops: [], **) str = @patterns.map do |e| e.to_sparql(top_level: false, **) + " . \n" end.join("") str = "GRAPH #{graph_name.to_sparql(**)} {\n#{str}\n}\n" if graph_name if top_level SPARQL::Algebra::Operator.to_sparql(str, filter_ops: filter_ops, **) else # Filters filter_ops.each do |op| str << "\nFILTER (#{op.to_sparql(**)}) ." end # Extensons extensions = .fetch(:extensions, []) extensions.each do |as, expression| v = expression.to_sparql(**) pp = RDF::Query::Variable.new(as).to_sparql(**) str << "\nBIND (" << v << " AS " << pp << ") ." end str = "{#{str}}" unless filter_ops.empty? && extensions.empty? str end end |
#to_sxp_bin ⇒ Array
Transform Query into an Array form of an SSE
If Query has the as_container
option set, serialize as Quads Otherwise, If Query is named, serialize as a GroupGraphPattern. Otherise, serialize as a BGP
423 424 425 426 427 428 429 430 |
# File 'lib/sparql/algebra/extensions.rb', line 423 def to_sxp_bin if [:as_container] [:graph, graph_name] + [patterns.map(&:to_sxp_bin)] else res = [:bgp] + patterns.map(&:to_sxp_bin) (graph_name ? [:graph, graph_name, res] : res) end end |
#vars ⇒ Array<RDF::Query::Variable>
Return the variables contained within patterns and graph name
504 505 506 |
# File 'lib/sparql/algebra/extensions.rb', line 504 def vars variables.values end |