Class: RDF::AllegroGraph::AbstractRepository

Inherits:
Repository
  • Object
show all
Defined in:
lib/rdf/allegro_graph/abstract_repository.rb

Overview

Features shared by regular AllegroGraph repositories and by persistent backend sessions.

Note that this class does not interoperate well with the Unix fork command if you're using blank nodes. See README.md for details.

Direct Known Subclasses

Repository, Session

RDF::Repository methods collapse

RDF::Enumerable methods collapse

AllegroGraph-specific query methods collapse

RDF::Mutable methods collapse

Serialization methods collapse

Instance Method Details

#build_query(query_options = {}) {|The| ... } ⇒ Query

Construct an AllegroGraph-specific query.

Options Hash (query_options):

  • :infer (true, false, String)

    The AllegroGraph inference mode to use. Defaults to false. The value true is equivalent to 'rdfs++'.

Yields:

  • query

Yield Parameters:

  • The (Query)

    query to build. Use the Query API to add patterns and functors.

Yield Returns:

  • (void)

See Also:



273
274
275
# File 'lib/rdf/allegro_graph/abstract_repository.rb', line 273

def build_query(query_options={}, &block)
  Query.new(self, query_options, &block)
end

#clear

This method returns an undefined value.

Clear all statements from the repository.



340
341
342
# File 'lib/rdf/allegro_graph/abstract_repository.rb', line 340

def clear
  @repo.statements.delete
end

#each {|statement| ... }

This method returns an undefined value.

Iterate over all statements in the repository. This is used by RDF::Enumerable as a fallback for handling any unimplemented methods.

Yields:

  • (statement)

Yield Parameters:

  • statement (RDF::Statement)

Yield Returns:

  • (void)


79
80
81
# File 'lib/rdf/allegro_graph/abstract_repository.rb', line 79

def each(&block)
  query_pattern(RDF::Query::Pattern.new, &block)
end

#has_statement?(statement) ⇒ Boolean

Does the repository contain the specified statement?



87
88
89
90
# File 'lib/rdf/allegro_graph/abstract_repository.rb', line 87

def has_statement?(statement)
  found = @repo.statements.find(statement_to_dict(statement))
  !found.empty?
end

#prolog_query(query) {|solution| ... } #prolog_query(pattern) ⇒ Enumerator<RDF::Query::Solution>

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.

This method returns an undefined value.

Run a raw Prolog query.

Overloads:

  • #prolog_query(query) {|solution| ... }

    This method returns an undefined value.

    Yields:

    • solution

    Yield Parameters:

    • solution (RDF::Query::Solution)

    Yield Returns:

    • (void)

See Also:



234
235
236
# File 'lib/rdf/allegro_graph/abstract_repository.rb', line 234

def prolog_query(query, query_options={}, &block)
  raw_query(:prolog, query, query_options, &block)
end

#serialize(value) ⇒ String

Serialize an RDF::Value for transmission to the server. This is exported for low-level libraries that need to access our serialization and deserialization machinery, which has special-case support for RDF nodes.

See Also:



356
357
358
359
360
361
# File 'lib/rdf/allegro_graph/abstract_repository.rb', line 356

def serialize(value)
  case value
  when RDF::Query::Variable then value.to_s
  else RDF::NTriples::Writer.serialize(map_to_server(value))
  end
end

#serialize_prolog(value) ⇒ String

Serialize an RDF::Value for use in a Prolog expression that will be transmitted to the server.

See Also:



369
370
371
372
373
374
375
# File 'lib/rdf/allegro_graph/abstract_repository.rb', line 369

def serialize_prolog(value)
  case value
  when RDF::AllegroGraph::Query::PrologLiteral then value.to_s
  when RDF::Query::Variable then value.to_s
  else "!#{serialize(value)}"
  end
end

#sparql_query(query) {|solution| ... } #sparql_query(pattern) ⇒ Enumerator<RDF::Query::Solution>

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.

This method returns an undefined value.

Run a raw SPARQL query.

Overloads:

  • #sparql_query(query) {|solution| ... }

    This method returns an undefined value.

    Yields:

    • solution

    Yield Parameters:

    • solution (RDF::Query::Solution)

    Yield Returns:

    • (void)

See Also:



209
210
211
# File 'lib/rdf/allegro_graph/abstract_repository.rb', line 209

def sparql_query(query, query_options={}, &block)
  raw_query(:sparql, query, query_options, &block)
end

#supports?(feature) ⇒ Boolean

Returns true if feature is supported.



47
48
49
50
51
52
# File 'lib/rdf/allegro_graph/abstract_repository.rb', line 47

def supports?(feature)
  case feature.to_sym
  when :context then true
  else super
  end
end