annotate rdf/SimpleSPARQLQuery.h @ 706:579b2da21e7a

Make FileSource capable of handling resource files. Without this, we failed to open the silent resource file used as a placeholder in templates and thus failed to replace it with the proper file after loading the template -- the consequence was that (although the right audio file ended up being shown as the main model) any derived models were not regenerated
author Chris Cannam
date Fri, 07 Oct 2011 17:04:09 +0100
parents b4a8d8221eaf
children 7eb389da7976
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@439 19 #include <QString>
Chris@439 20 #include <map>
Chris@439 21 #include <vector>
Chris@439 22
Chris@686 23 #include "base/Debug.h"
Chris@686 24
Chris@439 25 class ProgressReporter;
Chris@439 26
Chris@439 27 class SimpleSPARQLQuery
Chris@439 28 {
Chris@439 29 public:
Chris@439 30 enum ValueType { NoValue, URIValue, LiteralValue, BlankValue };
Chris@439 31
Chris@439 32 struct Value {
Chris@439 33 Value() : type(NoValue), value() { }
Chris@439 34 Value(ValueType t, QString v) : type(t), value(v) { }
Chris@439 35 ValueType type;
Chris@439 36 QString value;
Chris@439 37 };
Chris@439 38
Chris@439 39 typedef std::map<QString, Value> KeyValueMap;
Chris@439 40 typedef std::vector<KeyValueMap> ResultList;
Chris@439 41
Chris@492 42 /**
Chris@492 43 * QueryType specifies the context in which the query will be
Chris@492 44 * evaluated. SimpleSPARQLQuery maintains a general global data
Chris@492 45 * model, into which data can be loaded using addSourceToModel(),
Chris@492 46 * as well as permitting one-time queries directly on data sources
Chris@492 47 * identified by URL.
Chris@492 48 *
Chris@492 49 * The query type QueryFromModel indicates a query to be evaluated
Chris@492 50 * over the general global model; the query type
Chris@492 51 * QueryFromSingleSource indicates that the query should be
Chris@492 52 * evaluated in the context of a model generated solely by parsing
Chris@492 53 * the FROM url found in the query.
Chris@492 54 *
Chris@492 55 * Even in QueryFromSingleSource mode, the parsed data remains in
Chris@492 56 * memory and will be reused in subsequent queries with the same
Chris@492 57 * mode and FROM url. To release data loaded in this way once all
Chris@492 58 * queries across it are complete, pass the said FROM url to
Chris@492 59 * closeSingleSource().
Chris@492 60 */
Chris@489 61 enum QueryType {
Chris@489 62 QueryFromModel,
Chris@489 63 QueryFromSingleSource
Chris@489 64 };
Chris@489 65
Chris@492 66 /**
Chris@492 67 * Construct a query of the given type (indicating the data model
Chris@492 68 * context for the query) using the given SPARQL query content.
Chris@492 69 */
Chris@489 70 SimpleSPARQLQuery(QueryType type, QString query);
Chris@439 71 ~SimpleSPARQLQuery();
Chris@439 72
Chris@492 73 /**
Chris@492 74 * Add the given URI to the general global model used for
Chris@492 75 * QueryFromModel queries.
Chris@492 76 */
Chris@489 77 static bool addSourceToModel(QString sourceUri);
Chris@489 78
Chris@492 79 /**
Chris@492 80 * Release any data that has been loaded from the given source as
Chris@492 81 * part of a QueryFromSingleSource query with this source in the
Chris@492 82 * FROM clause. Note this will not prevent any subsequent queries
Chris@492 83 * on the source from working -- it will just make them slower as
Chris@492 84 * the data will need to be re-parsed.
Chris@492 85 */
Chris@492 86 static void closeSingleSource(QString sourceUri);
Chris@492 87
Chris@439 88 void setProgressReporter(ProgressReporter *reporter);
Chris@439 89 bool wasCancelled() const;
Chris@439 90
Chris@439 91 ResultList execute();
Chris@439 92
Chris@439 93 bool isOK() const;
Chris@439 94 QString getErrorString() const;
Chris@439 95
Chris@492 96 /**
Chris@492 97 * Construct and execute a query, and return the first result
Chris@492 98 * value for the given binding.
Chris@492 99 */
Chris@489 100 static Value singleResultQuery(QueryType type,
Chris@480 101 QString query,
Chris@480 102 QString binding);
Chris@480 103
Chris@439 104 protected:
Chris@439 105 class Impl;
Chris@439 106 Impl *m_impl;
Chris@589 107
Chris@589 108 private:
Chris@589 109 SimpleSPARQLQuery(const SimpleSPARQLQuery &); // not provided
Chris@589 110 SimpleSPARQLQuery &operator=(const SimpleSPARQLQuery &); // not provided
Chris@439 111 };
Chris@439 112
Chris@439 113 #endif