copy nodes to compose subgraph

883 views
Skip to first unread message

Daniel Aschauer

unread,
May 7, 2012, 4:06:17 AM5/7/12
to ne...@googlegroups.com
I have a graph where I want to copy a part of it starting from a root node.
All subnode with a boolean value show=true should be included.

Is there a simple way to do that or do I have to iterate throug the nodes and copy "by hand"?

Daniel



Peter Neubauer

unread,
May 7, 2012, 4:21:38 AM5/7/12
to ne...@googlegroups.com
Are these nodes connected to the root node in any way? Also, how big
is your graph? If you have a big graph and disconnected nodes, then an
"show" index might be more efficient to maintain and iterate when you
need it than traversing the graph. Depends a big on your layout.

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

If you can write, you can code - @coderdojomalmo
If you can sketch, you can use a graph database - @neo4j

Daniel Aschauer

unread,
May 7, 2012, 4:38:03 AM5/7/12
to ne...@googlegroups.com
Thanks for your reply!

Yes, there are connection between root and the other (sub)nodes, but there are nodes inbetween that as well have to be copied (and don't (need to) have a show=true property)
How big the graph will become, let's say a few thousand nodes..

Daniel

Peter Neubauer

unread,
May 7, 2012, 4:49:42 AM5/7/12
to ne...@googlegroups.com
In that case, I would just try to fish these paths out with a Cypher
query, something like

start root=node(0)
match path = root-[*1..]-node
where node.show = true
return path

which even gives you the paths and the nodes in between?

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

If you can write, you can code - @coderdojomalmo
If you can sketch, you can use a graph database - @neo4j


On Mon, May 7, 2012 at 10:38 AM, Daniel Aschauer

Daniel Aschauer

unread,
May 7, 2012, 7:01:36 AM5/7/12
to ne...@googlegroups.com
That is a solution I thought about as well. But wouldn't that produce a lot of overhead.
The case is that a lot of these leaves (show=true) will be connected to a subnode -> so this gives me a lot of path that would contain the same (sub)nodes in between?
Something cool would be the possibility to define a view on the graph to work with.

Thanks, Daniel

Peter Neubauer

unread,
May 7, 2012, 10:32:22 AM5/7/12
to ne...@googlegroups.com
Mmh,
with that amount of data that shouldn't be a problem, just pipe that
cypher into some export format (graphML or GEOFF) and use that do have
your derived graph read in?

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

If you can write, you can code - @coderdojomalmo
If you can sketch, you can use a graph database - @neo4j


Daniel Aschauer

unread,
May 7, 2012, 11:00:26 AM5/7/12
to ne...@googlegroups.com
Good point, although I do copying now by collection nodes and relationships from all paths and copying their properties. 
However could be interesting to be able to directly export some cypher query results. How can this be done?
I used the (com.tinkerpop.blueprints*)GraphMLWriter already, but there I have to provide a Graph?
Thanks,
Daniel

Peter Neubauer

unread,
May 10, 2012, 9:30:41 AM5/10/12
to ne...@googlegroups.com
Mmh,
I think simply iterating over all nodes/relationships and then
deduping them should work. We do something similar when providing
D3.js with data, see
https://github.com/mbostock/d3/blob/master/examples/force/miserables.json
for the data, and

http://mbostock.github.com/d3/ex/force.html for the resulting graph.

WDYT?

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

If you can write, you can code - @coderdojomalmo
If you can sketch, you can use a graph database - @neo4j


On Mon, May 7, 2012 at 5:00 PM, Daniel Aschauer

Daniel Aschauer

unread,
May 10, 2012, 9:54:13 AM5/10/12
to ne...@googlegroups.com
It works fine already put all nodes/relationships from the pathes in
one Collection, and then copying their properties.
The only problem I'm still facing is that the index is not updated for
the copies - will have to use some lookup table which properties to
index.
Cheers, Daniel

2012/5/10 Peter Neubauer <peter.n...@neotechnology.com>:

Daniel Aschauer

unread,
May 11, 2012, 5:53:51 AM5/11/12
to ne...@googlegroups.com
The problem a have is that I copy the Node objects with their properties, but I have to convert them somehow back to the according object (SDN annotated @NodeEntity) otherwise the repository methods and the index won't work?

How can this be done?

Thanks, Daniel

Peter Neubauer

unread,
May 11, 2012, 8:24:49 AM5/11/12
to ne...@googlegroups.com
Right,
I suspect that you need to update the indexes that are attached to an
entity (maybe you can infer that from the annotations of the objects,
since the indexes have names reflecting those, MH knows more) and of
course create the corresponding graph data. Maybe you could examine
what exactly the raw node looks like that is backing an object, and
create it that way?

I think inferring the used indexes might be the tricky part, but not impossible.

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

If you can write, you can code - @coderdojomalmo
If you can sketch, you can use a graph database - @neo4j


On Fri, May 11, 2012 at 11:53 AM, Daniel Aschauer

Michael Hunger

unread,
May 11, 2012, 2:34:06 PM5/11/12
to ne...@googlegroups.com
You can call template.postEntityCreation(node,clazz) to add the necessary indices for the type information.

template.setPersistentState(object,node) // existing node
template.postEntityCreation(node,clazz) // store type information in graph
template.save(object) saves the properties of the object onto the node

HTH

Michael

Daniel Aschauer

unread,
May 14, 2012, 11:07:54 AM5/14/12
to ne...@googlegroups.com
template.postEntityCreation(node,clazz) is deprecated.

As convert a Node to a @NodeEntity by this:
Class<?> targettype = Class.forName((String) nRootNode.getProperty("__type__"));
template.save(template.convert(nRootNode, targettype));

This works fine for some part, the node and the indices are created, but by using the repository method findAll these nodes are not included, why or what can be done to inlcude them?

I am using Sring data neo4j 2.0.1

Michael Hunger

unread,
May 14, 2012, 11:52:05 AM5/14/12
to ne...@googlegroups.com
That's what template.postEntityCreation(node,clazz) is for, it is deprecated b/c I want to replace it in the long term.

But for now it is is the external API way to go.

Michael

Michael Hunger

unread,
Feb 2, 2013, 10:06:52 AM2/2/13
to ne...@googlegroups.com
You can use it for now

Will go away with label support in neo an sdn

Sent from mobile device

Am 02.02.2013 um 13:47 schrieb Dmitry Serebrennikov <dser...@gmail.com>:

Michael,

Do you think it would be possible to remove the @deprecation flag from that method or perhaps add a comment stating the alternative to use or that it is the one to be used now and deprecation is only for long term considerations?

I ran into this same method earlier today but kept on looking since I didn't want to write new code using a deprecated method. It would have helped me to know that this was the approved method to use at this time.
--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages