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?
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
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;
On Wed, Nov 14, 2012 at 4:10 PM, Paul Lam <paul....@forward.co.uk> wrote:
> 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?
> 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:
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.
On Thursday, November 15, 2012 6:52:21 PM UTC, Peter Neubauer wrote:
> 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;
> On Wed, Nov 14, 2012 at 4:10 PM, Paul Lam <paul...@forward.co.uk<javascript:> > > wrote:
>> 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?
>> 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: