Commit fa12dd25 authored by artemserebriyskiy's avatar artemserebriyskiy Committed by artemserebriyskiy
Browse files

Merge branch 'master2' into master2-svn

git-svn-id: svn+ssh://svn.kde.org/home/kde/trunk/playground/base/nepomuk-kde/webextractor@1164003 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
parent 275e42a0
Top-level CMakeLists will not work
First compile libwebextractor
Then compile gui
then - runtime
#include "changelogwidget.h"
#include "ui_changeLogForm.h"
#include <nepomuk/changelog.h>
#include <nepomuk/changelogrecord.h>
namespace NS = Nepomuk::Sync;
class ChangeLogWidget::Private
{
public:
Ui_changeLogForm * ui;
NS::ChangeLog log;
Ui_changeLogForm * ui;
NS::ChangeLog log;
};
ChangeLogWidget::ChangeLogWidget(QWidget * parent):
QWidget(parent),
d( new Private() )
d(new Private())
{
d->ui = new Ui_changeLogForm();
d->ui->setupUi(this);
}
ChangeLogWidget::ChangeLogWidget( const NS::ChangeLog & log,QWidget * parent):
ChangeLogWidget::ChangeLogWidget(const NS::ChangeLog & log, QWidget * parent):
QWidget(parent),
d( new Private() )
d(new Private())
{
d->ui = new Ui_changeLogForm();
d->ui->setupUi(this);
......@@ -33,19 +34,62 @@ ChangeLogWidget::~ChangeLogWidget()
delete d->ui;
delete d;
}
void ChangeLogWidget::setLog( const NS::ChangeLog & log)
void ChangeLogWidget::setLog(const NS::ChangeLog & log)
{
// Fill form
QString text;
QTextStream stream(&text);
stream << log;
d->ui->changeLogBrowser->setPlainText(text);
foreach(const NS::ChangeLogRecord & rec, log.toList()) {
Soprano::Node subject = rec.subject();
if(subject.isResource()) {
stream << "<a HREF=\"" << subject.uri() << "\">" <<
subject.uri().host() <<
subject.uri().path() <<
"</a>";
} else {
stream << subject.literal().toString();
}
stream << " ";
Soprano::Node predicate = rec.predicate().uri();
if(predicate.isResource()) {
stream << "<a HREF=\"" << predicate.uri() << "\">";
if(predicate.uri().fragment().isEmpty())
stream << "Unknown property";
else
stream << predicate.uri().fragment();
stream << "</a>";
}
stream << " ";
Soprano::Node object = rec.object();
if(object.isResource()) {
stream << "<a HREF=\"" << object.uri() << "\">" <<
object.uri().host() <<
object.uri().path() <<
"</a>";
} else {
stream << object.literal().toString();
}
stream << "<br><hr>";
}
//stream << log;
d->ui->changeLogBrowser->setHtml(text);
d->log = log;
}
void ChangeLogWidget::clear()
{
setLog( NS::ChangeLog() );
setLog(NS::ChangeLog());
}
......@@ -8,9 +8,9 @@ namespace NW = Nepomuk::WebExtractor;
class DecisionWidget::Private
{
public:
Ui_DecisionForm * ui;
NW::Decision decision;
ChangeLogWidget * logWidget;
Ui_DecisionForm * ui;
NW::Decision decision;
ChangeLogWidget * logWidget;
};
void DecisionWidget::setupUi()
......@@ -24,14 +24,14 @@ void DecisionWidget::setupUi()
DecisionWidget::DecisionWidget(QWidget * parent):
QWidget(parent),
d( new Private() )
d(new Private())
{
setupUi();
}
DecisionWidget::DecisionWidget( const NW::Decision & decision,QWidget * parent):
DecisionWidget::DecisionWidget(const NW::Decision & decision, QWidget * parent):
QWidget(parent),
d( new Private() )
d(new Private())
{
setupUi();
setDecision(decision);
......@@ -43,12 +43,18 @@ DecisionWidget::~DecisionWidget()
delete d;
}
void DecisionWidget::setDecision( const NW::Decision & decision)
void DecisionWidget::setDecision(const NW::Decision & decision)
{
d->decision = decision;
d->logWidget->setLog(decision.log());
d->ui->descriptionBrowser->setPlainText(decision.description());
}
Nepomuk::WebExtractor::Decision DecisionWidget::decision() const
{
return d->decision;
}
void DecisionWidget::clear()
{
d->logWidget->clear();
......
......@@ -26,18 +26,19 @@
class WEBEXTRACTORUI_EXPORT DecisionWidget : public QWidget
{
Q_OBJECT;
Q_OBJECT;
public:
DecisionWidget(QWidget * parent = 0);
DecisionWidget( const Nepomuk::WebExtractor::Decision & dec, QWidget * parent = 0);
~DecisionWidget();
void setDecision( const Nepomuk::WebExtractor::Decision & dec);
DecisionWidget(const Nepomuk::WebExtractor::Decision & dec, QWidget * parent = 0);
~DecisionWidget();
void setDecision(const Nepomuk::WebExtractor::Decision & dec);
Nepomuk::WebExtractor::Decision decision() const;
public Q_SLOTS:
void clear();
void clear();
private:
class Private;
Private * d;
void setupUi();
class Private;
Private * d;
void setupUi();
};
#endif
......@@ -12,6 +12,7 @@ find_package(Nepomuk REQUIRED)
include(KDE4Defaults)
include(MacroLibrary)
set(WEBEXTRACTOR_VERSION_MAJOR 0 CACHE INT "Major WebExtractor version number" FORCE)
set(WEBEXTRACTOR_VERSION_MINOR 0 CACHE INT "Minor WebExtractor version number" FORCE)
set(WEBEXTRACTOR_VERSION_PATCH 1 CACHE INT "Release WebExtractor version number" FORCE)
......@@ -24,20 +25,22 @@ set (LIB_DESTINATION "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" CACHE STRING "Li
configure_file(LibWebextractorConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/LibWebextractorConfig.cmake @ONLY )
#build dependencies
add_subdirectory(ontologyloader)
include_directories(
${SOPRANO_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include/webextractor
${ontologyloader_SOURCE_DIR}
# ${CMAKE_CURRENT_SOURCE_DIR}/include
#${CMAKE_CURRENT_SOURCE_DIR}/include/webextractor
${CMAKE_CURRENT_BINARY_DIR}
${NEPOMUK_INCLUDE_DIR}
${CMAKE_BUILD_DIR}
${KDE4_INCLUDES}
)
add_definitions(-DMAKE_WEBEXTRACTOR_LIB)
set( webextractor_SRCS
resourceanalyzerfactory.cpp
......@@ -46,6 +49,7 @@ set( webextractor_SRCS
decisiondata.cpp
decisionfactory.cpp
decisionlist.cpp
decisionapplicationrequest.cpp
datappreply.cpp
datapp.cpp
debug_datapp.cpp
......@@ -63,13 +67,25 @@ set( webextractor_SRCS
nepomukservicedatabackend.cpp
servicedatabackend.cpp
identsetmanager.cpp
# Graph part
modelgraph.cpp
algorithm.cpp
graphalgorithm.cpp
copyvisitor.cpp
visitednodefilter.cpp
dotvisitor.cpp
nodefilterinterface.cpp
selectedpropertiesfunc.cpp
visitednodefilter.cpp
resourcenodefilter.cpp
plaintextvisitor.cpp
)
set ( webextractor_MOC
resourceanalyzerfactory.h
resourceanalyzer.h
datappreply.h
decisionapplicationrequest.h
datapp.h
debug_datapp.h
simplenetworkdatapp.h
......@@ -79,6 +95,13 @@ set ( webextractor_MOC
simplenetworkrequest.h
nepomukservicedatabackend.h
servicedatabackend.h
# Graph part
visitednodefilter.h
resourcenodefilter.h
selectedpropertiesfunc.h
childqueryinterface.h
resourcenodefilter.h
nodefilterinterface.h
)
QT4_WRAP_CPP( webextractor_RES ${webextractor_MOC} )
......@@ -100,7 +123,6 @@ set_target_properties(webextractor PROPERTIES
DEFINE_SYMBOL MAKE_WEBEXTRACTOR_LIB
)
#message(STATUS "(NOT) Found Qt network library ${QT_LIBRARIES} ")
target_link_libraries( webextractor
${NEPOMUK_LIBRARIES}
......@@ -110,6 +132,7 @@ target_link_libraries( webextractor
${QT_QTNETWORK_LIBRARY}
${QT_QTCORE_LIBRARY}
nepomuksync
ontologyloader
)
install(TARGETS webextractor
......@@ -135,6 +158,7 @@ set (WEBEXTRACTOR_HEADERS
decisionfactorybase.h
decisionfactory.h
decision.h
decisionapplicationrequest.h
decisionlist.h
decisiondata.h
global.h
......@@ -158,6 +182,19 @@ set (WEBEXTRACTOR_HEADERS
algorithm.h
modelgraphvisitor.h
${CMAKE_CURRENT_BINARY_DIR}/ndco.h
# Graph part
algorithm.h
graphalgorithm.h
copyvisitor.h
childqueryinterface.h
visitednodefilter.h
nodefilterinterface.h
resourcenodefilter.h
dotvisitor.h
modelgraphvisitor.h
modelgraph.h
selectedpropertiesfunc.h
plaintextvisitor.h
)
#set ( WEBEXTRACTOR_HEADERS
# ${CMAKE_CURRENT_SOURCE_DIR}/include/webextractor/resourceanalyzerfactory.h
......
......@@ -17,13 +17,21 @@
*/
#include "algorithm.h"
#include "modelgraphvisitor.h"
#include <Soprano/Node>
#include <Nepomuk/ResourceManager>
#include <Nepomuk/Resource>
#include "modelgraphvisitor.h"
#include "copyvisitor.h"
#include "plaintextvisitor.h"
#include "visitednodefilter.h"
#include "graphalgorithm.h"
#include "selectedpropertiesfunc.h"
#include "plaintextvisitor.h"
#include "modelgraph.h"
namespace NG = Nepomuk::Graph;
QUrl Nepomuk::deep_resource_copy(const Nepomuk::Resource & from, Nepomuk::ResourceManager * to , bool sameModels)
QUrl Nepomuk::deep_resource_copy(const Nepomuk::Resource & from, Nepomuk::ResourceManager * to, bool sameModels)
{
// Fix parameters
if(!to) {
......@@ -31,31 +39,26 @@ QUrl Nepomuk::deep_resource_copy(const Nepomuk::Resource & from, Nepomuk::Resou
}
// Make a copy
QList<QUrl> targets;
QSet<QUrl> targets;
QHash<QUrl, QUrl> convtable;
targets << from.resourceUri();
typedef void * BaseType; /* Base class, because we don't need it */
typedef Soprano::Node NodeType; /* Type of the Node. It can be ignored too */
typedef DummyNodeFunc<void*> NodeFunc; /* For given Node return itself as Node descriptor */
typedef ConvertWriteVisitor<void*, Soprano::Node> ParseFunc; /* Conversation func. This function will perform actual copying */
typedef Nepomuk::Graph::SelectedResourcePropertiesFunc<void*, Soprano::Node> NextFunc;/* This function will return as childs all nodes that are resource and there is triple ( subject, ?p, child )*/
Nepomuk::Graph::visit_model_graph <
BaseType,
NodeType,
NodeFunc,
ParseFunc,
NextFunc
> (
0,
from.manager()->mainModel(),
NG::CopyVisitor * visitor = new NG::CopyVisitor(to, &convtable);
NG::SelectedPropertiesFunc * childrenFunc = new NG::SelectedPropertiesFunc();
NG::ModelGraph * mg = new NG::ModelGraph(from.manager()->mainModel(), childrenFunc);
Nepomuk::Graph::visit_model_graph
(
mg,
targets,
-1,
NodeFunc(),
ParseFunc(to, &convtable),
NextFunc(),
visitor
- 1,
sameModels
);
delete visitor;
delete childrenFunc;
delete mg;
return convtable[from.resourceUri()];
}
......@@ -78,42 +81,72 @@ QHash<QUrl, QUrl> * Nepomuk::deep_resource_copy_adjust(
}
// Make a copy
QList<QUrl> targets;
QSet<QUrl> targets;
targets << from.resourceUri();
NG::CopyVisitor * visitor = new NG::CopyVisitor(to, convtable);
NG::VisitedNodeFilter * childrenFunc = new NG::VisitedNodeFilter(
visited,
new NG::SelectedPropertiesFunc()
);
NG::ModelGraph * mg = new NG::ModelGraph(from.manager()->mainModel(), childrenFunc);
typedef void * BaseType; /* Base class, because we don't need it */
typedef Soprano::Node NodeType; /* Type of the Node. It can be ignored too */
typedef DummyNodeFunc<void*> NodeFunc; /* For given Node return itself as Node descriptor */
typedef ConvertWriteVisitor <BaseType, NodeType>
Visitor; /* Conversation func. This function will perform actual copying */
typedef IgnoreVisitedFunc <
BaseType,
NodeType,
Nepomuk::Graph::SelectedResourcePropertiesFunc<void*, Soprano::Node>
> NextFunc;/* This function will return as childs all nodes that are resource and there is triple ( subject, ?p, child )*/
Nepomuk::Graph::visit_model_graph <
BaseType,
NodeType,
NodeFunc,
Visitor,
NextFunc
> (
0,
from.manager()->mainModel(),
Nepomuk::Graph::visit_model_graph
(
mg,
targets,
visitor,
-1,
NodeFunc(),
Visitor(to, convtable),
NextFunc(&visited),
sameModels
);
delete visitor;
delete childrenFunc;
delete mg;
return convtable;
}
void Nepomuk::dump_resource_as_text(const Nepomuk::Resource & resource, QTextStream & stream, int depth_limit)
{
dump_resource_as_text(
resource.resourceUri(),
resource.manager()->mainModel(),
stream,
depth_limit);
}
void Nepomuk::dump_resource_as_text(const QUrl & resource, Soprano::Model * model, QTextStream & stream, int depth_limit)
{
// Make a copy
QSet<QUrl> targets;
targets << resource;
dump_resources_as_text(targets, model, stream, depth_limit);
}
void Nepomuk::dump_resources_as_text(const QSet<QUrl> & resources, Soprano::Model * model, QTextStream & stream, int depth_limit)
{
NG::PlainTextVisitor * visitor = new NG::PlainTextVisitor(&stream);
NG::SelectedPropertiesFunc * childrenFunc = new NG::SelectedPropertiesFunc();
NG::ModelGraph * mg = new NG::ModelGraph(model, childrenFunc);
Nepomuk::Graph::visit_model_graph
(
mg,
resources,
visitor,
depth_limit,
false
);
delete visitor;
delete childrenFunc;
delete mg;
}
/*
QUrl Nepomuk::ngUri( const Soprano::Node & node)
{
......
......@@ -20,18 +20,24 @@
#define __NEPOMUK_ALGORITHM_H_
#include <QUrl>
#include <Soprano/Model>
#include <Soprano/Node>
#include <QUrl>
#include <Nepomuk/Resource>
#include <Nepomuk/ResourceManager>
#include "modelgraphvisitor.h"
#include "webextractor_export.h"
class QTextStream;
namespace Soprano
{
class Model;
}
namespace Nepomuk
{
class Resource;
class ResourceManager;
/*! Make a deep copy of the resource.
* \param from Resource to copy
* \param to ResourceManager that manages a model to copy to
......@@ -39,7 +45,7 @@ namespace Nepomuk
* are the same. This will prevent deadlocks
* \return Url of the new resource
*/
QUrl deep_resource_copy(const Nepomuk::Resource & from, Nepomuk::ResourceManager * to = 0, bool sameModels = true);
WEBEXTRACTOR_EXPORT QUrl deep_resource_copy(const Nepomuk::Resource & from, Nepomuk::ResourceManager * to = 0, bool sameModels = true);
/*! Make a deep copy or the resource, respecting already copied parts.
......@@ -49,126 +55,19 @@ namespace Nepomuk
* \param convtable This is table of previously copied resources. In form
* < original resource url, copy resource url>
*/
QHash<QUrl, QUrl> * deep_resource_copy_adjust(const Nepomuk::Resource & from, Nepomuk::ResourceManager * to = 0, QHash<QUrl, QUrl> * convtable = 0 , bool sameModels = true);
WEBEXTRACTOR_EXPORT QHash<QUrl, QUrl> * deep_resource_copy_adjust(const Nepomuk::Resource & from, Nepomuk::ResourceManager * to = 0, QHash<QUrl, QUrl> * convtable = 0 , bool sameModels = true);
//WEBEXTRACTOR_EXPORT QUrl ngUri( const Soprano::Node & node);
/*! \brief This class will write all recived statements to given model
* Also it will convert any subject or object to new object.
* So with this function user can perform a deep copy of the resource
* T and Node types are ignored
* This class should be used as ParseFunc
/*! \brief Write graph as text
* Use this function only for debugging.
*/
WEBEXTRACTOR_EXPORT void dump_resource_as_text(const Nepomuk::Resource & from, QTextStream & stream, int depth_limit = -1);
/*! \brief Write graph as text
* Use this function only for debugging.
*/
template < typename T, typename Node, typename NodeGetter = Graph::NodeCast<T, Node> >
class ConvertWriteVisitor: public Graph::NullVisitor<T, Node>
{
private:
Nepomuk::ResourceManager * m_targetManager;
QHash< QUrl, QUrl> * m_proxyUrls;
Soprano::Node vertexProxy();
NodeGetter m_getter;
public:
ConvertWriteVisitor(Nepomuk::ResourceManager * targetManager, QHash<QUrl, QUrl> * answer , NodeGetter getter = NodeGetter()) {
Q_ASSERT(targetManager);
Q_ASSERT(answer);
m_targetManager = targetManager;
m_proxyUrls = answer;
m_getter = getter;
}
void enter_vertex(T base, Node node) {
// Simply create proxy
vertexProxy(m_getter(base, node));
}
void enter_edge(T base, Node n, const Soprano::Node & currentNode,
const Soprano::Node & propertyNode,
const Soprano::Node & childNode) {
Q_UNUSED(base); Q_UNUSED(n);
Soprano::Node subjProxyNode = vertexProxy(currentNode);
Soprano::Node objProxyNode = vertexProxy(childNode);
// Add statement
m_targetManager->mainModel()->addStatement(Soprano::Statement(
subjProxyNode,
propertyNode,
objProxyNode
));
}
Soprano::Node vertexProxy(const Soprano::Node & node) {
if(node.isBlank())
return node;
if(node.isLiteral())
return node;
Soprano::Node answer;
QHash< QUrl, QUrl >::const_iterator it =
m_proxyUrls->find(node.uri());
if(it == m_proxyUrls->end()) {
// Create new
// Create new url
// FIXME What label should be passed to the generateUniqueUri
answer = Soprano::Node(
m_targetManager->generateUniqueUri("unknown")
);
Q_ASSERT(!answer.uri().isEmpty());
// Add to table
kDebug() << "Adding proxy to " << node.uri() << " : " << answer.uri();
m_proxyUrls->insert(node.uri(), answer.uri());
} else {
answer = Soprano::Node(it.value());
}
return answer;
}
};
template < typename T, typename Node, typename SubFunc = Graph::SelectedResourcePropertiesFunc<T, Node>, typename NodeGetter = Graph::NodeCast<T, Node> >
class IgnoreVisitedFunc
{
private:
QSet<QUrl > * m_visited;
SubFunc m_subFunc;
NodeGetter m_getter;
typedef SubFunc sub_type;
public:
IgnoreVisitedFunc(QSet<QUrl> * visited, NodeGetter getter = NodeGetter(), SubFunc subFunc = SubFunc()) {
if(!visited)
m_visited = new QSet<QUrl>();
else
this->m_visited = visited;
m_subFunc = subFunc;
m_getter = getter;
}
QString operator()(T base, Node node, const Soprano::Model * model) {