annotate rdf/SimpleSPARQLQuery.h @ 855:42bbc538d983 tonioni_multi_transform

Merge from tonioni branch
author Chris Cannam
date Wed, 04 Dec 2013 18:29:15 +0000
parents 7eb389da7976
children
rev   line source
Chris@439 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@439 2
Chris@439 3 /*
Chris@439 4 Sonic Visualiser
Chris@439 5 An audio file viewer and annotation editor.
Chris@439 6 Centre for Digital Music, Queen Mary, University of London.
Chris@439 7 This file copyright 2008 QMUL.
Chris@439 8
Chris@439 9 This program is free software; you can redistribute it and/or
Chris@439 10 modify it under the terms of the GNU General Public License as
Chris@439 11 published by the Free Software Foundation; either version 2 of the
Chris@439 12 License, or (at your option) any later version. See the file
Chris@439 13 COPYING included with this distribution for more information.
Chris@439 14 */
Chris@439 15
Chris@439 16 #ifndef _SIMPLE_SPARQL_QUERY_H_
Chris@439 17 #define _SIMPLE_SPARQL_QUERY_H_
Chris@439 18
Chris@724 19 #ifdef NOT_DEFINED
Chris@724 20
Chris@439 21 #include <QString>
Chris@439 22 #include <map>
Chris@439 23 #include <vector>
Chris@439 24
Chris@686 25 #include "base/Debug.h"
Chris@686 26
Chris@439 27 class ProgressReporter;
Chris@439 28
Chris@439 29 class SimpleSPARQLQuery
Chris@439 30 {
Chris@439 31 public:
Chris@439 32 enum ValueType { NoValue, URIValue, LiteralValue, BlankValue };
Chris@439 33
Chris@439 34 struct Value {
Chris@439 35 Value() : type(NoValue), value() { }
Chris@439 36 Value(ValueType t, QString v) : type(t), value(v) { }
Chris@439 37 ValueType type;
Chris@439 38 QString value;
Chris@439 39 };
Chris@439 40
Chris@439 41 typedef std::map<QString, Value> KeyValueMap;
Chris@439 42 typedef std::vector<KeyValueMap> ResultList;
Chris@439 43
Chris@492 44 /**
Chris@492 45 * QueryType specifies the context in which the query will be
Chris@492 46 * evaluated. SimpleSPARQLQuery maintains a general global data
Chris@492 47 * model, into which data can be loaded using addSourceToModel(),
Chris@492 48 * as well as permitting one-time queries directly on data sources
Chris@492 49 * identified by URL.
Chris@492 50 *
Chris@492 51 * The query type QueryFromModel indicates a query to be evaluated
Chris@492 52 * over the general global model; the query type
Chris@492 53 * QueryFromSingleSource indicates that the query should be
Chris@492 54 * evaluated in the context of a model generated solely by parsing
Chris@492 55 * the FROM url found in the query.
Chris@492 56 *
Chris@492 57 * Even in QueryFromSingleSource mode, the parsed data remains in
Chris@492 58 * memory and will be reused in subsequent queries with the same
Chris@492 59 * mode and FROM url. To release data loaded in this way once all
Chris@492 60 * queries across it are complete, pass the said FROM url to
Chris@492 61 * closeSingleSource().
Chris@492 62 */
Chris@489 63 enum QueryType {
Chris@489 64 QueryFromModel,
Chris@489 65 QueryFromSingleSource
Chris@489 66 };
Chris@489 67
Chris@492 68 /**
Chris@492 69 * Construct a query of the given type (indicating the data model
Chris@492 70 * context for the query) using the given SPARQL query content.
Chris@492 71 */
Chris@489 72 SimpleSPARQLQuery(QueryType type, QString query);
Chris@439 73 ~SimpleSPARQLQuery();
Chris@439 74
Chris@492 75 /**
Chris@492 76 * Add the given URI to the general global model used for
Chris@492 77 * QueryFromModel queries.
Chris@492 78 */
Chris@489 79 static bool addSourceToModel(QString sourceUri);
Chris@489 80
Chris@492 81 /**
Chris@492 82 * Release any data that has been loaded from the given source as
Chris@492 83 * part of a QueryFromSingleSource query with this source in the
Chris@492 84 * FROM clause. Note this will not prevent any subsequent queries
Chris@492 85 * on the source from working -- it will just make them slower as
Chris@492 86 * the data will need to be re-parsed.
Chris@492 87 */
Chris@492 88 static void closeSingleSource(QString sourceUri);
Chris@492 89
Chris@439 90 void setProgressReporter(ProgressReporter *reporter);
Chris@439 91 bool wasCancelled() const;
Chris@439 92
Chris@439 93 ResultList execute();
Chris@439 94
Chris@439 95 bool isOK() const;
Chris@439 96 QString getErrorString() const;
Chris@439 97
Chris@492 98 /**
Chris@492 99 * Construct and execute a query, and return the first result
Chris@492 100 * value for the given binding.
Chris@492 101 */
Chris@489 102 static Value singleResultQuery(QueryType type,
Chris@480 103 QString query,
Chris@480 104 QString binding);
Chris@480 105
Chris@439 106 protected:
Chris@439 107 class Impl;
Chris@439 108 Impl *m_impl;
Chris@589 109
Chris@589 110 private:
Chris@589 111 SimpleSPARQLQuery(const SimpleSPARQLQuery &); // not provided
Chris@589 112 SimpleSPARQLQuery &operator=(const SimpleSPARQLQuery &); // not provided
Chris@439 113 };
Chris@439 114
Chris@439 115 #endif
Chris@724 116
Chris@724 117 #endif