@Test public void edgesAreMovedToLeader() { Node n1 = getNode("http: Node n2 = getNode("http: Node n3 = getNode("http: Node n4 = getNode("http: Node n5 = getNode("http: assertThat(n1.getDegree(RelationshipType.withName("hasPhenotype")), is(0)); assertThat(n2.getDegree(RelationshipType.withName("hasPhenotype")), is(1)); assertThat(n3.getDegree(RelationshipType.withName("hasPhenotype")), is(1)); assertThat(n1.getDegree(IS_EQUIVALENT), is(1)); assertThat(n2.getDegree(IS_EQUIVALENT), is(2)); assertThat(n3.getDegree(IS_EQUIVALENT), is(1)); assertThat(n4.getDegree(), is(2)); assertThat(n5.getDegree(), is(2)); clique.run(); assertThat(n1.getDegree(RelationshipType.withName("hasPhenotype")), is(2)); assertThat(n2.getDegree(RelationshipType.withName("hasPhenotype")), is(0)); assertThat(n3.getDegree(RelationshipType.withName("hasPhenotype")), is(0)); assertThat(n1.getDegree(IS_EQUIVALENT), is(2)); assertThat(n2.getDegree(IS_EQUIVALENT), is(1)); assertThat(n3.getDegree(IS_EQUIVALENT), is(1)); assertThat(n4.getDegree(), is(3)); assertThat(n5.getDegree(), is(1)); assertThat(n1.hasLabel(Clique.CLIQUE_LEADER_LABEL), is(true)); assertThat(n2.hasLabel(Clique.CLIQUE_LEADER_LABEL), is(false)); assertThat(n3.hasLabel(Clique.CLIQUE_LEADER_LABEL), is(false)); assertThat(n4.hasLabel(Clique.CLIQUE_LEADER_LABEL), is(true)); assertThat(n5.hasLabel(Clique.CLIQUE_LEADER_LABEL), is(false)); }
@Override public void run() { logger.info("Starting clique merge"); Transaction tx = graphDb.beginTx(); ResourceIterable<Node> allNodes = graphDb.getAllNodes(); int size = Iterators.size(allNodes.iterator()); tx.success(); tx.close(); logger.info(size + " nodes left to process"); tx = graphDb.beginTx(); TraversalDescription traversalDescription = graphDb.traversalDescription().breadthFirst().uniqueness(Uniqueness.NODE_GLOBAL); for (RelationshipType rel : relationships) { traversalDescription = traversalDescription.relationships(rel, Direction.BOTH); } Set<Long> processedNodes = new HashSet<Long>(); for (Node baseNode : allNodes) { size -= 1; if (size % 100000 == 0) { logger.info(size + " nodes left to process"); } if (size % batchCommitSize == 0) { logger.fine("Node batch commit"); tx.success(); tx.close(); tx = graphDb.beginTx(); } logger.fine("Processing Node - " + baseNode.getProperty(NodeProperties.IRI)); if (!processedNodes.contains(baseNode.getId())) { List<Node> clique = new ArrayList<Node>(); for (Node node : traversalDescription.traverse(baseNode).nodes()) { logger.fine("-- " + node.getProperty(NodeProperties.IRI)); clique.add(node); processedNodes.add(node.getId()); } logger.fine("clique size: " + clique.size()); if (clique.size() == 1) { Node defactoLeader = clique.get(0); markAsCliqueLeader(defactoLeader); } else { Node leader = electCliqueLeader(clique, prefixLeaderPriority); markAsCliqueLeader(leader); clique.remove(leader); moveEdgesToLeader(leader, clique, tx); ensureLabel(leader, clique); } } } tx.success(); tx.close(); }
Clique implements Postprocessor { @Override public void run() { logger.info("Starting clique merge"); Transaction tx = graphDb.beginTx(); ResourceIterable<Node> allNodes = graphDb.getAllNodes(); int size = Iterators.size(allNodes.iterator()); tx.success(); tx.close(); logger.info(size + " nodes left to process"); tx = graphDb.beginTx(); TraversalDescription traversalDescription = graphDb.traversalDescription().breadthFirst().uniqueness(Uniqueness.NODE_GLOBAL); for (RelationshipType rel : relationships) { traversalDescription = traversalDescription.relationships(rel, Direction.BOTH); } Set<Long> processedNodes = new HashSet<Long>(); for (Node baseNode : allNodes) { size -= 1; if (size % 100000 == 0) { logger.info(size + " nodes left to process"); } if (size % batchCommitSize == 0) { logger.fine("Node batch commit"); tx.success(); tx.close(); tx = graphDb.beginTx(); } logger.fine("Processing Node - " + baseNode.getProperty(NodeProperties.IRI)); if (!processedNodes.contains(baseNode.getId())) { List<Node> clique = new ArrayList<Node>(); for (Node node : traversalDescription.traverse(baseNode).nodes()) { logger.fine("-- " + node.getProperty(NodeProperties.IRI)); clique.add(node); processedNodes.add(node.getId()); } logger.fine("clique size: " + clique.size()); if (clique.size() == 1) { Node defactoLeader = clique.get(0); markAsCliqueLeader(defactoLeader); } else { Node leader = electCliqueLeader(clique, prefixLeaderPriority); markAsCliqueLeader(leader); clique.remove(leader); moveEdgesToLeader(leader, clique, tx); ensureLabel(leader, clique); } } } tx.success(); tx.close(); } }
Clique implements Postprocessor { @Override public void run() { logger.info("Starting clique merge"); Transaction tx = graphDb.beginTx(); ResourceIterable<Node> allNodes = graphDb.getAllNodes(); int size = Iterators.size(allNodes.iterator()); tx.success(); tx.close(); logger.info(size + " nodes left to process"); tx = graphDb.beginTx(); TraversalDescription traversalDescription = graphDb.traversalDescription().breadthFirst().uniqueness(Uniqueness.NODE_GLOBAL); for (RelationshipType rel : relationships) { traversalDescription = traversalDescription.relationships(rel, Direction.BOTH); } Set<Long> processedNodes = new HashSet<Long>(); for (Node baseNode : allNodes) { size -= 1; if (size % 100000 == 0) { logger.info(size + " nodes left to process"); } if (size % batchCommitSize == 0) { logger.fine("Node batch commit"); tx.success(); tx.close(); tx = graphDb.beginTx(); } logger.fine("Processing Node - " + baseNode.getProperty(NodeProperties.IRI)); if (!processedNodes.contains(baseNode.getId())) { List<Node> clique = new ArrayList<Node>(); for (Node node : traversalDescription.traverse(baseNode).nodes()) { logger.fine("-- " + node.getProperty(NodeProperties.IRI)); clique.add(node); processedNodes.add(node.getId()); } logger.fine("clique size: " + clique.size()); if (clique.size() == 1) { Node defactoLeader = clique.get(0); markAsCliqueLeader(defactoLeader); } else { Node leader = electCliqueLeader(clique, prefixLeaderPriority); markAsCliqueLeader(leader); clique.remove(leader); moveEdgesToLeader(leader, clique, tx); ensureLabel(leader, clique); } } } tx.success(); tx.close(); } @Inject  Clique(GraphDatabaseService graphDb, CliqueConfiguration cliqueConfiguration); }
Clique implements Postprocessor { @Override public void run() { logger.info("Starting clique merge"); Transaction tx = graphDb.beginTx(); ResourceIterable<Node> allNodes = graphDb.getAllNodes(); int size = Iterators.size(allNodes.iterator()); tx.success(); tx.close(); logger.info(size + " nodes left to process"); tx = graphDb.beginTx(); TraversalDescription traversalDescription = graphDb.traversalDescription().breadthFirst().uniqueness(Uniqueness.NODE_GLOBAL); for (RelationshipType rel : relationships) { traversalDescription = traversalDescription.relationships(rel, Direction.BOTH); } Set<Long> processedNodes = new HashSet<Long>(); for (Node baseNode : allNodes) { size -= 1; if (size % 100000 == 0) { logger.info(size + " nodes left to process"); } if (size % batchCommitSize == 0) { logger.fine("Node batch commit"); tx.success(); tx.close(); tx = graphDb.beginTx(); } logger.fine("Processing Node - " + baseNode.getProperty(NodeProperties.IRI)); if (!processedNodes.contains(baseNode.getId())) { List<Node> clique = new ArrayList<Node>(); for (Node node : traversalDescription.traverse(baseNode).nodes()) { logger.fine("-- " + node.getProperty(NodeProperties.IRI)); clique.add(node); processedNodes.add(node.getId()); } logger.fine("clique size: " + clique.size()); if (clique.size() == 1) { Node defactoLeader = clique.get(0); markAsCliqueLeader(defactoLeader); } else { Node leader = electCliqueLeader(clique, prefixLeaderPriority); markAsCliqueLeader(leader); clique.remove(leader); moveEdgesToLeader(leader, clique, tx); ensureLabel(leader, clique); } } } tx.success(); tx.close(); } @Inject  Clique(GraphDatabaseService graphDb, CliqueConfiguration cliqueConfiguration); @Override void run(); Node electCliqueLeader(List<Node> clique, List<String> prefixLeaderPriority); }
Clique implements Postprocessor { @Override public void run() { logger.info("Starting clique merge"); Transaction tx = graphDb.beginTx(); ResourceIterable<Node> allNodes = graphDb.getAllNodes(); int size = Iterators.size(allNodes.iterator()); tx.success(); tx.close(); logger.info(size + " nodes left to process"); tx = graphDb.beginTx(); TraversalDescription traversalDescription = graphDb.traversalDescription().breadthFirst().uniqueness(Uniqueness.NODE_GLOBAL); for (RelationshipType rel : relationships) { traversalDescription = traversalDescription.relationships(rel, Direction.BOTH); } Set<Long> processedNodes = new HashSet<Long>(); for (Node baseNode : allNodes) { size -= 1; if (size % 100000 == 0) { logger.info(size + " nodes left to process"); } if (size % batchCommitSize == 0) { logger.fine("Node batch commit"); tx.success(); tx.close(); tx = graphDb.beginTx(); } logger.fine("Processing Node - " + baseNode.getProperty(NodeProperties.IRI)); if (!processedNodes.contains(baseNode.getId())) { List<Node> clique = new ArrayList<Node>(); for (Node node : traversalDescription.traverse(baseNode).nodes()) { logger.fine("-- " + node.getProperty(NodeProperties.IRI)); clique.add(node); processedNodes.add(node.getId()); } logger.fine("clique size: " + clique.size()); if (clique.size() == 1) { Node defactoLeader = clique.get(0); markAsCliqueLeader(defactoLeader); } else { Node leader = electCliqueLeader(clique, prefixLeaderPriority); markAsCliqueLeader(leader); clique.remove(leader); moveEdgesToLeader(leader, clique, tx); ensureLabel(leader, clique); } } } tx.success(); tx.close(); } @Inject  Clique(GraphDatabaseService graphDb, CliqueConfiguration cliqueConfiguration); @Override void run(); Node electCliqueLeader(List<Node> clique, List<String> prefixLeaderPriority);  }