Scpecific request computing a raw

35 views
Skip to first unread message

Anthony

unread,
Mar 2, 2012, 10:16:03 AM3/2/12
to Neo4j
I'm new Neo4j user and developper beginner.

I work on a graph that is composed of multiples parts.
Parts have subparts.
Each part and subparts have a weight.

How can i get the total weigth of a part composed by the weigth of
this part with the weigth of all subpart ?

I don't know neither Java nor Groovy.

Can you help me to choose the better way to begin ?

Thanks for your attention.

Josh Adell

unread,
Mar 2, 2012, 12:34:01 PM3/2/12
to Neo4j
I think you could do this with a Cypher query:

START part=node(123) // Or look it up in an index
MATCH p = part-[:HAS_SUB_PART]->subpart
RETURN SUM( EXTRACT (n in nodes(p) : n.weight ) )

I might be a bit shaky on the syntax, but all the pieces should be
there.

-- Josh

Michael Hunger

unread,
Mar 2, 2012, 12:42:33 PM3/2/12
to ne...@googlegroups.com
Probably as the number of parts is not limited (it's a tree) use an variable length path "*0.."

> START part=node(123) // Or look it up in an index

> MATCH p = part-[:HAS_SUB_PART*0..]->subpart


> RETURN SUM( EXTRACT (n in nodes(p) : n.weight ) )

Josh Adell

unread,
Mar 2, 2012, 1:40:13 PM3/2/12
to Neo4j
Ah yes. I thought it, I just didn't type it.

-- Josh

On Mar 2, 12:42 pm, Michael Hunger <michael.hun...@neotechnology.com>
wrote:

Anthony

unread,
Mar 2, 2012, 5:08:29 PM3/2/12
to Neo4j
Thanks for your reactivity.

The previous command help me but in my problem, there are
effectivities on relation.

Q1: How can I multiply effectivity with part weight ?

The ultimate goal should be to have : part weight = (subpart1.weight *
effectivity1) + (subpart2.weight * effectivity2) + ...

Q2: It's possible on cypher ?

One again, thanks.

Michael Hunger

unread,
Mar 2, 2012, 5:28:55 PM3/2/12
to ne...@googlegroups.com
How deep is your tree at maximum?

Michael

Andres Taylor

unread,
Mar 2, 2012, 8:44:11 PM3/2/12
to ne...@googlegroups.com
On Fri, Mar 2, 2012 at 6:34 PM, Josh Adell <josh....@gmail.com> wrote:
I think you could do this with a Cypher query:

START part=node(123)   // Or look it up in an index
MATCH p = part-[:HAS_SUB_PART]->subpart
RETURN SUM( EXTRACT (n in nodes(p) : n.weight ) )

We talked about this a few weeks ago, but it has not been implemented. You are trying to aggregate over a collection of elements, and not aggregate over sub graphs. And Cypher doesn't support that. :(

Andrés 
Reply all
Reply to author
Forward
0 new messages