Package rdfalchemy :: Package sparql :: Module sesame2 :: Class SesameGraph
[hide private]
[frames] | no frames]

Class SesameGraph

source code

 object --+    
          |    
SPARQLGraph --+
              |
             SesameGraph

openrdf-sesame graph via http Uses the sesame2 HTTP communication protocol to provide rdflib type api constructor takes http endpoint and repository name e.g. SesameGraph('http://www.openvest.org:8080/sesame/repositories/Test')
Instance Methods [hide private]
 
__init__(self, url, context=None)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
get_namespaces(self)
Namespaces dict
source code
 
get_contexts(self)
context list ...
source code
 
_statement_encode(self, (s, p, o), context)
helper function to encode triples to sesame statement uri's
source code
 
add(self, (s, p, o), context=None)
Add a triple with optional context
source code
 
remove(self, (s, p, o), context=None)
Remove a triple from the graph
source code
 
triples(self, (s, p, o), context=None)
Generator over the triple store
source code
 
__len__(self)
Returns the number of triples in the graph calls http://{self.url}/size very fast
source code
 
set(self, (subject, predicate, object))
Convenience method to update the value of object
source code
 
qname(self, uri)
turn uri into a qname given self.namespaces
source code
 
query(self, strOrQuery, initBindings={}, initNs={}, resultMethod='brtr', processor='sparql', rawResults=False)
Executes a SPARQL query against this Graph
source code
 
parse(self, source, publicID=None, format='xml', method='POST')
Parse source into Graph
source code
 
load(self, source, publicID=None, format='xml') source code

Inherited from SPARQLGraph: __contains__, __iter__, comment, construct, describe, getParser, items, label, objects, predicate_objects, predicates, subject_objects, subject_predicates, subjects, transitive_objects, transitive_subjects, value

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Methods [hide private]

Inherited from SPARQLGraph (private): _processInitBindings

Class Variables [hide private]
  parsers = {'brtr': <class 'rdfalchemy.sparql.parsers._BRTRSPAR...
Properties [hide private]
  namespaces
  contexts

Inherited from object: __class__

Method Details [hide private]

__init__(self, url, context=None)
(Constructor)

source code 
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Overrides: object.__init__
(inherited documentation)

get_contexts(self)

source code 
context list ... pretty slow

remove(self, (s, p, o), context=None)

source code 

Remove a triple from the graph

If the triple does not provide a context attribute, removes the triple from all contexts.

triples(self, (s, p, o), context=None)

source code 

Generator over the triple store

Returns triples that match the given triple pattern. If triple pattern does not provide a context, all contexts will be searched.

Parameters:
  • method - must be 'CONSTRUCT' or 'SELECT'

    • CONSTRUCT calls CONSTRUCT query and returns a Graph result

    • SELECT calls a SELECT query and returns an interator streaming over the results

Returns:
a generator over triples matching the pattern
Overrides: SPARQLGraph.triples

set(self, (subject, predicate, object))

source code 

Convenience method to update the value of object

Remove any existing triples for subject and predicate before adding (subject, predicate, object).

qname(self, uri)

source code 
turn uri into a qname given self.namespaces
Overrides: SPARQLGraph.qname

query(self, strOrQuery, initBindings={}, initNs={}, resultMethod='brtr', processor='sparql', rawResults=False)

source code 
Executes a SPARQL query against this Graph
Parameters:
  • strOrQuery - Is either a string consisting of the SPARQL query
  • initBindings - optional mapping from a Variable to an RDFLib term (used as initial bindings for SPARQL query)
  • initNs - optional mapping from a namespace prefix to a namespace
  • resultMethod - results query requested (must be 'xml', 'json' 'brtr') xml streams over the result set and json must read the entire set to succeed
  • processor - The kind of RDF query (must be 'sparql' or 'serql')
  • rawResults - If set to True, returns the raw xml or json stream rather than the parsed results.
Overrides: SPARQLGraph.query

parse(self, source, publicID=None, format='xml', method='POST')

source code 

Parse source into Graph

Graph will get loaded into it's own context (sub graph). Format defaults to 'xml' (AKA: rdf/xml).

Parameters:
  • source - source file in the form of "http://....." or "~/dir/file.rdf"
  • publicID - optional the logical URI if it's different from the physical source URI.
  • format - must be one of 'xml' or 'n3'
  • method - must be one of

    • 'POST' -- method adds data to a context
    • 'PUT' -- method replaces data in a context
Returns:
Returns the context into which the source was parsed.

Class Variable Details [hide private]

parsers

Value:
{'brtr': <class 'rdfalchemy.sparql.parsers._BRTRSPARQLHandler'>,
 'json': <class 'rdfalchemy.sparql.parsers._JSONSPARQLHandler'>,
 'xml': <class 'rdfalchemy.sparql.parsers._XMLSPARQLHandler'>}

Property Details [hide private]

namespaces

Get Method:
get_namespaces(self) - Namespaces dict

contexts

Get Method:
get_contexts(self) - context list ...