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