Dataquay 0.8
Store.h
Go to the documentation of this file.
1/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3/*
4 Dataquay
5
6 A C++/Qt library for simple RDF datastore management.
7 Copyright 2009-2012 Chris Cannam.
8
9 Permission is hereby granted, free of charge, to any person
10 obtaining a copy of this software and associated documentation
11 files (the "Software"), to deal in the Software without
12 restriction, including without limitation the rights to use, copy,
13 modify, merge, publish, distribute, sublicense, and/or sell copies
14 of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be
18 included in all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
24 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
28 Except as contained in this notice, the name of Chris Cannam
29 shall not be used in advertising or otherwise to promote the sale,
30 use or other dealings in this Software without prior written
31 authorization.
32*/
33
34#ifndef DATAQUAY_STORE_H
35#define DATAQUAY_STORE_H
36
37#include "Triple.h"
38
39#include <QList>
40#include <QHash>
41#include <QMap>
42#include <QPair>
43#include <QSet>
44
45namespace Dataquay
46{
47
49typedef QHash<QString, Node> Dictionary;
50
52typedef QList<Dictionary> ResultSet;
53
58
60typedef QPair<ChangeType, Triple> Change;
61
63typedef QList<Change> ChangeSet;
64
65
71class Store
72{
73public:
80 virtual bool add(Triple t) = 0;
81
88 virtual bool remove(Triple t) = 0;
89
95 virtual void change(ChangeSet changes) = 0;
96
103 virtual void revert(ChangeSet changes) = 0;
104
110 virtual bool contains(Triple t) const = 0;
111
118 virtual Triples match(Triple t) const = 0;
119
135 virtual ResultSet query(QString sparql) const = 0;
136
146 virtual Node complete(Triple t) const = 0;
147
155 virtual Triple matchOnce(Triple t) const = 0;
156
163 virtual Node queryOnce(QString sparql, QString bindingName) const = 0;
164
170 virtual Uri getUniqueUri(QString prefix) const = 0;
171
177 virtual Node addBlankNode() = 0;
178
189 virtual Uri expand(QString uri) const = 0;
190
200 virtual void save(QString filename) const = 0;
201
227
244 virtual void import(QUrl url, ImportDuplicatesMode idm, QString format = "") = 0;
245
259 virtual void importString(QString encodedRdf, Uri baseUri,
260 ImportDuplicatesMode idm, QString format = "") = 0;
261
289
290 typedef QSet<Feature> Features;
291
296 virtual Features getSupportedFeatures() const = 0;
297
298protected:
299 virtual ~Store() { }
300};
301
302}
303
304QDataStream &operator<<(QDataStream &out, const Dataquay::ChangeType &);
305QDataStream &operator>>(QDataStream &in, Dataquay::ChangeType &);
306
307#endif
308
QDataStream & operator>>(QDataStream &in, Dataquay::ChangeType &)
QDataStream & operator<<(QDataStream &out, const Dataquay::ChangeType &)
Node represents a single RDF node, with conversions to and from variant types.
Definition Node.h:65
Store is an abstract interface for Dataquay RDF data stores.
Definition Store.h:72
virtual Node complete(Triple t) const =0
Given a triple in which any two nodes are specified and the other is a wildcard node of type Nothing,...
Feature
Feature defines the set of optional features a Store implementation may support.
Definition Store.h:284
@ RemoteImportFeature
Definition Store.h:287
virtual Triple matchOnce(Triple t) const =0
Return a triple from the store that matches the given wildcard triple, or the empty triple if none ma...
virtual Uri getUniqueUri(QString prefix) const =0
Get a new URI, starting with the given prefix (e.g.
virtual Uri expand(QString uri) const =0
Expand the given URI (which may use local namespaces) and prefix-expand it, returning the result as a...
virtual ResultSet query(QString sparql) const =0
Run a SPARQL query against the store and return its results.
virtual bool contains(Triple t) const =0
Return true if the store contains the given triple, false otherwise.
virtual void save(QString filename) const =0
Export the store to an RDF/TTL file with the given filename.
virtual bool add(Triple t)=0
Add a triple to the store.
QSet< Feature > Features
Definition Store.h:290
virtual Triples match(Triple t) const =0
Return all triples matching the given wildcard triple.
virtual void revert(ChangeSet changes)=0
Atomically apply the sequence of add/remove changes described in the given ChangeSet,...
virtual ~Store()
Definition Store.h:299
virtual Node addBlankNode()=0
Create and return a new blank node.
virtual bool remove(Triple t)=0
Remove a triple from the store.
virtual Features getSupportedFeatures() const =0
Retrieve the set of optional features supported by this Store implementation.
ImportDuplicatesMode
ImportDuplicatesMode determines the outcome when an import operation encounters a triple in the impor...
Definition Store.h:222
@ ImportFailOnDuplicates
Definition Store.h:224
@ ImportIgnoreDuplicates
Definition Store.h:223
@ ImportPermitDuplicates
Definition Store.h:225
virtual void change(ChangeSet changes)=0
Atomically apply the sequence of add/remove changes described in the given ChangeSet.
virtual void importString(QString encodedRdf, Uri baseUri, ImportDuplicatesMode idm, QString format="")=0
Import the RDF document encoded in the given string into the current store (in addition to its existi...
virtual Node queryOnce(QString sparql, QString bindingName) const =0
Run a SPARQL query against the store and return the node of the first result for the given query bind...
Triple represents an RDF statement made up of three Node objects.
Definition Triple.h:48
A list of RDF triples.
Definition Triple.h:111
Uri represents a single URI.
Definition Uri.h:77
QPair< ChangeType, Triple > Change
An add or remove operation specified by add/remove token and triple.
Definition Store.h:60
QList< Change > ChangeSet
A sequence of add/remove operations such as may be enacted by a transaction.
Definition Store.h:63
QList< Dictionary > ResultSet
A list of Dictionary types, used to contain a sequence of query results.
Definition Store.h:52
QHash< QString, Node > Dictionary
A mapping from key to node, used to list results for a set of result keys.
Definition Store.h:49
ChangeType
Definition Store.h:54
@ AddTriple
Definition Store.h:55
@ RemoveTriple
Definition Store.h:56