• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

Nepomuk-Core

  • sources
  • kde-4.12
  • kdelibs
  • nepomuk-core
  • tools
  • nepomukcmd
tools/nepomukcmd/main.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013 Vishesh Handa <me@vhanda.in>
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public License as
6  published by the Free Software Foundation; either version 2 of
7  the License or (at your option) version 3 or any later version
8  accepted by the membership of KDE e.V. (or its successor approved
9  by the membership of KDE e.V.), which shall act as a proxy
10  defined in Section 14 of version 3 of the license.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include <QtCore/QCoreApplication>
22 #include <QtCore/QHash>
23 #include <QtCore/QUrl>
24 #include <QtCore/QSet>
25 #include <QTime>
26 
27 #include <kcmdlineargs.h>
28 #include <kaboutdata.h>
29 #include <KDE/KLocale>
30 #include <KComponentData>
31 #include <KUrl>
32 #include <KDebug>
33 
34 #include <Soprano/Model>
35 #include <Soprano/QueryResultIterator>
36 
37 #include "resourcemanager.h"
38 
39 int main( int argc, char *argv[] )
40 {
41  KAboutData aboutData( "nepomukcmd",
42  "nepomukcmd",
43  ki18n("Nepomuk Cmd"),
44  "0.1",
45  ki18n("Nepomuk Command - A debugging tool"),
46  KAboutData::License_GPL,
47  ki18n("(c) 2013, Vishesh Handa"),
48  KLocalizedString(),
49  "http://nepomuk.kde.org" );
50  aboutData.addAuthor(ki18n("Vishesh Handa"),ki18n("Maintainer"), "me@vhanda.in");
51  aboutData.setProgramIconName( "nepomuk" );
52 
53  KCmdLineArgs::init( argc, argv, &aboutData );
54 
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 );
59 
60  KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
61 
62  QCoreApplication app( argc, argv );
63  KComponentData comp( aboutData );
64 
65  if( args->count() == 0 )
66  KCmdLineArgs::usage();
67 
68  QTextStream err( stdout );
69 
70  const QString command = args->arg( 0 ).toLower();
71  if ( command != QLatin1String("query") ) {
72  err << "Command " << command << " is not supported";
73  return 1;
74  }
75 
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;
80 
81  Nepomuk2::ResourceManager* rm = Nepomuk2::ResourceManager::instance();
82  if( !rm->initialized() ) {
83  err << "Could not connect to Nepomuk";
84  return 1;
85  }
86 
87  Soprano::Model* model = rm->mainModel();
88  QTextStream stream( stdout );
89 
90  QTime timer;
91  timer.start();
92  Soprano::QueryResultIterator it = model->executeQuery( query, lang );
93  int queryTime = timer.elapsed();
94 
95  if( it.isBool() ) {
96  stream << (it.boolValue() ? "true" : "false") << endl;
97  }
98  else {
99  int resultCount = 0;
100  while( it.next() ) {
101  QStringList bindValues;
102  foreach(const QString& binding, it.bindingNames()) {
103  bindValues << QString::fromLatin1("%1 -> %2").arg( binding, it[binding].toN3() );
104  }
105 
106  stream << bindValues.join("; ") << endl;
107  resultCount++;
108  }
109  stream << "Total Results: " << resultCount << endl;
110  }
111  int totalTime = timer.elapsed();
112 
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;
115 
116  return 0;
117 }
main
int main(int argc, char *argv[])
Definition: tools/nepomukcmd/main.cpp:39
Nepomuk2::ResourceManager::initialized
bool initialized() const
Definition: resourcemanager.cpp:306
Nepomuk2::ResourceManager::instance
static ResourceManager * instance()
Definition: resourcemanager.cpp:270
resourcemanager.h
Nepomuk2::ResourceManager
The ResourceManager is the central Nepomuk configuration point.
Definition: resourcemanager.h:55
Nepomuk2::ResourceManager::mainModel
Soprano::Model * mainModel()
Retrieve the main data storage model.
Definition: resourcemanager.cpp:363
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Nepomuk-Core

Skip menu "Nepomuk-Core"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal