Module: Tripod::Repository
Overview
This module wraps access to an RDF::Repository
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Instance Method Summary collapse
-
#get_triples_for_this_resource ⇒ Object
returns a graph of triples from the underlying repository where this resource’s uri is the subject.
-
#hydrate!(opts = {}) ⇒ RDF::Repository
hydrates the resource’s repo with statements from the db or passed in graph of statements.
-
#repository_as_graph ⇒ Object
returns a graph of all triples in the repository.
- #retrieve_triples_from_database(accept_header = Tripod.ntriples_header_str) ⇒ Object
Instance Attribute Details
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
7 8 9 |
# File 'lib/tripod/repository.rb', line 7 def repository @repository end |
Instance Method Details
#get_triples_for_this_resource ⇒ Object
returns a graph of triples from the underlying repository where this resource’s uri is the subject.
63 64 65 66 67 68 69 |
# 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 = {}) ⇒ RDF::Repository
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.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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 ⇒ Object
returns a graph of all triples in the repository
50 51 52 53 54 55 56 |
# 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) ⇒ Object
58 59 60 |
# 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 |