22 #include <QtCore/QCoreApplication>
23 #include <QtCore/QHash>
24 #include <QtCore/QUrl>
25 #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>
43 int main(
int argc,
char *argv[] )
45 KAboutData aboutData(
"nepomukshow",
47 ki18n(
"Nepomuk Show"),
49 ki18n(
"The Nepomuk Resource Viewer - A debugging tool"),
50 KAboutData::License_GPL,
51 ki18n(
"(c) 2012, Vishesh Handa"),
53 "http://nepomuk.kde.org" );
54 aboutData.addAuthor(ki18n(
"Vishesh Handa"),ki18n(
"Maintainer"),
"me@vhanda.in");
55 aboutData.addAuthor(ki18n(
"Sebastian Trüg"),ki18n(
"Developer"),
"trueg@kde.org");
56 aboutData.setProgramIconName(
"nepomuk" );
58 KCmdLineArgs::init( argc, argv, &aboutData );
60 KCmdLineOptions options;
61 options.add(
"+resource", ki18n(
"The resource URI, a file URL, or a file path."));
62 options.add(
"depth <depth>", ki18n(
"The number of sub resources to list"),
"0");
63 options.add(
"graphs", ki18n(
"Print information about the graphs"));
64 options.add(
"inference", ki18n(
"Uses Inference to print additional properties"));
65 options.add(
"plainText", ki18n(
"Print the plain text content of the file"));
66 KCmdLineArgs::addCmdLineOptions( options );
68 KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
70 QCoreApplication app( argc, argv );
71 KComponentData comp( aboutData );
73 if( args->count() == 0 )
74 KCmdLineArgs::usage();
76 QTextStream err( stdout );
81 const QUrl url = args->url( 0 );
84 err <<
"Resource does not exist: " << args->url( 0 ).url() << endl;
94 if( url.scheme() != QLatin1String(
"nepomuk") ) {
95 QString query = QString::fromLatin1(
"select ?r where { ?r nie:url %1 . }")
96 .arg( Soprano::Node::resourceToN3( url ) );
97 Soprano::QueryResultIterator it = model->executeQuery( query, Soprano::Query::QueryLanguageSparql );
99 uriList << it[0].uri();
103 uriList << res.
uri();
109 int depth = args->getOption(
"depth").toInt();
110 int oldSize = uriList.size();
111 for(
int i=0; i<depth; i++ ) {
113 foreach(
const QUrl& uri, uriList) {
114 QString query = QString::fromLatin1(
"select ?o where { %1 ?p ?o. FILTER(REGEX(STR(?o), '^nepomuk')). }")
115 .arg( Soprano::Node::resourceToN3(uri) );
116 Soprano::QueryResultIterator it = model->executeQuery( query, Soprano::Query::QueryLanguageSparql );
118 newUris << it[0].uri();
120 uriList.unite( newUris );
122 if( uriList.size() == oldSize )
125 oldSize = uriList.size();
131 QTextStream stream( stdout );
134 if( args->isSet(
"graphs") )
136 if( args->isSet(
"inference") )
138 if( args->isSet(
"plainText") )
141 foreach(
const QUrl& resUri, uriList ) {
142 printer.
print( stream, resUri );
void setGraphs(bool status)
static ResourceManager * instance()
void print(QTextStream &stream, const QUrl &uri)
int main(int argc, char *argv[])
void setInference(bool status)
Resource is the central object type in Nepomuk.
QUrl uri() const
The URI of the resource, uniquely identifying it.
void setPlainText(bool status)
Soprano::Model * mainModel()
Retrieve the main data storage model.