[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/base/nepomuk-kde/scribo/plugins/pimo
From: Sebastian Trueg <sebastian () trueg ! de>
Date: 2010-11-22 19:32:34
Message-ID: 20101122193234.60536AC8A0 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1199804 by trueg:
Added olena support and a global token tree
M +1 -0 CMakeLists.txt
AM nepomuktokentree.cpp [License: LGPL]
AM nepomuktokentree.h [License: LGPL]
M +12 -31 pimotextmatchplugin.cpp
M +3 -0 tokentree.cpp
M +1 -1 tokentree.h
--- trunk/playground/base/nepomuk-kde/scribo/plugins/pimo/CMakeLists.txt \
#1199803:1199804 @@ -12,6 +12,7 @@
tokentree.cpp
tokennode.cpp
tokendetector.cpp
+ nepomuktokentree.cpp
)
kde4_add_plugin(scribo_pimotextmatchplugin ${pimotextmatchplugin_SRCS})
--- trunk/playground/base/nepomuk-kde/scribo/plugins/pimo/pimotextmatchplugin.cpp \
#1199803:1199804 @@ -22,7 +22,7 @@
#include "pimo.h"
#include "textoccurrence.h"
#include "entity.h"
-#include "tokentree.h"
+#include "nepomuktokentree.h"
#include "tokendetector.h"
#include <Soprano/Model>
@@ -46,6 +46,8 @@
#include <QtCore/QThread>
+K_GLOBAL_STATIC(NepomukTokenTree, s_tokenTree)
+
class PimoTextMatchPlugin::WorkThread : public QThread
{
public:
@@ -56,15 +58,12 @@
void run();
private:
- void buildTokenTree();
QString m_text;
- TokenTree* m_tokenTree;
bool m_canceled;
};
PimoTextMatchPlugin::WorkThread::WorkThread( QObject* parent )
: QThread(parent),
- m_tokenTree(0),
m_canceled(false)
{
}
@@ -73,19 +72,25 @@
{
m_canceled = true;
wait();
- delete m_tokenTree;
}
void PimoTextMatchPlugin::WorkThread::start(const QString &text)
{
m_text = text;
+ s_tokenTree->disconnect(this);
+ if(s_tokenTree->isPopulationFinished()) {
+ kDebug() << "Population has already finished. We can start right away.";
QThread::start();
}
+ else {
+ connect(s_tokenTree, SIGNAL(finishedPopulation()),
+ this, SLOT(start()));
+ }
+}
void PimoTextMatchPlugin::WorkThread::run()
{
- buildTokenTree();
- TokenDetector* detector = new TokenDetector(m_tokenTree);
+ TokenDetector* detector = new TokenDetector(s_tokenTree);
connect(detector, SIGNAL(tokenFound(int,int,QVariant)),
parent(), SLOT(slotTokenFound(int,int,QVariant)),
Qt::QueuedConnection);
@@ -99,31 +104,7 @@
delete detector;
}
-void PimoTextMatchPlugin::WorkThread::buildTokenTree()
-{
- if(!m_tokenTree) {
- m_tokenTree = new TokenTree();
- // populatre tree with all resources that have a nao:prefLabel - urgh, this \
could be big!
- Nepomuk::Query::Query query(
- Nepomuk::Query::ComparisonTerm( \
Soprano::Vocabulary::NAO::prefLabel(), Nepomuk::Query::Term())
- );
- query.addRequestProperty(Nepomuk::Query::Query::RequestProperty(Soprano::Vocabulary::NAO::prefLabel(), \
false));
- kDebug() << query.toSparqlQuery();
-
- Soprano::QueryResultIterator it
- = Nepomuk::ResourceManager::instance()->mainModel()->executeQuery( \
query.toSparqlQuery(),
- \
Soprano::Query::QueryLanguageSparql );
- while ( !m_canceled && it.next() ) {
- const QUrl res( it[0].uri() );
- const QString label( it[1].toString() );
- m_tokenTree->add(label, QVariant::fromValue(res));
- }
- }
-}
-
-
-
PimoTextMatchPlugin::PimoTextMatchPlugin( QObject* parent, const QVariantList& )
: TextMatchPlugin( parent ),
m_workThread(0)
--- trunk/playground/base/nepomuk-kde/scribo/plugins/pimo/tokentree.cpp \
#1199803:1199804 @@ -26,6 +26,8 @@
#include <QtCore/QChar>
#include <QtCore/QList>
+#include <KDebug>
+
TokenTree::TokenTree()
: m_root(0)
{
@@ -38,6 +40,7 @@
void TokenTree::add(const QString &token, const QVariant &value)
{
+ kDebug() << token << value;
if(!m_root)
m_root = new TokenNode(QChar());
findNode(token, true)->setValue(value);
--- trunk/playground/base/nepomuk-kde/scribo/plugins/pimo/tokentree.h \
#1199803:1199804 @@ -31,7 +31,7 @@
{
public:
TokenTree();
- ~TokenTree();
+ virtual ~TokenTree();
void add(const QString& token, const QVariant& value);
TokenNode* findNode(const QString& token, bool create = false);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic