Class: RDF::AllegroGraph::Query

Inherits:
Query
  • Object
show all
Includes:
Functors::SnaFunctors
Defined in:
lib/rdf/allegro_graph/query.rb,
lib/rdf/allegro_graph/query/functor_expression.rb,
lib/rdf/allegro_graph/query/prolog_literal.rb

Overview

A query with AllegroGraph-specific extensions.

Note that many of of the more exotic features of this class can only be used when running Prolog queries against a Session object. This requires both elevated AllegroGraph privileges and dedicated back-end session resources on the server, so plan accordingly.

The Functors module contains a wide variety of functors which may be used when building a Prolog query.

Defined Under Namespace

Classes: FunctorExpression, PrologLiteral

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Functors::SnaFunctors

#bidirectional_search_paths, #breadth_first_search_paths, #depth_first_search_paths, #ego_group, #ego_group_member, #neighbor_count, #neighbors

Instance Attribute Details

#query_optionsObject (readonly)

Our query options.



25
26
27
# File 'lib/rdf/allegro_graph/query.rb', line 25

def query_options
  @query_options
end

Instance Method Details

#functor(name, *arguments)

This method returns an undefined value.

Add a functor expression to this query. Functors can only be used in Prolog queries.

Parameters:

  • name (String)
  • arguments (Array<Symbol,RDF::Value,value>)

    The arguments to the functor, which may be either variables, RDF::Value objects, or Ruby values that we can convert to literals.



81
82
83
84
85
# File 'lib/rdf/allegro_graph/query.rb', line 81

def functor(name, *arguments)
  # TODO: Don't abuse duck-typing quite so much.
  patterns <<
    RDF::AllegroGraph::Query::FunctorExpression.new(name, *arguments)
end

#requires_prolog?Boolean

Does this query contain Prolog-specific functors that we can't represent as SPARQL?

Returns:

  • (Boolean)


91
92
93
# File 'lib/rdf/allegro_graph/query.rb', line 91

def requires_prolog?
  !patterns.all? {|p| p.kind_of?(RDF::Query::Pattern) }
end

#runEnumerator<RDF::Query::Solution> #run {|| ... }

Note:

This function returns a single-use Enumerator! If you want to to treat the results as an array, call to_a on it, or you will re-run the query against the server repeatedly. This curious decision is made for consistency with RDF.rb.

Run this query against the associated repository. This method exists solely to make the following API pleasant to use:

repo.build_query do |q|
  q.pattern [:s, :p, :o]
end.run do |solution|
  puts solution
end

Note that this function returns an Enumerator, not an array, because RDF.rb is committed to streaming results gradually. If you want to treat the result as an array, call 'to_a' explicitly:

solutions = repo.build_query do |q|
  q.pattern [:s, :p, :o]
end.run.to_a

If you forget to do this, you will run a new query each time you attempt to iterate over the solutions!

Overloads:

  • #runEnumerator<RDF::Query::Solution>

    Returns:

    • (Enumerator<RDF::Query::Solution>)
  • #run {|| ... }

    This method returns an undefined value.

    Yields:

    • solution

    Yield Parameters:

    • (RDF::Query::Solution)

    Yield Returns:

    • (void)

See Also:

  • Repository#query


69
70
71
# File 'lib/rdf/allegro_graph/query.rb', line 69

def run(&block)
  @repository.query(self, &block)
end