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