Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Commit aa3afcd

Browse files
committed
updating doc examples
1 parent 250340a commit aa3afcd

File tree

3 files changed

+54
-41
lines changed

3 files changed

+54
-41
lines changed

algo/src/test/java/org/neo4j/graphalgo/similarity/WeightedInputTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@
77

88
public class WeightedInputTest {
99

10+
@Test
11+
public void blah() {
12+
double[] weights1 = new double[]{3, 0, 9, 0, 5};
13+
double[] weights2 = new double[]{1, 2, 3, 4, 4, 4, 4, 5, 6};
14+
15+
WeightedInput input1 = new WeightedInput(1, weights1);
16+
WeightedInput input2 = new WeightedInput(2, weights2);
17+
18+
SimilarityResult similarityResult = input1.pearson(null, -1.0, input2);
19+
20+
assertEquals(1.0, similarityResult.similarity, 0.01);
21+
}
22+
1023
@Test
1124
public void pearsonNoCompression() {
1225
double[] weights1 = new double[]{1, 2, 3, 4, 4, 4, 4, 5, 6};

doc/asciidoc/scripts/similarity-pearson.cypher

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,38 @@ MERGE (matrix:Movie {name:'The Matrix'})
1010
MERGE (good_men:Movie {name:'A Few Good Men'})
1111
MERGE (top_gun:Movie {name:'Top Gun'})
1212
MERGE (jerry:Movie {name:'Jerry Maguire'})
13+
MERGE (gruffalo:Movie {name:'The Gruffalo'})
1314

1415
MERGE (zhen:Person {name: "Zhen"})
1516
MERGE (praveena:Person {name: "Praveena"})
1617
MERGE (michael:Person {name: "Michael"})
1718
MERGE (arya:Person {name: "Arya"})
1819
MERGE (karin:Person {name: "Karin"})
1920

20-
MERGE (praveena)-[:RATED {score: 9}]->(good_men)
21-
MERGE (praveena)-[:RATED {score: 5}]->(jerry)
22-
MERGE (praveena)-[:RATED {score: 3}]->(home_alone)
21+
MERGE (zhen)-[:RATED {score: 1}]->(home_alone)
22+
MERGE (zhen)-[:RATED {score: 2}]->(good_men)
23+
MERGE (zhen)-[:RATED {score: 3}]->(matrix)
24+
MERGE (zhen)-[:RATED {score: 6}]->(jerry)
2325

24-
MERGE (zhen)-[:RATED {score: 3}]->(home_alone)
25-
MERGE (zhen)-[:RATED {score: 5}]->(good_men)
26-
MERGE (zhen)-[:RATED {score: 9}]->(matrix)
26+
MERGE (praveena)-[:RATED {score: 6}]->(home_alone)
27+
MERGE (praveena)-[:RATED {score: 7}]->(good_men)
28+
MERGE (praveena)-[:RATED {score: 8}]->(matrix)
29+
MERGE (praveena)-[:RATED {score: 9}]->(jerry)
2730

28-
MERGE (michael)-[:RATED {score: 8}]->(home_alone)
29-
MERGE (michael)-[:RATED {score: 3}]->(matrix)
31+
MERGE (michael)-[:RATED {score: 7}]->(home_alone)
3032
MERGE (michael)-[:RATED {score: 9}]->(good_men)
33+
MERGE (michael)-[:RATED {score: 3}]->(jerry)
34+
MERGE (michael)-[:RATED {score: 4}]->(top_gun)
3135

32-
MERGE (arya)-[:RATED {score: 3}]->(top_gun)
33-
MERGE (arya)-[:RATED {score: 10}]->(matrix)
34-
MERGE (arya)-[:RATED {score: 1}]->(jerry)
36+
MERGE (arya)-[:RATED {score: 8}]->(top_gun)
37+
MERGE (arya)-[:RATED {score: 1}]->(matrix)
38+
MERGE (arya)-[:RATED {score: 10}]->(jerry)
39+
MERGE (arya)-[:RATED {score: 10}]->(gruffalo)
3540

3641
MERGE (karin)-[:RATED {score: 9}]->(top_gun)
3742
MERGE (karin)-[:RATED {score: 7}]->(matrix)
38-
MERGE (karin)-[:RATED {score: 2}]->(home_alone)
39-
40-
MERGE (michael)-[:RATED {score: 7}]->(home_alone)
41-
MERGE (michael)-[:RATED {score: 9}]->(good_men)
42-
MERGE (michael)-[:RATED {score: 3}]->(jerry)
43-
MERGE (michael)-[:RATED {score: 4}]->(top_gun)
43+
MERGE (karin)-[:RATED {score: 7}]->(home_alone)
44+
MERGE (karin)-[:RATED {score: 9}]->(gruffalo)
4445

4546
// end::create-sample-graph[]
4647

@@ -96,8 +97,8 @@ RETURN movie.name AS movie
9697

9798

9899
// tag::cypher-projection[]
99-
WITH "MATCH (person:Person)-[likes:LIKES]->(c)
100-
RETURN id(person) AS item, id(c) AS category, likes.score AS weight" AS query
100+
WITH "MATCH (person:Person)-[rated:RATED]->(c)
101+
RETURN id(person) AS item, id(c) AS category, rated.score AS weight" AS query
101102
CALL algo.similarity.pearson(query, {
102103
graph: 'cypher', topK: 1, similarityCutoff: 0.1, write:true
103104
})

doc/asciidoc/similarity-pearson.adoc

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,21 @@ include::scripts/similarity-pearson.cypher[tag=stream]
7777
[opts="header"]
7878
|===
7979
| `from` | `to` | `similarity`
80-
| "Zhen" | "Praveena" | 1.0
81-
| "Zhen" | "Karin" | 1.0
82-
| "Michael" | "Karin" | 0.9707253433941511
83-
| "Michael" | "Arya" | 0.5198613887753597
84-
| "Zhen" | "Michael" | 0.3711537444790451
85-
| "Zhen" | "Arya" | 0.0
86-
| "Praveena" | "Arya" | 0.0
87-
| "Praveena" | "Karin" | 0.0
88-
| "Praveena" | "Michael" | -0.8910421112136306
89-
| "Arya" | "Karin" | -1.0
80+
| "Arya" | "Zhen" | 1.0
81+
| "Arya" | "Praveena" | 1.0
82+
| "Arya" | "Karin" | 0.9773555548504417
83+
| "Zhen" | "Praveena" | 0.9561828874675149
84+
| "Karin" | "Zhen" | 0.0
85+
| "Karin" | "Praveena" | 0.0
86+
| "Praveena" | "Michael" | -0.7857142857142859
87+
| "Zhen" | "Michael" | -0.8660254037844386
88+
| "Arya" | "Michael" | -1.0
89+
| "Karin" | "Michael" | -1.0
90+
9091
|===
9192
// end::stream[]
9293

93-
Zhen and Praveena and Zhen and Karin are the most similar with a score of 1.0 - the maximum score.
94+
Zhen and Arya, and Praveena and Arya are the most similar with a score of 1.0 - the maximum score.
9495
We also have 5 pairs of users who are not similar at all.
9596
We'd probably want to filter those out, which we can do by passing in the `similarityCutoff` parameter.
9697

@@ -105,11 +106,10 @@ include::scripts/similarity-pearson.cypher[tag=stream-similarity-cutoff]
105106
[opts="header"]
106107
|===
107108
| `from` | `to` | `similarity`
108-
| "Zhen" | "Praveena" | 1.0
109-
| "Zhen" | "Karin" | 1.0
110-
| "Michael" | "Karin" | 0.9707253433941511
111-
| "Michael" | "Arya" | 0.5198613887753597
112-
| "Zhen" | "Michael" | 0.3711537444790451
109+
| "Arya" | "Zhen" | 1.0
110+
| "Arya" | "Praveena" | 1.0
111+
| "Arya" | "Karin" | 0.9773555548504417
112+
| "Zhen" | "Praveena" | 0.9561828874675149
113113
|===
114114
// end::stream-similarity-cutoff[]
115115

@@ -128,17 +128,16 @@ include::scripts/similarity-pearson.cypher[tag=stream-topk]
128128
[opts="header",cols="1,1,1"]
129129
|===
130130
| `from` | `to` | `similarity`
131-
| "Zhen" | "Praveena" | 1.0
132-
| "Praveena" | "Zhen" | 1.0
133-
| "Karin" | "Zhen" | 1.0
134-
| "Michael" | "Karin" | 0.9707253433941511
135-
| "Arya" | "Michael" | 0.5198613887753597
131+
| "Arya" | "Zhen" | 1.0
132+
| "Zhen" | "Arya" | 1.0
133+
| "Praveena" | "Arya" | 1.0
134+
| "Karin" | "Arya" | 0.9773555548504417
136135

137136
|===
138137
// end::stream-topk[]
139138

140139
These results will not be symmetrical.
141-
For example, the person most similar to Michael is Karin, but the person most similar to Karin is Zhen.
140+
For example, the person most similar to Karin is Arya, but the person most similar to Arya is Zhen.
142141

143142
.Parameters
144143
[opts="header",cols="1,1,1,1,4"]

0 commit comments

Comments
 (0)