Class: RDF::Marmotta

Inherits:
SPARQL::Client::Repository
  • Object
show all
Defined in:
lib/rdf/marmotta.rb

Defined Under Namespace

Classes: Client

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :sparql => 'sparql/select',
  :sparql_update => 'sparql/update',
  :ldpath => 'ldpath'
}
CTYPES =

Supported Accept headers for Marmotta. As of 3.3.0, Marmotta will reject a request if the first content type listed is not suppported.

RDF::Format.content_types.select do |key, values|
  !(values.map(&:to_s) & ['RDF::RDFXML::Format',
                          'RDF::Turtle::Format',
                          'RDF::TriG::Format',
                          'RDF::TriX::Format',
                          'RDF::N3::Format']).empty?
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url, options = {}) ⇒ Marmotta

Returns a new instance of Marmotta.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rdf/marmotta.rb', line 30

def initialize(base_url, options = {})
  @options   = options.dup

  @tx_class ||= @options.delete(:transaction_class) { DEFAULT_TX_CLASS }

  @endpoints = DEFAULT_OPTIONS
  @endpoints.merge!(options)
  @endpoints.each do |k, v|
    next unless RDF::URI(v.to_s).relative?
    @endpoints[k] = (RDF::URI(base_url.to_s) / v.to_s)
  end
  @client        = Client.new(endpoints[:sparql].to_s, options)
  @update_client = Client.new(endpoints[:sparql_update].to_s, options)
end

Instance Attribute Details

#endpointsObject

Returns the value of attribute endpoints.



8
9
10
# File 'lib/rdf/marmotta.rb', line 8

def endpoints
  @endpoints
end

#update_clientObject (readonly)

Returns the value of attribute update_client.



9
10
11
# File 'lib/rdf/marmotta.rb', line 9

def update_client
  @update_client
end

Instance Method Details

#clearObject



64
65
66
# File 'lib/rdf/marmotta.rb', line 64

def clear
  update_client.query("DELETE { ?s ?p ?o } WHERE { ?s ?p ?o }")
end

#countObject



53
54
55
56
57
58
59
60
61
62
# File 'lib/rdf/marmotta.rb', line 53

def count
  begin
    binding = client.query("SELECT (COUNT(*) AS ?no) WHERE { ?s ?p ?o }").first.to_hash
    binding[binding.keys.first].value.to_i
  rescue SPARQL::Client::ServerError
    count = 0
    each_statement { count += 1 }
    count
  end
end

#delete_statement(statement) ⇒ Object



49
50
51
# File 'lib/rdf/marmotta.rb', line 49

def delete_statement(statement)
  delete(statement)
end

#query_clientObject



45
46
47
# File 'lib/rdf/marmotta.rb', line 45

def query_client
  @client
end