To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / utilities / widgettest / widgettest.cpp @ 53:bcea875d8d2f
History | View | Annotate | Download (2.57 KB)
| 1 |
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
|---|---|
| 2 |
|
| 3 |
#include <dataquay/Uri.h> |
| 4 |
|
| 5 |
#include "TypingSelectWidget.h" |
| 6 |
#include "TypeRegistrar.h" |
| 7 |
#include "Objects.h" |
| 8 |
#include "Matcher.h" |
| 9 |
|
| 10 |
#include <dataquay/BasicStore.h> |
| 11 |
#include <dataquay/RDFException.h> |
| 12 |
#include <dataquay/objectmapper/ObjectLoader.h> |
| 13 |
#include <dataquay/objectmapper/TypeMapping.h> |
| 14 |
|
| 15 |
#include <QApplication> |
| 16 |
|
| 17 |
#include <iostream> |
| 18 |
|
| 19 |
using namespace ClassicalData; |
| 20 |
using namespace Dataquay; |
| 21 |
using namespace std; |
| 22 |
|
| 23 |
/*
|
| 24 |
ostream &operator<<(ostream &target, const QString &str)
|
| 25 |
{
|
| 26 |
return target << str.toLocal8Bit().data();
|
| 27 |
}
|
| 28 |
|
| 29 |
ostream &operator<<(ostream &target, const QUrl &u)
|
| 30 |
{
|
| 31 |
return target << "<" << u.toString() << ">";
|
| 32 |
}
|
| 33 |
*/
|
| 34 |
|
| 35 |
void
|
| 36 |
usage(const char *name) |
| 37 |
{
|
| 38 |
int s = 0; |
| 39 |
for (int i = 0; name[i]; ++i) if (name[i] == '/') s = i + 1; |
| 40 |
name = name + s; |
| 41 |
cerr << "Usage:" << endl;
|
| 42 |
cerr << " " << name << " <input-rdf-file>" << endl; |
| 43 |
exit(2);
|
| 44 |
} |
| 45 |
|
| 46 |
bool
|
| 47 |
load(BasicStore *store, QString fileName) |
| 48 |
{
|
| 49 |
QUrl url = QUrl::fromLocalFile(fileName); |
| 50 |
|
| 51 |
cerr << "Importing from URL " << url << " ..."; |
| 52 |
try {
|
| 53 |
store->import(url, BasicStore::ImportPermitDuplicates); |
| 54 |
} catch (RDFException e) {
|
| 55 |
cerr << " retrying with explicit ntriples type...";
|
| 56 |
try {
|
| 57 |
store->import(url, BasicStore::ImportPermitDuplicates, "ntriples");
|
| 58 |
} catch (RDFException e) {
|
| 59 |
cerr << "failed" << endl;
|
| 60 |
cerr << "Import failed: " << e.what() << endl;
|
| 61 |
return false; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
cerr << " done" << endl;
|
| 66 |
return true; |
| 67 |
} |
| 68 |
|
| 69 |
int
|
| 70 |
main(int argc, char **argv) |
| 71 |
{
|
| 72 |
QApplication app(argc, argv); |
| 73 |
|
| 74 |
if (argc != 2) usage(argv[0]); |
| 75 |
QString inFileName = argv[1];
|
| 76 |
|
| 77 |
BasicStore *store = new BasicStore();
|
| 78 |
store->setBaseUri(Uri("http://dbtune.org/classical/resource/"));
|
| 79 |
ObjectLoader *loader = new ObjectLoader(store);
|
| 80 |
|
| 81 |
TypeMapping tm; |
| 82 |
|
| 83 |
TypeRegistrar::registerTypes(); |
| 84 |
TypeRegistrar::addMappings(store, &tm); |
| 85 |
|
| 86 |
loader->setTypeMapping(tm); |
| 87 |
|
| 88 |
if (!load(store, inFileName)) {
|
| 89 |
cerr << "Failed to load data source" << endl;
|
| 90 |
return 1; |
| 91 |
} |
| 92 |
|
| 93 |
cerr << "Imported RDF data, mapping to objects...";
|
| 94 |
QObjectList objects = loader->loadAll(); |
| 95 |
cerr << " done" << endl;
|
| 96 |
|
| 97 |
delete loader;
|
| 98 |
|
| 99 |
QList<Composer *> composers; |
| 100 |
foreach (QObject *o, objects) {
|
| 101 |
Composer *c = qobject_cast<Composer *>(o); |
| 102 |
if (c) composers.push_back(c);
|
| 103 |
} |
| 104 |
ComposerTypingThoroughMatcher matcher(composers); |
| 105 |
|
| 106 |
TypingSelectWidget *w = new TypingSelectWidget();
|
| 107 |
w->addMatcher(&matcher); |
| 108 |
|
| 109 |
w->show(); |
| 110 |
|
| 111 |
app.exec(); |
| 112 |
} |
| 113 |
|