-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
120 lines (105 loc) · 4.44 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
***************************************************************************
* Copyright (C) 2011 by Phaneendra Hegde <phaneendra.hegde@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************
*/
//Qt Includes
#include <QtCore/QCoreApplication>
#include <QDebug>
#include <QFile>
#include <QIODevice>
#include <QTextStream>
#include <QStringList>
#include <QHash>
#include <QHashIterator>
#include <QListIterator>
//Nepomuk Includes
#include <Nepomuk/File>
#include <Nepomuk/Resource>
#include <Nepomuk/Vocabulary/PIMO>
#include <Soprano/Vocabulary/NAO>
#include <Nepomuk/Vocabulary/NFO>
#include <Nepomuk/Vocabulary/NIE>
#include <Nepomuk/Query/Term>
#include <Nepomuk/Query/ResourceTypeTerm>
#include <Nepomuk/Query/ComparisonTerm>
#include <Nepomuk/Query/LiteralTerm>
#include <Nepomuk/Query/QueryServiceClient>
#include <Nepomuk/Query/Result>
#include <Nepomuk/Query/QueryParser>
#include <Nepomuk/Query/AndTerm>
#include <Nepomuk/Query/OrTerm>
#include <Nepomuk/Variant>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QFile fileSW("/home/pnh/kde/src/hastopic/stopwords.txt");
if (!fileSW.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug()<<"Can't open";
}
QStringList list,stopwords;
QTextStream sw(&fileSW);
while(!sw.atEnd()) {
QString line = sw.readLine();
stopwords += line.split(" ");
}
Nepomuk::Query::Query query;
query.setLimit(10);
Nepomuk::Query::Term term;
term = Nepomuk::Query::ResourceTypeTerm(Nepomuk::Vocabulary::NFO::TextDocument()) ||
Nepomuk::Query::ComparisonTerm(Nepomuk::Vocabulary::NIE::mimeType(),
Nepomuk::Query::LiteralTerm(QLatin1String("text/plain")));
query.setTerm(term);
QList<Nepomuk::Query::Result>results = Nepomuk::Query::QueryServiceClient::syncQuery( query );
Q_FOREACH( const Nepomuk::Query::Result& result, results ) {
if(result.resource().topics().length() <=3 ) {
Nepomuk::Variant v = result.resource().property(Nepomuk::Vocabulary::NIE::plainTextContent());
QString line = v.toString();
list = line.split(" ");
QHash<QString,int>hash;
foreach(QString str,list) {
if(!stopwords.contains(str)) {
if(hash.value(str))
hash[str] = hash[str]+1;
else
hash[str] = 1;
}
}
// QHashIterator<QString, int> l(hash);
// while (l.hasNext()) {
// l.next();
// }
QList<int> vals = hash.values();
QSet<int>set = vals.toSet();
vals= set.toList();
qSort(vals);
QStringList string;
while(string.length()<5) {
string = string+hash.keys(vals.last());
vals.removeLast();
}
qDebug()<<string << "File name:->>>>" << result.resource().genericLabel();
for(int i=0;i<3;i++) {
Nepomuk::Resource topic(string[i]);
topic.addType(Nepomuk::Vocabulary::PIMO::Topic());
result.resource().addTopic(topic);
}
}
}
return a.exec();
}