@@ -51,7 +51,7 @@ public double adamicAdarSimilarity(@Name("node1") Node node1, @Name("node2") Nod
51
51
Direction direction = configuration .getDirection (Direction .BOTH );
52
52
53
53
Set <Node > neighbors = new NeighborsFinder (api ).findCommonNeighbors (node1 , node2 , relationshipType , direction );
54
- return neighbors .stream ().mapToDouble (nb -> 1.0 / Math .log (degree (relationshipType , direction , nb ))).sum ();
54
+ return neighbors .stream ().mapToDouble (nb -> 1.0 / Math .log (degree (nb , relationshipType , direction ))).sum ();
55
55
}
56
56
57
57
@ UserFunction ("algo.linkprediction.resourceAllocation" )
@@ -70,7 +70,7 @@ public double resourceAllocationSimilarity(@Name("node1") Node node1, @Name("nod
70
70
Direction direction = configuration .getDirection (Direction .BOTH );
71
71
72
72
Set <Node > neighbors = new NeighborsFinder (api ).findCommonNeighbors (node1 , node2 , relationshipType , direction );
73
- return neighbors .stream ().mapToDouble (nb -> 1.0 / degree (relationshipType , direction , nb )).sum ();
73
+ return neighbors .stream ().mapToDouble (nb -> 1.0 / degree (nb , relationshipType , direction )).sum ();
74
74
}
75
75
76
76
@ UserFunction ("algo.linkprediction.commonNeighbors" )
@@ -103,7 +103,7 @@ public double preferentialAttachment(@Name("node1") Node node1, @Name("node2") N
103
103
RelationshipType relationshipType = configuration .getRelationship ();
104
104
Direction direction = configuration .getDirection (Direction .BOTH );
105
105
106
- return getDegree (node1 , relationshipType , direction ) * getDegree (node2 , relationshipType , direction );
106
+ return degree (node1 , relationshipType , direction ) * degree (node2 , relationshipType , direction );
107
107
}
108
108
109
109
@ UserFunction ("algo.linkprediction.totalNeighbors" )
@@ -116,19 +116,10 @@ public double totalNeighbors(@Name("node1") Node node1, @Name("node2") Node node
116
116
Direction direction = configuration .getDirection (Direction .BOTH );
117
117
118
118
NeighborsFinder neighborsFinder = new NeighborsFinder (api );
119
-
120
- Set <Node > neighbors = neighborsFinder .findNeighbors (node1 , relationshipType , direction );
121
- neighbors .addAll (neighborsFinder .findNeighbors (node2 , relationshipType , direction ));
122
-
123
- return neighbors .size ();
119
+ return neighborsFinder .findNeighbors (node1 , node2 , relationshipType , direction ).size ();
124
120
}
125
121
126
- private int getDegree (Node node , RelationshipType relationshipType , Direction direction ) {
127
- return relationshipType == null ? node .getDegree (direction ) : node .getDegree (relationshipType , direction );
128
- }
129
-
130
-
131
- private int degree (RelationshipType relationshipType , Direction direction , Node node ) {
122
+ private int degree (Node node , RelationshipType relationshipType , Direction direction ) {
132
123
return relationshipType == null ? node .getDegree (direction ) : node .getDegree (relationshipType , direction );
133
124
}
134
125
0 commit comments