@Test public void testMarkSmallClustersAsUnconnected() { final List<CanvasMatches> matchesList = new ArrayList<>(); final Set<String> unconnectedTileIds = new HashSet<>(); final String[][] testData = { {"A","B"},{"B","C"},{"C","D"},{"A","E"},{"B","F"},{"C","G"},{"D","H"},{"E","F"},{"F","G"},{"G","H"}, {"I","J"}, {"K","L"},{"L","M"},{"M","N"}, {"O","P"}, {"Q","R"},{"R","S"},{"Q","T"},{"R","U"},{"S","V"},{"T","U"},{"U","V"}, {"X","Y"} }; final String g = "group"; final double[][] p = {{8.0},{8.0}}; final double[][] q = {{9.0},{9.0}}; final double[] w = {1.0}; final Matches m = new Matches(p, q, w); for (final String[] pair : testData) { matchesList.add(new CanvasMatches(g, pair[0], g, pair[1], m)); } final UnconnectedTileRemovalClient.Parameters parameters = new UnconnectedTileRemovalClient.Parameters(); parameters.tileCluster.smallClusterFactor = 0.5; final Double z = 99.0; final SortedConnectedCanvasIdClusters clusters = new SortedConnectedCanvasIdClusters(matchesList); final List<Set<String>> sortedConnectedTileSets = clusters.getSortedConnectedTileIdSets(); final Set<String> keeperTileIds = new HashSet<>(); List<Set<String>> smallerRemainingClusters = UnconnectedTileRemovalClient.markSmallClustersAsUnconnected(parameters.tileCluster, z, sortedConnectedTileSets, keeperTileIds, unconnectedTileIds); final String[] expectedUnconnectedTiles = {"I", "J", "K", "L", "M", "N", "O", "P", "X", "Y"}; Assert.assertEquals("invalid number of small cluster tiles found ", expectedUnconnectedTiles.length, unconnectedTileIds.size()); for (final String tileId : expectedUnconnectedTiles) { Assert.assertTrue("tileId " + tileId + " should have been marked as unconnected", unconnectedTileIds.contains(tileId)); } Assert.assertEquals("invalid number of smaller remaining clusters returned", 1, smallerRemainingClusters.size()); parameters.tileCluster.maxSmallClusterSize = 1; smallerRemainingClusters = UnconnectedTileRemovalClient.markSmallClustersAsUnconnected(parameters.tileCluster, z, sortedConnectedTileSets, keeperTileIds, unconnectedTileIds); Assert.assertEquals("all inclusive test: invalid number of smaller remaining clusters returned", 5, smallerRemainingClusters.size()); }
static List<Set<String>> markSmallClustersAsUnconnected(final TileClusterParameters clusterParameters, final Double z, final List<Set<String>> sortedConnectedTileSets, final Set<String> keeperTileIds, final Set<String> unconnectedTileIds) { final List<Set<String>> smallerRemainingClusters = new ArrayList<>(); if (sortedConnectedTileSets.size() > 1) { final Set<String> largestCluster = sortedConnectedTileSets.get(0); final int maxSmallClusterSize = clusterParameters.getEffectiveMaxSmallClusterSize(largestCluster.size()); LOG.info("markSmallClustersAsUnconnected: for z {}, maxSmallClusterSize is {}", z, maxSmallClusterSize); final List<Integer> remainingClusterSizes = new ArrayList<>(); remainingClusterSizes.add(largestCluster.size()); for (int i = 1; i < sortedConnectedTileSets.size(); i++) { final Set<String> clusterTileIds = sortedConnectedTileSets.get(i); if (clusterTileIds.size() <= maxSmallClusterSize) { String keeperTileId = null; if (keeperTileIds.size() > 0) { for (final String tileId : clusterTileIds) { if (keeperTileIds.contains(tileId)) { keeperTileId = tileId; break; } } } if (keeperTileId == null) { unconnectedTileIds.addAll(clusterTileIds); LOG.info("markSmallClustersAsUnconnected: removed small {} tile cluster: {}", clusterTileIds.size(), getSortedSet(clusterTileIds)); } else { smallerRemainingClusters.add(clusterTileIds); remainingClusterSizes.add(clusterTileIds.size()); LOG.info("markSmallClustersAsUnconnected: keeping small {} tile cluster with tile {}: {}", clusterTileIds.size(), keeperTileId, getSortedSet(clusterTileIds)); } } else { smallerRemainingClusters.add(clusterTileIds); remainingClusterSizes.add(clusterTileIds.size()); } } LOG.info("markSmallClustersAsUnconnected: for z {}, {} clusters remain with sizes {}", z, remainingClusterSizes.size(), remainingClusterSizes); } return smallerRemainingClusters; }
UnconnectedTileRemovalClient { static List<Set<String>> markSmallClustersAsUnconnected(final TileClusterParameters clusterParameters, final Double z, final List<Set<String>> sortedConnectedTileSets, final Set<String> keeperTileIds, final Set<String> unconnectedTileIds) { final List<Set<String>> smallerRemainingClusters = new ArrayList<>(); if (sortedConnectedTileSets.size() > 1) { final Set<String> largestCluster = sortedConnectedTileSets.get(0); final int maxSmallClusterSize = clusterParameters.getEffectiveMaxSmallClusterSize(largestCluster.size()); LOG.info("markSmallClustersAsUnconnected: for z {}, maxSmallClusterSize is {}", z, maxSmallClusterSize); final List<Integer> remainingClusterSizes = new ArrayList<>(); remainingClusterSizes.add(largestCluster.size()); for (int i = 1; i < sortedConnectedTileSets.size(); i++) { final Set<String> clusterTileIds = sortedConnectedTileSets.get(i); if (clusterTileIds.size() <= maxSmallClusterSize) { String keeperTileId = null; if (keeperTileIds.size() > 0) { for (final String tileId : clusterTileIds) { if (keeperTileIds.contains(tileId)) { keeperTileId = tileId; break; } } } if (keeperTileId == null) { unconnectedTileIds.addAll(clusterTileIds); LOG.info("markSmallClustersAsUnconnected: removed small {} tile cluster: {}", clusterTileIds.size(), getSortedSet(clusterTileIds)); } else { smallerRemainingClusters.add(clusterTileIds); remainingClusterSizes.add(clusterTileIds.size()); LOG.info("markSmallClustersAsUnconnected: keeping small {} tile cluster with tile {}: {}", clusterTileIds.size(), keeperTileId, getSortedSet(clusterTileIds)); } } else { smallerRemainingClusters.add(clusterTileIds); remainingClusterSizes.add(clusterTileIds.size()); } } LOG.info("markSmallClustersAsUnconnected: for z {}, {} clusters remain with sizes {}", z, remainingClusterSizes.size(), remainingClusterSizes); } return smallerRemainingClusters; } }
UnconnectedTileRemovalClient { static List<Set<String>> markSmallClustersAsUnconnected(final TileClusterParameters clusterParameters, final Double z, final List<Set<String>> sortedConnectedTileSets, final Set<String> keeperTileIds, final Set<String> unconnectedTileIds) { final List<Set<String>> smallerRemainingClusters = new ArrayList<>(); if (sortedConnectedTileSets.size() > 1) { final Set<String> largestCluster = sortedConnectedTileSets.get(0); final int maxSmallClusterSize = clusterParameters.getEffectiveMaxSmallClusterSize(largestCluster.size()); LOG.info("markSmallClustersAsUnconnected: for z {}, maxSmallClusterSize is {}", z, maxSmallClusterSize); final List<Integer> remainingClusterSizes = new ArrayList<>(); remainingClusterSizes.add(largestCluster.size()); for (int i = 1; i < sortedConnectedTileSets.size(); i++) { final Set<String> clusterTileIds = sortedConnectedTileSets.get(i); if (clusterTileIds.size() <= maxSmallClusterSize) { String keeperTileId = null; if (keeperTileIds.size() > 0) { for (final String tileId : clusterTileIds) { if (keeperTileIds.contains(tileId)) { keeperTileId = tileId; break; } } } if (keeperTileId == null) { unconnectedTileIds.addAll(clusterTileIds); LOG.info("markSmallClustersAsUnconnected: removed small {} tile cluster: {}", clusterTileIds.size(), getSortedSet(clusterTileIds)); } else { smallerRemainingClusters.add(clusterTileIds); remainingClusterSizes.add(clusterTileIds.size()); LOG.info("markSmallClustersAsUnconnected: keeping small {} tile cluster with tile {}: {}", clusterTileIds.size(), keeperTileId, getSortedSet(clusterTileIds)); } } else { smallerRemainingClusters.add(clusterTileIds); remainingClusterSizes.add(clusterTileIds.size()); } } LOG.info("markSmallClustersAsUnconnected: for z {}, {} clusters remain with sizes {}", z, remainingClusterSizes.size(), remainingClusterSizes); } return smallerRemainingClusters; } private  UnconnectedTileRemovalClient(final Parameters parameters); }
UnconnectedTileRemovalClient { static List<Set<String>> markSmallClustersAsUnconnected(final TileClusterParameters clusterParameters, final Double z, final List<Set<String>> sortedConnectedTileSets, final Set<String> keeperTileIds, final Set<String> unconnectedTileIds) { final List<Set<String>> smallerRemainingClusters = new ArrayList<>(); if (sortedConnectedTileSets.size() > 1) { final Set<String> largestCluster = sortedConnectedTileSets.get(0); final int maxSmallClusterSize = clusterParameters.getEffectiveMaxSmallClusterSize(largestCluster.size()); LOG.info("markSmallClustersAsUnconnected: for z {}, maxSmallClusterSize is {}", z, maxSmallClusterSize); final List<Integer> remainingClusterSizes = new ArrayList<>(); remainingClusterSizes.add(largestCluster.size()); for (int i = 1; i < sortedConnectedTileSets.size(); i++) { final Set<String> clusterTileIds = sortedConnectedTileSets.get(i); if (clusterTileIds.size() <= maxSmallClusterSize) { String keeperTileId = null; if (keeperTileIds.size() > 0) { for (final String tileId : clusterTileIds) { if (keeperTileIds.contains(tileId)) { keeperTileId = tileId; break; } } } if (keeperTileId == null) { unconnectedTileIds.addAll(clusterTileIds); LOG.info("markSmallClustersAsUnconnected: removed small {} tile cluster: {}", clusterTileIds.size(), getSortedSet(clusterTileIds)); } else { smallerRemainingClusters.add(clusterTileIds); remainingClusterSizes.add(clusterTileIds.size()); LOG.info("markSmallClustersAsUnconnected: keeping small {} tile cluster with tile {}: {}", clusterTileIds.size(), keeperTileId, getSortedSet(clusterTileIds)); } } else { smallerRemainingClusters.add(clusterTileIds); remainingClusterSizes.add(clusterTileIds.size()); } } LOG.info("markSmallClustersAsUnconnected: for z {}, {} clusters remain with sizes {}", z, remainingClusterSizes.size(), remainingClusterSizes); } return smallerRemainingClusters; } private  UnconnectedTileRemovalClient(final Parameters parameters); static void main(final String[] args); }
UnconnectedTileRemovalClient { static List<Set<String>> markSmallClustersAsUnconnected(final TileClusterParameters clusterParameters, final Double z, final List<Set<String>> sortedConnectedTileSets, final Set<String> keeperTileIds, final Set<String> unconnectedTileIds) { final List<Set<String>> smallerRemainingClusters = new ArrayList<>(); if (sortedConnectedTileSets.size() > 1) { final Set<String> largestCluster = sortedConnectedTileSets.get(0); final int maxSmallClusterSize = clusterParameters.getEffectiveMaxSmallClusterSize(largestCluster.size()); LOG.info("markSmallClustersAsUnconnected: for z {}, maxSmallClusterSize is {}", z, maxSmallClusterSize); final List<Integer> remainingClusterSizes = new ArrayList<>(); remainingClusterSizes.add(largestCluster.size()); for (int i = 1; i < sortedConnectedTileSets.size(); i++) { final Set<String> clusterTileIds = sortedConnectedTileSets.get(i); if (clusterTileIds.size() <= maxSmallClusterSize) { String keeperTileId = null; if (keeperTileIds.size() > 0) { for (final String tileId : clusterTileIds) { if (keeperTileIds.contains(tileId)) { keeperTileId = tileId; break; } } } if (keeperTileId == null) { unconnectedTileIds.addAll(clusterTileIds); LOG.info("markSmallClustersAsUnconnected: removed small {} tile cluster: {}", clusterTileIds.size(), getSortedSet(clusterTileIds)); } else { smallerRemainingClusters.add(clusterTileIds); remainingClusterSizes.add(clusterTileIds.size()); LOG.info("markSmallClustersAsUnconnected: keeping small {} tile cluster with tile {}: {}", clusterTileIds.size(), keeperTileId, getSortedSet(clusterTileIds)); } } else { smallerRemainingClusters.add(clusterTileIds); remainingClusterSizes.add(clusterTileIds.size()); } } LOG.info("markSmallClustersAsUnconnected: for z {}, {} clusters remain with sizes {}", z, remainingClusterSizes.size(), remainingClusterSizes); } return smallerRemainingClusters; } private  UnconnectedTileRemovalClient(final Parameters parameters); static void main(final String[] args);  }