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: find all longest paths
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
  12 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
 
Tomas Teicher  
View profile  
 More options Apr 30 2012, 3:00 am
From: Tomas Teicher <tomasteic...@gmail.com>
Date: Mon, 30 Apr 2012 00:00:25 -0700 (PDT)
Local: Mon, Apr 30 2012 3:00 am
Subject: cypher: find all longest paths

Hi
I have cypher query as follows:

start a = node(1) MATCH path = a-[r:HAS_PARENT*]->b return path

it returns results as follows:

Pater -> John -> Maria -> Mike
Peter -> John -> Maria
Peter-> John

I would like to return only longest paths.

I have a graph where every node can have just one relationship of type
HAS_PARENT. So when I return only longest paths, I should found all nodes
with that relationship

Can anybody help?

thanks
Tomas


 
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 Apr 30 2012, 3:54 am
From: Peter Neubauer <peter.neuba...@neotechnology.com>
Date: Mon, 30 Apr 2012 09:54:55 +0200
Local: Mon, Apr 30 2012 3:54 am
Subject: Re: [Neo4j] cypher: find all longest paths
Tomas,

Taking the Matrix default, you can do something like
http://tinyurl.com/6ralddc or

start n=node(1)
match p = n-[:KNOWS*1..]->m
with n,MAX(length(p)) as l
match p = n-[:KNOWS*1..]->m
where length(p) = l
return p,l

It's a bit lengthy since you first need to find the maxlength, and
then the paths that have this length, but it should work. For a
shorter workaround you could simply just limit the result and return
after the first clause:

start n=node(1) match p = n-[:KNOWS*1..]->m return p,MAX(length(p)) as
l order by l desc limit 1

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


 
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.
Tomas Teicher  
View profile  
 More options May 4 2012, 4:25 pm
From: Tomas Teicher <tomasteic...@gmail.com>
Date: Fri, 4 May 2012 13:25:18 -0700 (PDT)
Local: Fri, May 4 2012 4:25 pm
Subject: Re: cypher: find all longest paths

thank you

I have found one more way

start n=node(1) match p = n-[:KNOWS*1..]->m WHERE NOT(m-[:KNOWS]->())
return p

last node in path cannot have outgoing KNOWS relationship, so it should
return only the longest paths of the relationships.

Dňa pondelok, 30. apríla 2012 9:00:25 UTC+2 Tomas Teicher napísal(-a):


 
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.
Tomas Teicher  
View profile  
 More options May 4 2012, 4:30 pm
From: Tomas Teicher <tomasteic...@gmail.com>
Date: Fri, 4 May 2012 13:30:14 -0700 (PDT)
Local: Fri, May 4 2012 4:30 pm
Subject: Re: cypher: find all longest paths

In fact, this work only when nodes are in hierarchical structure (so
between two nodes is only one possible path), but this sutisfies my use case

thanks for the tips

Tomas

Dňa piatok, 4. mája 2012 22:25:18 UTC+2 Tomas Teicher napísal(-a):


 
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.
Alireza Rezaei Mahdiraji  
View profile   Translate to Translated (View Original)
 More options May 7, 9:28 am
From: Alireza Rezaei Mahdiraji <alireza...@gmail.com>
Date: Tue, 7 May 2013 06:28:25 -0700 (PDT)
Local: Tues, May 7 2013 9:28 am
Subject: Re: [Neo4j] cypher: find all longest paths

I want to find all different paths starting from root element, i.e., no
prefix paths but
paths can be of different length.
The query you wrote find the maximal length and only returns those.
Best,
Alireza


 
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   Translate to Translated (View Original)
 More options May 7, 9:44 am
From: Michael Hunger <michael.hun...@neotechnology.com>
Date: Tue, 7 May 2013 15:44:57 +0200
Local: Tues, May 7 2013 9:44 am
Subject: Re: [Neo4j] cypher: find all longest paths

start n=node(1) match p = n-[:KNOWS*1..]->m return p

Am 07.05.2013 um 15:28 schrieb Alireza Rezaei Mahdiraji <alireza...@gmail.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.
Alireza Rezaei Mahdiraji  
View profile   Translate to Translated (View Original)
 More options May 7, 9:55 am
From: Alireza Rezaei Mahdiraji <alireza...@gmail.com>
Date: Tue, 7 May 2013 06:55:29 -0700 (PDT)
Local: Tues, May 7 2013 9:55 am
Subject: Re: [Neo4j] cypher: find all longest paths

This will also return prefix paths of each maximal path.

Like examples above:

Pater -> John -> Maria -> Mike
Peter -> John -> Maria
Peter-> John

Best,
Alireza


 
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.
Alireza Rezaei Mahdiraji  
View profile   Translate to Translated (View Original)
 More options May 7, 10:04 am
From: Alireza Rezaei Mahdiraji <alireza...@gmail.com>
Date: Tue, 7 May 2013 07:04:50 -0700 (PDT)
Local: Tues, May 7 2013 10:04 am
Subject: Re: [Neo4j] cypher: find all longest paths

Forgot to write, I do not want that :)
Alireza


 
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.
Thomas Fenzl  
View profile   Translate to Translated (View Original)
 More options May 7, 10:41 am
From: Thomas Fenzl <thomas.fe...@gmail.com>
Date: Tue, 07 May 2013 16:41:47 +0200
Local: Tues, May 7 2013 10:41 am
Subject: Re: [Neo4j] cypher: find all longest paths
You can filter paths where the final nodes still has outgoing
connections like this:

start n=node(1) match p = n-[:KNOWS*1..]->m
where not m -[:KNOWS]->()
return p

Regards,
Thomas

On 2013-05-07 15:55, Alireza Rezaei Mahdiraji wrote:


 
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.
Alireza Rezaei Mahdiraji  
View profile   Translate to Translated (View Original)
 More options May 8, 6:26 am
From: Alireza Rezaei Mahdiraji <alireza...@gmail.com>
Date: Wed, 8 May 2013 03:26:28 -0700 (PDT)
Local: Wed, May 8 2013 6:26 am
Subject: Re: [Neo4j] cypher: find all longest paths

OK, here is a little bit more about the type of path I am interested:
I have a graph which has 4 levels of nodes, namely, B, F, E, and V.
All nodes have two properties let say name and dim.  Nodes in set V
are only connected to E, and E only to F and F only to B.

So now, I want to know if all paths starting from B to V (or vice versa)
have
the maximum length (here 3). Conceptually, it means that some nodes of
types
E might not be connected to any F and instead be connected to some B.
This only happens from V to B direction. Another case, some Nodes from
V may be directly connected to B but not to any E or F.
I hope it is clear enough :)

Now, the question is how I check to see there are paths (at least one) of
such type, i.e.,
with length less than maximum (3 here)?

Best,
Alireza


 
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.
Lasse Westh-Nielsen  
View profile   Translate to Translated (View Original)
 More options May 8, 7:09 am
From: Lasse Westh-Nielsen <la...@neotechnology.com>
Date: Wed, 8 May 2013 13:09:22 +0200
Local: Wed, May 8 2013 7:09 am
Subject: Re: [Neo4j] cypher: find all longest paths

Alireza,

Are you looking for the number of paths of length 2 or less between B and V:

start b=node({b}), v=node({v}) match p = b-[:KNOWS*1..2]->v
return count(p)

Or did I misunderstand?

 - Lasse

On Wed, May 8, 2013 at 12:26 PM, Alireza Rezaei Mahdiraji <


 
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.
Alireza Rezaei Mahdiraji  
View profile   Translate to Translated (View Original)
 More options May 8, 10:44 am
From: Alireza Rezaei Mahdiraji <alireza...@gmail.com>
Date: Wed, 8 May 2013 07:44:00 -0700 (PDT)
Subject: Re: [Neo4j] cypher: find all longest paths

It seems using your query together with a where clause will get what I
want,
I will test it on more cases and report back if it does not.
Thanks a lot :)
Best,
Alireza


 
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 »