patternCounts = patternCounts.stream()
.filter((pc) -> pc.getCount() > 1 || pc.getPattern().equals("1"))
.collect(Collectors.toList());
if(patternCounts.size() > 0) {
PatternCount patternCount = (PatternCount) patternCounts.toArray()[counter];
String pattern = (String) currentNode.get("pattern");
String newPattern = GeneratePattern(i, patternCount, pattern);
String newTemplate = GetTemplate(newPattern);
while (nodeManager.getOrCreateNode(graphManager, newPattern, db).hasProperty("matches") && counter < (patternCounts.size() - 1)) {
patternCount = (PatternCount) patternCounts.toArray()[counter];
pattern = (String) currentNode.get("pattern");
newPattern = GeneratePattern(i, patternCount, pattern);
newTemplate = GetTemplate(newPattern);
counter++;
}
Node leafNode = nodeManager.getOrCreateNode(graphManager, newPattern, db);
if (!leafNode.hasProperty("matches")) {
if (GraphManager.edgeCache.getIfPresent((String.valueOf(leafNode.getId()))) == null) {
GraphManager.edgeCache.put((String.valueOf(leafNode.getId())), (String.valueOf(leafNode.getId())));
}
if (GraphManager.edgeCache.getIfPresent(currentNode.get("id") + "->" + (int) leafNode.getId()) == null) {
patternRelationshipCache.getOrCreateRelationship((Long) currentNode.get("id"), leafNode.getId(), db, graphManager);
}
Long leafNodeId = leafNode.getId();
nodeManager.setNodeProperty(leafNodeId, "matches", patternCount.getDataNodes().size(), db);
nodeManager.setNodeProperty(leafNodeId, "threshold", GraphManager.MIN_THRESHOLD, db);
nodeManager.setNodeProperty(leafNodeId, "phrase", newTemplate, db);
// Bind new pattern to the data nodes it was generated from
patternCount.getDataNodes().forEach((dn) ->
{
String[] dataLabels = (String[]) dn.get("label");
for (String labelName : dataLabels) {
Node labelNode = nodeManager.getOrCreateNode(classNodeManager, labelName, db);
classRelationshipCache.getOrCreateRelationship(leafNode.getId(), labelNode.getId(), db, graphManager);