Class: IqTriplestorage::SesameAdaptor

Inherits:
BaseAdaptor show all
Defined in:
lib/iq_triplestorage/sesame_adaptor.rb

Instance Attribute Summary

Attributes inherited from BaseAdaptor

#host

Instance Method Summary collapse

Methods inherited from BaseAdaptor

#http_request

Constructor Details

#initialize(host, options = {}) ⇒ SesameAdaptor

Returns a new instance of SesameAdaptor.

Raises:

  • (ArgumentError)


8
9
10
11
12
# File 'lib/iq_triplestorage/sesame_adaptor.rb', line 8

def initialize(host, options={})
  super
  @repo = options[:repository]
  raise(ArgumentError, "repository must not be nil") if @repo.nil?
end

Instance Method Details

#batch_update(triples_by_graph) ⇒ Object

expects a hash of N-Triples by graph URI



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/iq_triplestorage/sesame_adaptor.rb', line 15

def batch_update(triples_by_graph)
  path = "/repositories/#{CGI.escape(@repo)}/statements"
  path = URI.join("#{@host}/", path[1..-1]).path

  del_params = triples_by_graph.keys.
      map { |graph| val = CGI.escape("<#{graph}>"); "context=#{val}" }.
      join("&")
  res = http_request("DELETE", "#{path}?#{del_params}")
  return false unless res.code == "204"

  data = triples_by_graph.map do |graph_uri, ntriples|
    "<#{graph_uri}> {\n#{ntriples}\n}\n"
  end.join("\n\n")
  res = http_request("POST", path, data,
        { "Content-Type" => "application/x-trig" })
  return res.code == "204"
end