Permalink
Browse files

adding new example on mutual friends and groups, enabled similar tags…

… example
  • Loading branch information...
1 parent 392f7e6 commit 3eb938bd4cec44e33081e4f64081f0cbe517f7c5 @peterneubauer committed Apr 23, 2012
@@ -63,6 +63,28 @@ include::find-people-based-on-similar-favorites.txt[]
:leveloffset: 1
+[[cypher-cookbook-mutual-friends-and-groups]]
+== Find people based on mutual friends and groups ==
+
+:leveloffset: 2
+
+include::cypher-mutualfriendsandgroups-graph.txt[]
+
+include::find-mutual-friends-and-groups.txt[]
+
+:leveloffset: 1
+
+[[cypher-cookbook-similar-tags]]
+== Find friends based on similar tagging ==
+
+:leveloffset: 2
+
+include::cypher-peoplesimilaritytags-graph.txt[]
+
+include::find-people-based-on-similar-tagged-favorties.txt[]
+
+:leveloffset: 1
+
[[cypher-cookbook-multirelational-social-network]]
== Multirelational (social) graphs ==
@@ -0,0 +1,55 @@
+/**
+ * Copyright (c) 2002-2012 "Neo Technology,"
+ * Network Engine for Objects in Lund AB [http://neotechnology.com]
+ *
+ * This file is part of Neo4j.
+ *
+ * Neo4j is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.neo4j.cypher.docgen.cookbook
+
+import org.junit.Test
+import org.junit.Assert._
+import org.neo4j.cypher.docgen.DocumentingTestBase
+import org.junit.Ignore
+import org.junit.Before
+
+
+class MutualFriendsAndGroupsTest extends DocumentingTestBase {
+ def graphDescription = List(
+ "Joe member_of_group Group1",
+ "Bob member_of_group Group1",
+ "Bill member_of_group Group1",
+ "Jill member_of_group Group1",
+ "Joe knows Bill",
+ "Jill knows Bill")
+
+ def section = "cookbook"
+
+ @Test def peopleSimilarityTags() {
+ testQuery(
+ title = "Find mutual friends and groups",
+ text = """In this scenario, the problem is to determine mutual friends and groups, if any,
+between persons. If no mutual groups or friends are found, there should be a 0 returned.""",
+ queryText = "START me=node(%Joe%), other=node(%Jill%, %Bob%) " +
+ "MATCH " +
+ "pGroups=me-[?:member_of_group]->mg<-[?:member_of_group]-other, " +
+ "pMutualFriends=me-[?:knows]->mf<-[?:knows]-other " +
+ "RETURN other.name as name, count(distinct pGroups) AS mutualGroups, count(distinct pMutualFriends) AS mutualFriends " +
+ "ORDER By mutualFriends DESC",
+ returns = "The list of mutual groups and friends for the given persons.",
+ (p) => assertEquals(List(Map("name" -> "Jill", "mutualGroups" -> 1, "mutualFriends" -> 1),
+ Map("name" -> "Bob", "mutualGroups" -> 1, "mutualFriends" -> 0)), p.toList))
+ }
+}
@@ -37,20 +37,21 @@ class PeopleSimilarityTagsTest extends DocumentingTestBase {
def section = "cookbook"
- @Test @Ignore def peopleSimilarityTags() {
+ @Test def peopleSimilarityTags() {
testQuery(
- title = "Find people based on tagged favorties",
- text = """To find out people similar to me based on taggings, an approach could be:
- 1. Determine the tags associated with what I favorite.
- 2. What else is tagged with those tags?
- 3. Who favorites items tagged with the same tags.
- 4. Sort the result by how many of the same things these people like.""",
- queryText = "START me=node:node_auto_index(name = \"Joe\") " +
- "MATCH me-[:favorite]->myFavorites-[:tagged]->tag<-[:tagged]-(theirFavorites)<-[:favorite]-people " +
- "RETURN me.name, people.name, tag.name, count(*) " +
- "ORDER BY count(*) DESC",
+ title = "Find people based on similar tagged favorties",
+ text = """To find out people similar to me based on taggings of their favorited items, an approach could be:
+* Determine the tags associated with what I favorite.
+* What else is tagged with those tags?
+* Who favorites items tagged with the same tags.
+* Sort the result by how many of the same things these people like.""",
+ queryText = "START me=node(%Joe%) " +
+ "MATCH me-[:favorite]->myFavorites-[:tagged]->tag<-[:tagged]-theirFavorites<-[:favorite]-people " +
+ "WHERE NOT(me=people) " +
+ "RETURN people.name as name, count(*) as similar_favs " +
+ "ORDER BY similar_favs DESC",
returns = "The list of possible friends ranked by them liking similar stuff that are not yet friends.",
- (p) => assertEquals(List(Map("person.name" -> "Sara", "count(stuff)" -> 2),
- Map("person.name" -> "Derrick", "count(stuff)" -> 1)), p.toList))
+ (p) => assertEquals(List(Map("name" -> "Sara", "similar_favs" -> 2),
+ Map("name" -> "Derrick", "similar_favs" -> 1)), p.toList))
}
}

0 comments on commit 3eb938b

Please sign in to comment.