annotate rdf/SimpleSPARQLQuery.h @ 492:23945cdd7161

* Update RDF query stuff again so as to set up a temporary datastore each time we want to query over an rdf file, instead of using rasqal against the file. Seems the only way to avoid threading and storage management issues when trying to load from a single-source file and perform queries against our main datastore at the same time. Maybe.
author Chris Cannam
date Mon, 24 Nov 2008 16:26:11 +0000
parents 82ab61fa9223
children a03aafaacb5a
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@439 23 class ProgressReporter;
Chris@439 24
Chris@439 25 class SimpleSPARQLQuery
Chris@439 26 {
Chris@439 27 public:
Chris@439 28 enum ValueType { NoValue, URIValue, LiteralValue, BlankValue };
Chris@439 29
Chris@439 30 struct Value {
Chris@439 31 Value() : type(NoValue), value() { }
Chris@439 32 Value(ValueType t, QString v) : type(t), value(v) { }
Chris@439 33 ValueType type;
Chris@439 34 QString value;
Chris@439 35 };
Chris@439 36
Chris@439 37 typedef std::map<QString, Value> KeyValueMap;
Chris@439 38 typedef std::vector<KeyValueMap> ResultList;
Chris@439 39
Chris@492 40 /**
Chris@492 41 * QueryType specifies the context in which the query will be
Chris@492 42 * evaluated. SimpleSPARQLQuery maintains a general global data
Chris@492 43 * model, into which data can be loaded using addSourceToModel(),
Chris@492 44 * as well as permitting one-time queries directly on data sources
Chris@492 45 * identified by URL.
Chris@492 46 *
Chris@492 47 * The query type QueryFromModel indicates a query to be evaluated
Chris@492 48 * over the general global model; the query type
Chris@492 49 * QueryFromSingleSource indicates that the query should be
Chris@492 50 * evaluated in the context of a model generated solely by parsing
Chris@492 51 * the FROM url found in the query.
Chris@492 52 *
Chris@492 53 * Even in QueryFromSingleSource mode, the parsed data remains in
Chris@492 54 * memory and will be reused in subsequent queries with the same
Chris@492 55 * mode and FROM url. To release data loaded in this way once all
Chris@492 56 * queries across it are complete, pass the said FROM url to
Chris@492 57 * closeSingleSource().
Chris@492 58 */
Chris@489 59 enum QueryType {
Chris@489 60 QueryFromModel,
Chris@489 61 QueryFromSingleSource
Chris@489 62 };
Chris@489 63
Chris@492 64 /**
Chris@492 65 * Construct a query of the given type (indicating the data model
Chris@492 66 * context for the query) using the given SPARQL query content.
Chris@492 67 */
Chris@489 68 SimpleSPARQLQuery(QueryType type, QString query);
Chris@439 69 ~SimpleSPARQLQuery();
Chris@439 70
Chris@492 71 /**
Chris@492 72 * Add the given URI to the general global model used for
Chris@492 73 * QueryFromModel queries.
Chris@492 74 */
Chris@489 75 static bool addSourceToModel(QString sourceUri);
Chris@489 76
Chris@492 77 /**
Chris@492 78 * Release any data that has been loaded from the given source as
Chris@492 79 * part of a QueryFromSingleSource query with this source in the
Chris@492 80 * FROM clause. Note this will not prevent any subsequent queries
Chris@492 81 * on the source from working -- it will just make them slower as
Chris@492 82 * the data will need to be re-parsed.
Chris@492 83 */
Chris@492 84 static void closeSingleSource(QString sourceUri);
Chris@492 85
Chris@439 86 void setProgressReporter(ProgressReporter *reporter);
Chris@439 87 bool wasCancelled() const;
Chris@439 88
Chris@439 89 ResultList execute();
Chris@439 90
Chris@439 91 bool isOK() const;
Chris@439 92 QString getErrorString() const;
Chris@439 93
Chris@492 94 /**
Chris@492 95 * Construct and execute a query, and return the first result
Chris@492 96 * value for the given binding.
Chris@492 97 */
Chris@489 98 static Value singleResultQuery(QueryType type,
Chris@480 99 QString query,
Chris@480 100 QString binding);
Chris@480 101
Chris@439 102 protected:
Chris@439 103 class Impl;
Chris@439 104 Impl *m_impl;
Chris@439 105 };
Chris@439 106
Chris@439 107 #endif