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: How to get top 1 record for each X?
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
  3 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
 
Paul Lam  
View profile  
 More options Nov 14 2012, 10:10 am
From: Paul Lam <paul....@forward.co.uk>
Date: Wed, 14 Nov 2012 07:10:29 -0800 (PST)
Local: Wed, Nov 14 2012 10:10 am
Subject: Cypher: How to get top 1 record for each X?

This came about from looking at using Cypher as a recommender. If person 1
likes A; person 2 likes A and B; then you would recommend B to person 1. I
can do the first part in Cypher to list top common shared likes items, but
how do I use that resulting table to get a list of user names that I should
recommend?

Using this graph as an example -- http://console.neo4j.org/r/2096v6

This cypher query returns the top shared likes products.

START   food = node:node_auto_index(type = "food"), user =
node:node_auto_index(type = "user")
MATCH   food<-[:IS_A]-x<-[:LIKE]-person-[:IS_A]->user
WITH    person, x
MATCH   person-[:LIKE]->y-[:IS_A]->cc
WHERE   NOT x = y
WITH    x, y, COUNT(*) AS cnt
RETURN  x.name, y.name, cnt
ORDER BY cnt DESC
LIMIT 10;

How do I use WITH to get for each X, return the top Y. Then I can do,
MATCH person-[:LIKE]->x
WHERE NOT(person-[:LIKE]->y)
RETURN x, y, person.name

One expected result using the linked example is:

X, Y, names
apple, orange, Bob

etc. for each X and its corresponding top Y.


 
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 Nov 15 2012, 1:52 pm
From: Peter Neubauer <peter.neuba...@neotechnology.com>
Date: Thu, 15 Nov 2012 19:51:58 +0100
Local: Thurs, Nov 15 2012 1:51 pm
Subject: Re: [Neo4j] Cypher: How to get top 1 record for each X?

Hi Paul,
you can fold a lot of this into comma separated MATCH paths and multiple
WHERE filters. I did now

START   food = node:node_auto_index(type = "food"), user =
node:node_auto_index(type = "user")
MATCH   food<-[:IS_A]-x<-[:LIKE]-person-[:IS_A]->user,
person-[:LIKE]->y-[:IS_A]->cc, person-[:LIKE]->x
WHERE   person-[:LIKE]->y-[:IS_A]->cc AND NOT x = y AND
NOT(person-[:LIKE]->y)
RETURN  x.name, y.name, person.name, count(*) as cnt
ORDER BY cnt DESC
LIMIT 10;

http://console.neo4j.org/r/fakfci

Not sure that is what you are expecting?

/peter

Cheers,

/peter neubauer

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

Neo4j 1.8 GA -
http://www.dzone.com/links/neo4j_18_release_fluent_graph_literacy.html


 
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.
Paul Lam  
View profile  
 More options Nov 16 2012, 5:40 am
From: Paul Lam <paul....@forward.co.uk>
Date: Fri, 16 Nov 2012 02:40:16 -0800 (PST)
Local: Fri, Nov 16 2012 5:40 am
Subject: Re: [Neo4j] Cypher: How to get top 1 record for each X?

Thanks for cleaning that up. What I need is the next step though. Using
this on the web console,

START   food = node:node_auto_index(type = "food"), user =
node:node_auto_index(type = "user")
MATCH   food<-[:IS_A]-x<-[:LIKE]-person-[:IS_A]->user,
        person-[:LIKE]->y-[:IS_A]->food
WHERE   NOT x = y
RETURN  x.name, y.name, count(*) as cnt
ORDER BY cnt DESC
LIMIT 10;

We get that people likes apple prefer orange the most as a second item. I
want to get all the people that likes apple but not orange. Which I can do
like this:

START   apple = node:node_auto_index(name = "apple"), orange =
node:node_auto_index(name = "orange")
MATCH   person-[:LIKE]->apple
WHERE   NOT(person-[:LIKE]->orange)
RETURN  person.name

My question though, is how to get a generalised query of the above
automatically from the first query so that for each food X, it returns that
best Y (e.g. for apple, it's orange only; for bread, it's apple; and etc)
and the list of people that likes X but not yet Y.


 
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 »