This wrapper intercepts calls through the store interface and implements thread-safe logging of destructive operations (adds / removes) in reverse. This is persisted on the store instance and the reverse operations are executed In order to return the store to the state it was when the transaction began Since the reverse operations are persisted on the store, the store itself acts as a transaction.
Calls to commit or rollback, flush the list of reverse operations This provides thread-safe atomicity and isolation (assuming concurrent operations occur with different store instances), but no durability (transactions are persisted in memory and won’t be available to reverse operations after the system fails): A and I out of ACID.
Bases: Store
store (Store
) –
identifier: URIRef of the Store. Defaults to CWD configuration: string containing information open can use to connect to datastore.
store (Store
) –
Number of statements in the store. This should only account for non- quoted (asserted) statements if the context is not specified, otherwise it should return the number of statements in the formula or context given.
Adds the given statement to a specific context or to the model. The quoted argument is interpreted by formula-aware stores to indicate this statement is quoted/hypothetical It should be an error to not specify a context and have the quoted argument be True. It should also be an error for the quoted argument to be True when the store is not formula-aware.
This closes the database connection. The commit_pending_transaction parameter specifies whether to commit all pending transactions before closing (if the store is transactional).
Generator over all contexts in the graph. If triple is specified, a generator over all contexts the triple is in.
if store is graph_aware, may also return empty contexts
This destroys the instance of the store identified by the configuration string.
Opens the store specified by the configuration string. If create is True a store will be created if it does not already exist. If create is False and a store does not already exist an exception is raised. An exception is also raised if a store exists, but there is insufficient permissions to open the store. This should return one of: VALID_STORE, CORRUPTED_STORE, or NO_STORE
If stores provide their own SPARQL implementation, override this.
queryGraph is None, a URIRef or ‘__UNION__’ If None the graph is specified in the query-string/object If URIRef it specifies the graph to query, If ‘__UNION__’ the union of all named graphs should be queried (This is used by ConjunctiveGraphs Values other than None obviously only makes sense for context-aware stores.)
Remove the set of triples matching the pattern from the store
A generator over all the triples matching the pattern. Pattern can include any objects for used for comparing against nodes in the store, for example, REGEXTerm, URIRef, Literal, BNode, Variable, Graph, QuotedGraph, Date? DateRange?
Bases: Store
A store that allows for on-disk persistent using BerkeleyDB, a fast key/value DB.
This store implementation used to be known, previous to rdflib 6.0.0 as ‘Sleepycat’ due to that being the then name of the Python wrapper for BerkeleyDB.
This store allows for quads as well as triples. See examples of use in both the examples.berkeleydb_example
and test/test_store/test_store_berkeleydb.py
files.
NOTE on installation:
To use this store, you must have BerkeleyDB installed on your system separately to Python (brew install berkeley-db
on a Mac) and also have the BerkeleyDB Python wrapper installed (pip install berkeleydb
). You may need to install BerkeleyDB Python wrapper like this: YES_I_HAVE_THE_RIGHT_TO_USE_THIS_BERKELEY_DB_VERSION=1 pip install berkeleydb
identifier (Optional
[Identifier
]) –
identifier: URIRef of the Store. Defaults to CWD configuration: string containing information open can use to connect to datastore.
identifier (Optional
[Identifier
]) –
Number of statements in the store. This should only account for non- quoted (asserted) statements if the context is not specified, otherwise it should return the number of statements in the formula or context given.
Add a triple to the store of triples.
Add a graph to the store, no effect if the graph already exists. :type graph: Graph
:param graph: a Graph instance
This closes the database connection. The commit_pending_transaction parameter specifies whether to commit all pending transactions before closing (if the store is transactional).
Generator over all contexts in the graph. If triple is specified, a generator over all contexts the triple is in.
if store is graph_aware, may also return empty contexts
Opens the store specified by the configuration string. If create is True a store will be created if it does not already exist. If create is False and a store does not already exist an exception is raised. An exception is also raised if a store exists, but there is insufficient permissions to open the store. This should return one of: VALID_STORE, CORRUPTED_STORE, or NO_STORE
Remove the set of triples matching the pattern from the store
Remove a graph from the store, this should also remove all triples in the graph
graphid – a Graph instance
graph (Graph
) –
A generator over all the triples matching
Bases: object
list of weak references to the object (if defined)
Bases: object
A generator that will help clean up when it is done being used.
Bases: Store
An in memory implementation of a triple store.
Same as SimpleMemory above, but is Context-aware, Graph-aware, and Formula-aware Authors: Ashley Sommer
identifier (Optional
[Identifier
]) –
identifier: URIRef of the Store. Defaults to CWD configuration: string containing information open can use to connect to datastore.
identifier (Optional
[Identifier
]) –
Number of statements in the store. This should only account for non- quoted (asserted) statements if the context is not specified, otherwise it should return the number of statements in the formula or context given.
Add a triple to the store of triples.
Add a graph to the store, no effect if the graph already exists. :type graph: Graph
:param graph: a Graph instance
Generator over all contexts in the graph. If triple is specified, a generator over all contexts the triple is in.
if store is graph_aware, may also return empty contexts
If stores provide their own SPARQL implementation, override this.
queryGraph is None, a URIRef or ‘__UNION__’ If None the graph is specified in the query-string/object If URIRef it specifies the graph to query, If ‘__UNION__’ the union of all named graphs should be queried (This is used by ConjunctiveGraphs Values other than None obviously only makes sense for context-aware stores.)
Remove the set of triples matching the pattern from the store
Remove a graph from the store, this should also remove all triples in the graph
A generator over all the triples matching
If stores provide their own (SPARQL) Update implementation, override this.
queryGraph is None, a URIRef or ‘__UNION__’ If None the graph is specified in the query-string/object If URIRef it specifies the graph to query, If ‘__UNION__’ the union of all named graphs should be queried (This is used by ConjunctiveGraphs Values other than None obviously only makes sense for context-aware stores.)
Bases: Store
A fast naive in memory implementation of a triple store.
This triple store uses nested dictionaries to store triples. Each triple is stored in two such indices as follows spo[s][p][o] = 1 and pos[p][o][s] = 1.
Authors: Michel Pelletier, Daniel Krech, Stefan Niederhauser
identifier (Optional
[Identifier
]) –
identifier: URIRef of the Store. Defaults to CWD configuration: string containing information open can use to connect to datastore.
identifier (Optional
[Identifier
]) –
Number of statements in the store. This should only account for non- quoted (asserted) statements if the context is not specified, otherwise it should return the number of statements in the formula or context given.
Add a triple to the store of triples.
If stores provide their own SPARQL implementation, override this.
queryGraph is None, a URIRef or ‘__UNION__’ If None the graph is specified in the query-string/object If URIRef it specifies the graph to query, If ‘__UNION__’ the union of all named graphs should be queried (This is used by ConjunctiveGraphs Values other than None obviously only makes sense for context-aware stores.)
Remove the set of triples matching the pattern from the store
A generator over all the triples matching
If stores provide their own (SPARQL) Update implementation, override this.
queryGraph is None, a URIRef or ‘__UNION__’ If None the graph is specified in the query-string/object If URIRef it specifies the graph to query, If ‘__UNION__’ the union of all named graphs should be queried (This is used by ConjunctiveGraphs Values other than None obviously only makes sense for context-aware stores.)
This wrapper intercepts calls through the store interface which make use of the REGEXTerm class to represent matches by REGEX instead of literal comparison.
Implemented for stores that don’t support this and essentially provides the support by replacing the REGEXTerms by wildcards (None) and matching against the results from the store it’s wrapping.
Bases: Store
identifier: URIRef of the Store. Defaults to CWD configuration: string containing information open can use to connect to datastore.
Number of statements in the store. This should only account for non- quoted (asserted) statements if the context is not specified, otherwise it should return the number of statements in the formula or context given.
context – a graph instance to query or None
Adds the given statement to a specific context or to the model. The quoted argument is interpreted by formula-aware stores to indicate this statement is quoted/hypothetical It should be an error to not specify a context and have the quoted argument be True. It should also be an error for the quoted argument to be True when the store is not formula-aware.
override – rebind, even if the given namespace is already bound to another prefix.
This closes the database connection. The commit_pending_transaction parameter specifies whether to commit all pending transactions before closing (if the store is transactional).
Generator over all contexts in the graph. If triple is specified, a generator over all contexts the triple is in.
if store is graph_aware, may also return empty contexts
a generator over Nodes
This destroys the instance of the store identified by the configuration string.
Opens the store specified by the configuration string. If create is True a store will be created if it does not already exist. If create is False and a store does not already exist an exception is raised. An exception is also raised if a store exists, but there is insufficient permissions to open the store. This should return one of: VALID_STORE, CORRUPTED_STORE, or NO_STORE
Remove the set of triples matching the pattern from the store
A generator over all the triples matching the pattern. Pattern can include any objects for used for comparing against nodes in the store, for example, REGEXTerm, URIRef, Literal, BNode, Variable, Graph, QuotedGraph, Date? DateRange?
context – A conjunctive query can be indicated by either providing a value of None, or a specific context can be queries by passing a Graph instance (if store is context aware).
Bases: str
REGEXTerm can be used in any term slot and is interpreted as a request to perform a REGEX match (not a string comparison) using the value (pre-compiled) for checking rdf:type matches
Helper for pickle.
list of weak references to the object (if defined)
Bases: object
this class deals with nitty gritty details of talking to a SPARQL server
auth, if present, must be a tuple of (username, password) used for Basic Authentication
Any additional keyword arguments will be passed to to the request, and can be used to setup timeouts etc.
list of weak references to the object (if defined)
Bases: Exception
list of weak references to the object (if defined)
This is an RDFLib store around Ivan Herman et al.’s SPARQL service wrapper. This was first done in layer-cake, and then ported to RDFLib
Bases: SPARQLConnector
, Store
An RDFLib store around a SPARQL endpoint
This is context-aware and should work as expected when a context is specified.
For ConjunctiveGraphs, reading is done from the “default graph”. Exactly what this means depends on your endpoint, because SPARQL does not offer a simple way to query the union of all graphs as it would be expected for a ConjuntiveGraph. This is why we recommend using Dataset instead, which is motivated by the SPARQL 1.1.
Fuseki/TDB has a flag for specifying that the default graph is the union of all graphs (tdb:unionDefaultGraph
in the Fuseki config).
Warning
By default the SPARQL Store does not support blank-nodes!
As blank-nodes act as variables in SPARQL queries, there is no way to query for a particular blank node without using non-standard SPARQL extensions.
See http://www.w3.org/TR/sparql11-query/#BGPsparqlBNodes
You can make use of such extensions through the node_to_sparql
argument. For example if you want to transform BNode(‘0001’) into “<bnode:b0001>”, you can use a function like this:
>>> def my_bnode_ext(node): ... if isinstance(node, BNode): ... return '<bnode:b%s>' % node ... return _node_to_sparql(node) >>> store = SPARQLStore('http://dbpedia.org/sparql', ... node_to_sparql=my_bnode_ext)
You can request a particular result serialization with the returnFormat
parameter. This is a string that must have a matching plugin registered. Built in is support for xml
, json
, csv
, tsv
and application/rdf+xml
.
The underlying SPARQLConnector uses the urllib library. Any extra kwargs passed to the SPARQLStore connector are passed to urllib when doing HTTP calls. I.e. you have full control of cookies/auth/headers.
Form example:
>>> store = SPARQLStore('...my endpoint ...', auth=('user','pass'))
will use HTTP basic auth.
auth, if present, must be a tuple of (username, password) used for Basic Authentication
Any additional keyword arguments will be passed to to the request, and can be used to setup timeouts etc.
Number of statements in the store. This should only account for non- quoted (asserted) statements if the context is not specified, otherwise it should return the number of statements in the formula or context given.
Adds the given statement to a specific context or to the model. The quoted argument is interpreted by formula-aware stores to indicate this statement is quoted/hypothetical It should be an error to not specify a context and have the quoted argument be True. It should also be an error for the quoted argument to be True when the store is not formula-aware.
Adds each item in the list of statements to a specific context. The quoted argument is interpreted by formula-aware stores to indicate this statement is quoted/hypothetical. Note that the default implementation is a redirect to add
Add a graph to the store, no effect if the graph already exists. :type graph: Graph
:param graph: a Graph instance
Iterates over results to “SELECT ?NAME { GRAPH ?NAME { ?s ?p ?o } }” or “SELECT ?NAME { GRAPH ?NAME {} }” if triple is None
.
Returns instances of this store with the SPARQL wrapper object updated via addNamedGraph(?NAME).
This causes a named-graph-uri key / value pair to be sent over the protocol.
Please note that some SPARQL endpoints are not able to find empty named graphs.
This destroys the instance of the store identified by the configuration string.
A generator of objects with the given subject and predicate
This method is included so that calls to this Store via Graph, e.g. Graph(“SPARQLStore”), can set the required parameters
A generator of (predicate, object) tuples for the given subject
A generator of predicates with the given subject and object
If stores provide their own SPARQL implementation, override this.
queryGraph is None, a URIRef or ‘__UNION__’ If None the graph is specified in the query-string/object If URIRef it specifies the graph to query, If ‘__UNION__’ the union of all named graphs should be queried (This is used by ConjunctiveGraphs Values other than None obviously only makes sense for context-aware stores.)
Remove the set of triples matching the pattern from the store
Remove a graph from the store, this should also remove all triples in the graph
A generator of (subject, object) tuples for the given predicate
A generator of (subject, predicate) tuples for the given object
A generator of subjects with the given predicate and object
tuple (s, o, p) the triple used as filter for the SPARQL select. (None, None, None) means anything.
context context the graph effectively calling this method.
Returns a tuple of triples executing essentially a SPARQL like SELECT ?subj ?pred ?obj WHERE { ?subj ?pred ?obj }
context may include three parameter to refine the underlying query:
LIMIT: an integer to limit the number of results
OFFSET: an integer to enable paging of results
ORDERBY: an instance of Variable(‘s’), Variable(‘o’) or Variable(‘p’) or, by default, the first ‘None’ from the given triple
Warning
Using LIMIT or OFFSET automatically include ORDERBY otherwise this is because the results are retrieved in a not deterministic way (depends on the walking path on the graph)
Using OFFSET without defining LIMIT will discard the first OFFSET - 1 results
a_graph.LIMIT = limit a_graph.OFFSET = offset triple_generator = a_graph.triples(mytriple): # do something # Removes LIMIT and OFFSET if not required for the next triple() calls del a_graph.LIMIT del a_graph.OFFSET
A variant of triples that can take a list of terms instead of a single term in any slot. Stores can implement this to optimize the response time from the import default ‘fallback’ implementation, which will iterate over each term in the list and dispatch to triples.
If stores provide their own (SPARQL) Update implementation, override this.
queryGraph is None, a URIRef or ‘__UNION__’ If None the graph is specified in the query-string/object If URIRef it specifies the graph to query, If ‘__UNION__’ the union of all named graphs should be queried (This is used by ConjunctiveGraphs Values other than None obviously only makes sense for context-aware stores.)
Bases: SPARQLStore
A store using SPARQL queries for reading and SPARQL Update for changes.
This can be context-aware, if so, any changes will be to the given named graph only.
In favor of the SPARQL 1.1 motivated Dataset, we advise against using this with ConjunctiveGraphs, as it reads and writes from and to the “default graph”. Exactly what this means depends on the endpoint and can result in confusion.
For Graph objects, everything works as expected.
See the SPARQLStore
base class for more information.
:param autocommit if set, the store will commit after every writing operations. If False, we only make queries on the server once commit is called.
:param dirty_reads if set, we do not commit before reading. So you cannot read what you wrote before manually calling commit.
Number of statements in the store. This should only account for non- quoted (asserted) statements if the context is not specified, otherwise it should return the number of statements in the formula or context given.
Add a triple to the store of triples.
Add a list of quads to the store.
Add a graph to the store, no effect if the graph already exists. :type graph: Graph
:param graph: a Graph instance
add(), addN(), and remove() are transactional to reduce overhead of many small edits. Read and update() calls will automatically commit any outstanding edits. This should behave as expected most of the time, except that alternating writes and reads can degenerate to the original call-per-triple situation that originally existed.
Iterates over results to “SELECT ?NAME { GRAPH ?NAME { ?s ?p ?o } }” or “SELECT ?NAME { GRAPH ?NAME {} }” if triple is None
.
Returns instances of this store with the SPARQL wrapper object updated via addNamedGraph(?NAME).
This causes a named-graph-uri key / value pair to be sent over the protocol.
Please note that some SPARQL endpoints are not able to find empty named graphs.
A generator of objects with the given subject and predicate
sets the endpoint URLs for this SPARQLStore
A generator of (predicate, object) tuples for the given subject
A generator of predicates with the given subject and object
If stores provide their own SPARQL implementation, override this.
queryGraph is None, a URIRef or ‘__UNION__’ If None the graph is specified in the query-string/object If URIRef it specifies the graph to query, If ‘__UNION__’ the union of all named graphs should be queried (This is used by ConjunctiveGraphs Values other than None obviously only makes sense for context-aware stores.)
Remove a triple from the store
Remove a graph from the store, this should also remove all triples in the graph
A generator of (subject, object) tuples for the given predicate
A generator of (subject, predicate) tuples for the given object
A generator of subjects with the given predicate and object
tuple (s, o, p) the triple used as filter for the SPARQL select. (None, None, None) means anything.
context context the graph effectively calling this method.
Returns a tuple of triples executing essentially a SPARQL like SELECT ?subj ?pred ?obj WHERE { ?subj ?pred ?obj }
context may include three parameter to refine the underlying query:
LIMIT: an integer to limit the number of results
OFFSET: an integer to enable paging of results
ORDERBY: an instance of Variable(‘s’), Variable(‘o’) or Variable(‘p’) or, by default, the first ‘None’ from the given triple
Warning
Using LIMIT or OFFSET automatically include ORDERBY otherwise this is because the results are retrieved in a not deterministic way (depends on the walking path on the graph)
Using OFFSET without defining LIMIT will discard the first OFFSET - 1 results
a_graph.LIMIT = limit a_graph.OFFSET = offset triple_generator = a_graph.triples(mytriple): # do something # Removes LIMIT and OFFSET if not required for the next triple() calls del a_graph.LIMIT del a_graph.OFFSET
Perform a SPARQL Update Query against the endpoint, INSERT, LOAD, DELETE etc. Setting initNs adds PREFIX declarations to the beginning of the update. Setting initBindings adds inline VALUEs to the beginning of every WHERE clause. By the SPARQL grammar, all operations that support variables (namely INSERT and DELETE) require a WHERE clause. Important: initBindings fails if the update contains the substring ‘WHERE {’ which does not denote a WHERE clause, e.g. if it is part of a literal.
Context-aware query rewriting
When: If context-awareness is enabled and the graph is not the default graph of the store.
Why: To ensure consistency with the Memory
store. The graph must accept “local” SPARQL requests (requests with no GRAPH keyword) as if it was the default graph.
What is done: These “local” queries are rewritten by this store. The content of each block of a SPARQL Update operation is wrapped in a GRAPH block except if the block is empty. This basically causes INSERT, INSERT DATA, DELETE, DELETE DATA and WHERE to operate only on the context.
Example: "INSERT DATA { <urn:michel> <urn:likes> <urn:pizza> }"
is converted into "INSERT DATA { GRAPH <urn:graph> { <urn:michel> <urn:likes> <urn:pizza> } }"
.
Warning: Queries are presumed to be “local” but this assumption is not checked. For instance, if the query already contains GRAPH blocks, the latter will be wrapped in new GRAPH blocks.
Warning: A simplified grammar is used that should tolerate extensions of the SPARQL grammar. Still, the process may fail in uncommon situations and produce invalid output.
This package contains modules for additional RDFLib stores
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4