[Nepomuk] Graph visitor for Nepomuk model.

Artem Serebriyskiy v.for.vandal at gmail.com
Thu Aug 5 23:27:25 CEST 2010


*Discussion.*

*What: *
The API of the Model Graph  Visitor [MGV]. The MGV is an function that
treats Model (Soprano::Model) as a big graph. Subjects and objects in
statements  are vertices, and properties are edges.
The input parameters to the function are initial vertices. Then function
visit every vertex that can be reached from the initial vertices and every
connecting edge.

*Why:*
It can be used for different algorithms:

   - deep copy of the resource // see algorithm.cpp
   - displaying of the resources  in birds-eye view
   - May be some other


*Current implementation:*
In playground base/nepomuk/webextractor/libwebextractor.
Files: algorithm.h algorithm.cpp modelgraphvisitor.h
Application: <>/webextractor/runtime/graphviz. Creat a dot file for selected
resource.
Example of the result: attached.

The current API is realy weird.
template < typename T, typename Node, typename NodeFunc, typename Visitor ,
typename NextFunc  >
       void visit_model_graph(
            T base,
            Soprano::Model * model,
            const QList<QUrl> & targets, // Start points
            int depth_limit = -1,
            NodeFunc nodeFunc = NodeFunc(),
            Visitor visitor = Visitor(),
            NextFunc nextFunc = NextFunc(),
            bool caching = true // Doesn't matter for discussion
)

*Comments*:

   - T and Node are some user defined classes. T as analogue to boost::graph
   G and Node is analogue to  boost::graph_traits<G>::vertex_descriptor
   - NodeFunc is a functor that converts Node object to Soprano::Node


In my opinion these 3 types are unnecessary. Node can be replaced with
Soprano::Node. Then NodeFunc can be discarded. And I think that T can be
replaced with Soprano::Model* or discarded.

   - Visitor. This is main class. Methods of this class are called on every
   vertex and every edge. Look  NullVisitor for more details (
   modelgraphvisitor.h). The DotVisitor are example of visitor.
   - NextFunc is  a functor. For given node it must return a query(
   currently as String, unfortunately).   If query is not empty then it must
   have ?p ?o result variables. The result of the query ( if any ) is the
   edge(?p) and corresponding child node (?o); There is an implemntation of
   this class that selects all properties of the Soprano::Node ( if this node
   is resource node. Literal nodes are ignored because they can't have childs).

*Suggestions:*
There are 2 basic ideas - use templates or use virtual methods.

*Templates:*
discard T, discard Node, discard NodeFunc
template < typename Visitor , typename NextFunc  >
       void visit_model_graph(
             Soprano::Model * model,
            const QList<QUrl> & targets,
            int depth_limit = -1,
            Visitor visitor = Visitor(),
            NextFunc nextFunc = NextFunc(),
            bool caching = true)


*Virtual Methods:*
void visit_model_graph(
            Soprano::Model * model,
            const QList<QUrl> & targets,
            int depth_limit = -1,
            VisitorInterface *  visitor = new  DummyVisitor(),
            NextFuncInterface * nextFunc = new DefaultNextFunc(),
            bool caching = true)

*Remarks*:
The best possible idea is to provide apropriate  boost::graph_traits. Then
we will have full power of boost::graph library. But I have no idea how to
implement VertexListGraph<file:///usr/share/doc/libboost-doc/HTML/libs/graph/doc/VertexListGraph.html>concept.
It is required for
copy_graph, bread_first_search and for many others.
One more problem is in BFS Visitor Concept.  I don't know boost::graph
well, but due to description of the  vis.initialize_vertex(s, g) the
bread_first_visit is 2-passes algorithm. At first  pass
viz.initialize_vertext() will be called on every vertex and at second pass
all other methods.  But Nepomuk is constantly changing, so there is no
guarantee that  vertices and edges discovered in first pass will be the same
as in second pass. Comment from anyone who knows boost::graph is very
welcome.

-- 
Sincerely yours,
Artem
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.kde.org/pipermail/nepomuk/attachments/20100806/dc1516a2/attachment-0001.htm 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: d1.png
Type: image/png
Size: 167049 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/nepomuk/attachments/20100806/dc1516a2/attachment-0001.png 


More information about the Nepomuk mailing list