21 #include <QtCore/QCoreApplication>
22 #include <QtCore/QHash>
23 #include <QtCore/QUrl>
24 #include <QtCore/QSet>
27 #include <kcmdlineargs.h>
28 #include <kaboutdata.h>
29 #include <KDE/KLocale>
30 #include <KComponentData>
34 #include <Soprano/Model>
35 #include <Soprano/QueryResultIterator>
39 int main(
int argc,
char *argv[] )
41 KAboutData aboutData(
"nepomukcmd",
45 ki18n(
"Nepomuk Command - A debugging tool"),
46 KAboutData::License_GPL,
47 ki18n(
"(c) 2013, Vishesh Handa"),
49 "http://nepomuk.kde.org" );
50 aboutData.addAuthor(ki18n(
"Vishesh Handa"),ki18n(
"Maintainer"),
"me@vhanda.in");
51 aboutData.setProgramIconName(
"nepomuk" );
53 KCmdLineArgs::init( argc, argv, &aboutData );
55 KCmdLineOptions options;
56 options.add(
"+command", ki18n(
"The command to use"));
57 options.add(
"inference", ki18n(
"Uses Inference to print additional properties"));
58 KCmdLineArgs::addCmdLineOptions( options );
60 KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
62 QCoreApplication app( argc, argv );
63 KComponentData comp( aboutData );
65 if( args->count() == 0 )
66 KCmdLineArgs::usage();
68 QTextStream err( stdout );
70 const QString command = args->arg( 0 ).toLower();
71 if ( command != QLatin1String(
"query") ) {
72 err <<
"Command " << command <<
" is not supported";
76 const QString query = args->arg( 1 );
77 Soprano::Query::QueryLanguage lang = Soprano::Query::QueryLanguageSparqlNoInference;
78 if ( args->isSet(
"inference") )
79 lang = Soprano::Query::QueryLanguageSparql;
83 err <<
"Could not connect to Nepomuk";
88 QTextStream stream( stdout );
92 Soprano::QueryResultIterator it = model->executeQuery( query, lang );
93 int queryTime = timer.elapsed();
96 stream << (it.boolValue() ?
"true" :
"false") << endl;
101 QStringList bindValues;
102 foreach(
const QString& binding, it.bindingNames()) {
103 bindValues << QString::fromLatin1(
"%1 -> %2").arg( binding, it[binding].toN3() );
106 stream << bindValues.join(
"; ") << endl;
109 stream <<
"Total Results: " << resultCount << endl;
111 int totalTime = timer.elapsed();
113 stream <<
"Execution Time: " << QTime().addMSecs( queryTime ).toString(
"hh:mm:ss.zz" ) << endl;
114 stream <<
"Total Time: " << QTime().addMSecs( totalTime ).toString(
"hh:mm:ss.zz" ) << endl;
int main(int argc, char *argv[])
static ResourceManager * instance()
The ResourceManager is the central Nepomuk configuration point.
Soprano::Model * mainModel()
Retrieve the main data storage model.