Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
cypher: counting different relationship types
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
tcb  
View profile  
 More options Oct 2 2012, 11:36 am
From: tcb <thecolourblu...@gmail.com>
Date: Tue, 2 Oct 2012 16:36:14 +0100
Local: Tues, Oct 2 2012 11:36 am
Subject: cypher: counting different relationship types

Hi,

I am trying to count the number of relationships of each type for some
nodes.

This query (from the docs) is a good start and gives me the type and the
count of that type

START n=node(1)

MATCH n-[r?]->()

RETURN type(r), count(*)

But I know the types I want and I would like to return something like this:

RETURN count(type(r) = REL1), count(type(r) = REL2)

- this doesn't work ;(

It's a little hard to figure just what cypher is able to do- it seems like
something like this should work. My best attempt so far is two MATCH
clauses:

MATCH n-[r1?]->()

MATCH n-[r2?]->()

RETURN count(type(r1)), count(type(r2))

Is there a better way to do this?

On a side note- how does having the two match statements affect the
performance of the cypher query? Does it loop over all relationships of
each node twice? This could be costly when I have a dense graph.

thanks,


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter Neubauer  
View profile  
 More options Oct 2 2012, 3:37 pm
From: Peter Neubauer <peter.neuba...@neotechnology.com>
Date: Tue, 2 Oct 2012 21:36:46 +0200
Local: Tues, Oct 2 2012 3:36 pm
Subject: Re: [Neo4j] cypher: counting different relationship types
Hi there, you can do

START n=node(1)
MATCH n-[r?:REL1|REL2]->()
RETURN type(r), count(*)

see http://console.neo4j.org/r/5pig2k and
http://docs.neo4j.org/chunked/snapshot/query-match.html#match-match-b...

Cheers,

/peter neubauer

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

Wanna learn something new? Come to http://graphconnect.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
tcb  
View profile  
 More options Oct 2 2012, 3:55 pm
From: tcb <thecolourblu...@gmail.com>
Date: Tue, 2 Oct 2012 20:55:21 +0100
Local: Tues, Oct 2 2012 3:55 pm
Subject: Re: [Neo4j] cypher: counting different relationship types

thanks, but that returns the total count of either REL1 or REL2. What I
would like to do is return the separate counts, rather than the aggregate:

return count(REL1), count(REL2)

Is there a way to do this?

thanks,

On Tue, Oct 2, 2012 at 8:36 PM, Peter Neubauer <


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Hunger  
View profile  
 More options Oct 2 2012, 4:21 pm
From: Michael Hunger <michael.hun...@neotechnology.com>
Date: Tue, 2 Oct 2012 22:21:35 +0200
Local: Tues, Oct 2 2012 4:21 pm
Subject: Re: [Neo4j] cypher: counting different relationship types

....
with collect(r) as rels
return length(filter(r in rels : type(r) == 'REL1')) as REL1,
length(filter(r in rels : type(r) == 'REL2')) as REL2

Cheers

Michael

Am 02.10.2012 um 21:55 schrieb tcb:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter Neubauer  
View profile  
 More options Oct 2 2012, 4:23 pm
From: Peter Neubauer <peter.neuba...@neotechnology.com>
Date: Tue, 2 Oct 2012 22:23:11 +0200
Local: Tues, Oct 2 2012 4:23 pm
Subject: Re: [Neo4j] cypher: counting different relationship types
man,
that one is cool Michael "Open Sourcerer" Hunger!

Cheers,

/peter neubauer

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

Wanna learn something new? Come to http://graphconnect.com

On Tue, Oct 2, 2012 at 10:21 PM, Michael Hunger


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Hunger  
View profile  
 More options Oct 2 2012, 4:29 pm
From: Michael Hunger <michael.hun...@neotechnology.com>
Date: Tue, 2 Oct 2012 22:28:58 +0200
Local: Tues, Oct 2 2012 4:28 pm
Subject: Re: [Neo4j] cypher: counting different relationship types
Should be easier though :)

Am 02.10.2012 um 22:23 schrieb Peter Neubauer:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
tcb  
View profile  
 More options Oct 2 2012, 5:02 pm
From: tcb <thecolourblu...@gmail.com>
Date: Tue, 2 Oct 2012 22:02:32 +0100
Local: Tues, Oct 2 2012 5:02 pm
Subject: Re: [Neo4j] cypher: counting different relationship types

thanks Michael

that's a very nifty cypher alright, but it doesn't do what I want ;)

It collects all the relationships for all nodes and then counts the number
of each type. I want the counts of each type for each individual node.

This is what I've got working in the meantime:

start n=node(*)
match n-[r1?:REL1]->(), n-[r2?:REL2]->()
return n, count(r1) as REL1, count(r2) as REL2

+------------------------------------------------------------------+
| n                                                   | REL1 | REL2 |
+------------------------------------------------------------------+
| Node[11] | 10   | 2   |
| Node[10] | 4    | 6   |
| Node[12] | 0    | 5   |
....
| Node[13] | 6    | 3   |
| Node[14] | 2    | 1   |
+------------------------------------------------------------------+

and this seems to work just fine.

I've noticed there are stats for cypher queries on the scala side- is there
any progress on exposing them to java-side? It would be a great help to
improve our cypher queries...
https://github.com/neo4j/community/issues/730

thanks,

On Tue, Oct 2, 2012 at 9:21 PM, Michael Hunger <


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter Neubauer  
View profile  
 More options Oct 2 2012, 5:10 pm
From: Peter Neubauer <peter.neuba...@neotechnology.com>
Date: Tue, 2 Oct 2012 23:09:43 +0200
Local: Tues, Oct 2 2012 5:09 pm
Subject: Re: [Neo4j] cypher: counting different relationship types
Hi there,
the exposure sounds like a perfect contribution area me thinks :)

Cheers,

/peter neubauer

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

Wanna learn something new? Come to http://graphconnect.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »