Class: Ldpath::Loaders::LinkedDataFragment

Inherits:
Object
  • Object
show all
Defined in:
lib/ldpath/loaders/linked_data_fragment.rb

Constant Summary collapse

NEXT_PAGE =
RDF::URI('http://www.w3.org/ns/hydra/core#nextPage')

Instance Method Summary collapse

Constructor Details

#initialize(endpoint) ⇒ LinkedDataFragment

Returns a new instance of LinkedDataFragment.



10
11
12
# File 'lib/ldpath/loaders/linked_data_fragment.rb', line 10

def initialize(endpoint)
  @endpoint = endpoint
end

Instance Method Details

#load(uri) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ldpath/loaders/linked_data_fragment.rb', line 14

def load(uri)
  Ldpath.logger.debug "Loading LDF data for #{uri.inspect}"

  graph = RDF::Graph.new
  request_uri = RDF::URI("#{@endpoint}?subject=#{CGI.escape(uri)}")

  while request_uri
    Ldpath.logger.debug " -- querying #{request_uri}"
    request_graph = RDF::Graph.load(request_uri)
    graph.insert_statements(request_graph)
    request_uri = request_graph.first_object([request_uri, NEXT_PAGE, nil])
  end

  graph
end