Dataquay::BasicStore Class Reference

In-memory RDF data store implementing the Store interface, providing add, remove, matching and query operations for RDF triples and SPARQL, as well as export and import. More...

#include <dataquay/BasicStore.h>

Inherits Dataquay::Store.

List of all members.

Public Types

enum  ImportDuplicatesMode { ImportIgnoreDuplicates, ImportFailOnDuplicates, ImportPermitDuplicates }
 ImportDuplicatesMode determines the outcome when an import operation encounters a triple in the imported data set that already exists in the store. More...

Public Member Functions

 BasicStore ()
 ~BasicStore ()
void setBaseUri (QString uri)
 Set the base URI for the store.
QString getBaseUri () const
 Retrieve the base URI for the store.
void clear ()
 Empty the store (including prefixes as well as triples).
void addPrefix (QString prefix, QString uri)
 Add a prefix/uri pair (an XML namespace, except that this class doesn't directly deal in XML) for use in subsequent operations.
bool add (Triple t)
 Add a triple to the store.
bool remove (Triple t)
 Remove a triple from the store.
void change (ChangeSet changes)
 Atomically apply the sequence of add/remove changes described in the given ChangeSet.
void revert (ChangeSet changes)
 Atomically apply the sequence of add/remove changes described in the given ChangeSet, in reverse (ie removing adds and adding removes, in reverse order).
bool contains (Triple t) const
 Return true if the store contains the given triple, false otherwise.
Triples match (Triple t) const
 Return all triples matching the given wildcard triple.
ResultSet query (QString sparql) const
 Run a SPARQL query against the store and return its results.
Triple matchFirst (Triple t) const
 Return the first triple to match the given wildcard triple.
Node queryFirst (QString sparql, QString bindingName) const
 Run a SPARQL query against the store and return the node of the first result for the given query binding.
QUrl getUniqueUri (QString prefix) const
 Get a new URI, starting with the given prefix, that does not currently exist within this store.
QUrl expand (QString uri) const
 Expand the given URI (which may use local namespaces) and prefix-expand it, returning the result as a QUrl.
void save (QString filename) const
 Export the store to an RDF/TTL file with the given filename.
void import (QString url, ImportDuplicatesMode idm)
 Import the RDF document found at the given URL into the current store (in addition to its existing contents).

Static Public Member Functions

static BasicStoreload (QString url)
 Construct a new BasicStore from the RDF document at the given URL.


Detailed Description

In-memory RDF data store implementing the Store interface, providing add, remove, matching and query operations for RDF triples and SPARQL, as well as export and import.

BasicStore uses the Redland librdf datastore internally.

All operations are thread safe.

Definition at line 52 of file BasicStore.h.


Member Enumeration Documentation

ImportDuplicatesMode determines the outcome when an import operation encounters a triple in the imported data set that already exists in the store.

ImportIgnoreDuplicates: Any duplicate of a triple that is already in the store is discarded without comment.

ImportFailOnDuplicates: Import will fail with an RDFDuplicateImportException if any duplicate of a triple already in the store is found, and nothing will be imported.

ImportPermitDuplicates: No tests for duplicate triples will be carried out, and the behaviour when duplicates are imported will depend on the underlying store implementation (which may merge them or store them as separate duplicate triples). This is usually inadvisable: besides its unpredictability, this class does not generally handle duplicate triples well in other contexts.

Enumerator:
ImportIgnoreDuplicates 
ImportFailOnDuplicates 
ImportPermitDuplicates 

Definition at line 139 of file BasicStore.h.


Constructor & Destructor Documentation

Dataquay::BasicStore::BasicStore (  ) 

Definition at line 712 of file BasicStore.cpp.

Referenced by load().

Dataquay::BasicStore::~BasicStore (  ) 

Definition at line 717 of file BasicStore.cpp.


Member Function Documentation

void Dataquay::BasicStore::setBaseUri ( QString  uri  ) 

Set the base URI for the store.

This is used to expand the empty URI prefix when adding and querying triples, and is also used as the document base URI when exporting.

The default base URI is "#" (resolve local URIs relative to this document).

Definition at line 723 of file BasicStore.cpp.

QString Dataquay::BasicStore::getBaseUri (  )  const

Retrieve the base URI for the store.

Definition at line 729 of file BasicStore.cpp.

void Dataquay::BasicStore::clear (  ) 

Empty the store (including prefixes as well as triples).

Definition at line 735 of file BasicStore.cpp.

void Dataquay::BasicStore::addPrefix ( QString  prefix,
QString  uri 
)

Add a prefix/uri pair (an XML namespace, except that this class doesn't directly deal in XML) for use in subsequent operations.

Example: addPrefix("dc", "http://purl.org/dc/elements/1.1/") to add a prefix for the Dublin Core namespace.

The store always knows about the XSD and RDF namespaces.

Note that the base URI is always available as the empty prefix. For example, the URI ":blather" will be expanded to the base URI plus "blather".

Definition at line 777 of file BasicStore.cpp.

bool Dataquay::BasicStore::add ( Triple  t  )  [virtual]

Add a triple to the store.

Prefix expansion is performed on URI nodes in the triple. Return false if the triple was already in the store. (Although Redland permits duplicate triples in a store, Dataquay doesn't.) Throw RDFException if the triple can not be added for some other reason.

Implements Dataquay::Store.

Definition at line 741 of file BasicStore.cpp.

bool Dataquay::BasicStore::remove ( Triple  t  )  [virtual]

Remove a triple from the store.

Prefix expansion is performed on URI nodes in the triple. If some nodes in the triple are Nothing nodes, remove all matching triples. Return false if no matching triple was found in the store. Throw RDFException if removal failed for some other reason.

Implements Dataquay::Store.

Definition at line 747 of file BasicStore.cpp.

void Dataquay::BasicStore::change ( ChangeSet  changes  )  [virtual]

Atomically apply the sequence of add/remove changes described in the given ChangeSet.

Throw RDFException if any operation fails for any reason (including duplication etc).

Implements Dataquay::Store.

Definition at line 753 of file BasicStore.cpp.

void Dataquay::BasicStore::revert ( ChangeSet  changes  )  [virtual]

Atomically apply the sequence of add/remove changes described in the given ChangeSet, in reverse (ie removing adds and adding removes, in reverse order).

Throw RDFException if any operation fails for any reason (including duplication etc).

Implements Dataquay::Store.

Definition at line 759 of file BasicStore.cpp.

bool Dataquay::BasicStore::contains ( Triple  t  )  const [virtual]

Return true if the store contains the given triple, false otherwise.

Prefix expansion is performed on URI nodes in the triple. Throw RDFException if the triple is not complete or if the test failed for any other reason.

Implements Dataquay::Store.

Definition at line 765 of file BasicStore.cpp.

Triples Dataquay::BasicStore::match ( Triple  t  )  const [virtual]

Return all triples matching the given wildcard triple.

A node of type Nothing in any part of the triple matches any node in the data store. Prefix expansion is performed on URI nodes in the triple. Return an empty list if there are no matches; may throw RDFException if matching fails in some other way.

Implements Dataquay::Store.

Definition at line 771 of file BasicStore.cpp.

ResultSet Dataquay::BasicStore::query ( QString  sparql  )  const [virtual]

Run a SPARQL query against the store and return its results.

Any prefixes added previously using addQueryPrefix will be available in this query without needing to be declared in the SPARQL given here (equivalent to writing "PREFIX prefix: <uri>" for each prefix,uri pair set with addPrefix).

May throw RDFException.

Note that the RDF store must have an absolute base URI (rather than the default "#") in order to perform queries, as relative URIs in the query will be interpreted relative to the query base rather than the store and without a proper base URI there is no way to override that internally.

Implements Dataquay::Store.

Definition at line 783 of file BasicStore.cpp.

Triple Dataquay::BasicStore::matchFirst ( Triple  t  )  const [virtual]

Return the first triple to match the given wildcard triple.

A node of type Nothing in any part of the triple matches any node in the data store. Prefix expansion is performed on URI nodes in the triple. Return an empty triple (three Nothing nodes) if there are no matches. May throw RDFException.

Implements Dataquay::Store.

Definition at line 789 of file BasicStore.cpp.

Node Dataquay::BasicStore::queryFirst ( QString  sparql,
QString  bindingName 
) const [virtual]

Run a SPARQL query against the store and return the node of the first result for the given query binding.

This is a shorthand for use with queries that are only expected to have one result. May throw RDFException.

Implements Dataquay::Store.

Definition at line 795 of file BasicStore.cpp.

QUrl Dataquay::BasicStore::getUniqueUri ( QString  prefix  )  const [virtual]

Get a new URI, starting with the given prefix, that does not currently exist within this store.

The URI will be prefix expanded.

Implements Dataquay::Store.

Definition at line 801 of file BasicStore.cpp.

QUrl Dataquay::BasicStore::expand ( QString  uri  )  const [virtual]

Expand the given URI (which may use local namespaces) and prefix-expand it, returning the result as a QUrl.

(The QUrl class is not suitable for storing URIs that use namespaces, particularly local ones.)

Implements Dataquay::Store.

Definition at line 807 of file BasicStore.cpp.

void Dataquay::BasicStore::save ( QString  filename  )  const

Export the store to an RDF/TTL file with the given filename.

If the file already exists, it will if possible be overwritten. May throw RDFException, FileOperationFailed, FailedToOpenFile, etc.

Definition at line 813 of file BasicStore.cpp.

void Dataquay::BasicStore::import ( QString  url,
ImportDuplicatesMode  idm 
)

Import the RDF document found at the given URL into the current store (in addition to its existing contents).

Its behaviour when a triple is encountered that already exists in the store is controlled by the ImportDuplicatesMode.

May throw RDFException.

Note that the URL must be a URL, not just a filename (i.e. local files need the file: prefix).

Definition at line 819 of file BasicStore.cpp.

Referenced by load().

BasicStore * Dataquay::BasicStore::load ( QString  url  )  [static]

Construct a new BasicStore from the RDF document at the given URL.

May throw RDFException.

Note that the URL must be a URL, not just a filename (i.e. local files need the file: prefix).

Definition at line 825 of file BasicStore.cpp.

References BasicStore(), import(), and ImportIgnoreDuplicates.


The documentation for this class was generated from the following files:

Generated on Thu Sep 24 23:19:48 2009 for Dataquay by  doxygen 1.5.7.1