18
18
import org .neo4j .graphdb .Node ;
19
19
import org .neo4j .graphdb .Path ;
20
20
import org .neo4j .graphdb .PathExpanders ;
21
+ import org .neo4j .graphdb .ResourceIterable ;
21
22
import org .neo4j .graphdb .traversal .Evaluation ;
22
- import org .neo4j .graphdb .traversal .TraversalDescription ;
23
23
import org .neo4j .helpers .collection .IteratorUtil ;
24
24
25
25
import java .util .ArrayList ;
@@ -63,7 +63,9 @@ public AllClustersQuery(int minRank, int maxRank, int threshold,
63
63
this .is = is ;
64
64
}
65
65
66
- private TraversalDescription untilMaxRank (GraphDatabaseService service ) {
66
+ private ResourceIterable <Node > untilMaxRank (GraphDatabaseService service ) {
67
+ Iterable <Node > start = IteratorUtil .loop (service .findNodes (NodeLabels .NODE ,
68
+ SequenceProperties .RANK .name (), minRank ));
67
69
return service .traversalDescription ()
68
70
.breadthFirst ()
69
71
.evaluator (path -> {
@@ -74,23 +76,28 @@ private TraversalDescription untilMaxRank(GraphDatabaseService service) {
74
76
return Evaluation .EXCLUDE_AND_PRUNE ;
75
77
}
76
78
})
77
- .relationships (RelTypes .NEXT , Direction .OUTGOING );
79
+ .relationships (RelTypes .NEXT , Direction .OUTGOING )
80
+ .traverse (start ).nodes ();
78
81
}
79
82
80
83
@ Override
81
84
public Map <Integer , List <Cluster >> execute (GraphDatabaseService service ) {
85
+ Map <Integer , List <Cluster >> individualNodes = new HashMap <>();
82
86
Set <Long > bubbleSourcesNested = new HashSet <>();
83
87
Set <Long > bubbleSourcesToCluster = new HashSet <>();
84
88
Set <Long > bubbleSourcesToKeepIntact = new HashSet <>();
85
- Iterable <Node > start = IteratorUtil .loop (service .findNodes (NodeLabels .NODE ,
86
- SequenceProperties .RANK .name (), minRank ));
87
- for (Node n : untilMaxRank (service ).traverse (start ).nodes ()) {
89
+ for (Node n : untilMaxRank (service )) {
88
90
if (n .hasLabel (NodeLabels .BUBBLE_SOURCE )) {
89
91
bubbleSourcesToCluster .add (n .getId ());
90
- if (((long []) n .getProperty (BubbleProperties .BUBBLE_SOURCE_IDS .name ()))
91
- .length > 0 ) {
92
+ if (getBubbleIDs (n ).length > 0 ) {
92
93
bubbleSourcesNested .add (n .getId ());
93
94
}
95
+ } else {
96
+ if (getBubbleIDs (n ).length == 0 ) {
97
+ Cluster individualNode = createSingletonCluster (service , n );
98
+ individualNodes .put (individualNode .getStartRank (),
99
+ Collections .singletonList (individualNode ));
100
+ }
94
101
}
95
102
int interestingness = is .compute (new Neo4jScoreContainer (n ));
96
103
n .setProperty (SequenceProperties .INTERESTINGNESS .name (), interestingness );
@@ -103,7 +110,12 @@ public Map<Integer, List<Cluster>> execute(GraphDatabaseService service) {
103
110
}
104
111
}
105
112
bubbleSourcesToCluster .removeAll (bubbleSourcesNested );
106
- return cluster (service , bubbleSourcesToCluster , bubbleSourcesToKeepIntact );
113
+ return mergeMaps (Stream .of (individualNodes ,
114
+ cluster (service , bubbleSourcesToCluster , bubbleSourcesToKeepIntact )));
115
+ }
116
+
117
+ private long [] getBubbleIDs (Node n ) {
118
+ return (long []) n .getProperty (BubbleProperties .BUBBLE_SOURCE_IDS .name ());
107
119
}
108
120
109
121
private Map <Integer , List <Cluster >> cluster (GraphDatabaseService service ,
0 commit comments