module Tripod::Repository
This module wraps access to an RDF::Repository
Attributes
repository[R]
Public Instance Methods
get_triples_for_this_resource()
click to toggle source
returns a graph of triples from the underlying repository where this resource's uri is the subject.
# File lib/tripod/repository.rb, line 63 def get_triples_for_this_resource triples_graph = RDF::Graph.new @repository.query([RDF::URI.new(self.uri), :predicate, :object]) do |stmt| triples_graph << stmt end triples_graph end
hydrate!(opts = {})
click to toggle source
hydrates the resource's repo with statements from the db or passed in graph of statements. where the subject is the uri of this resource.
@example Hydrate the resource from the db
person.hydrate!
@example Hydrate the resource from a passed in graph
person.hydrate!(:graph => my_graph)
@return [ RDF::Repository ] A reference to the repository for this instance.
# File lib/tripod/repository.rb, line 20 def hydrate!(opts = {}) graph = opts[:graph] # we require that the uri is set. raise Tripod::Errors::UriNotSet.new() unless @uri @repository = RDF::Repository.new # make sure that the repo is empty before we begin if graph graph.each_statement do |statement| # Note that we use all statements, even those not about this resource, in case we're being # passed eager-loaded ones. @repository << statement end else triples = retrieve_triples_from_database @repository = RDF::Repository.new RDF::Reader.for(:ntriples).new(triples) do |reader| reader.each_statement do |statement| @repository << statement end end end end
repository_as_graph()
click to toggle source
returns a graph of all triples in the repository
# File lib/tripod/repository.rb, line 50 def repository_as_graph g = RDF::Graph.new @repository.each_statement do |s| g << s end g end
retrieve_triples_from_database(accept_header=Tripod.ntriples_header_str)
click to toggle source
# File lib/tripod/repository.rb, line 58 def retrieve_triples_from_database(accept_header=Tripod.ntriples_header_str) Tripod::SparqlClient::Query.query(self.class.all_triples_query(uri, graph_uri: self.graph_uri), accept_header) end