@Override public boolean filter(Vertex v) throws Exception { if (v.hasProperty(PageRankSampling.SCALED_PAGE_RANK_SCORE_PROPERTY_KEY)) { double pr = v.getPropertyValue(PageRankSampling.SCALED_PAGE_RANK_SCORE_PROPERTY_KEY) .getDouble(); if (sampleGreaterThanThreshold) { return pr > threshold; } else { return pr <= threshold; } } else { return keepVerticesIfSameScore; } } }
@Override public boolean filter(Vertex v) throws Exception { if (v.hasProperty(PageRankSampling.SCALED_PAGE_RANK_SCORE_PROPERTY_KEY)) { double pr = v.getPropertyValue(PageRankSampling.SCALED_PAGE_RANK_SCORE_PROPERTY_KEY) .getDouble(); if (sampleGreaterThanThreshold) { return pr > threshold; } else { return pr <= threshold; } } else { return keepVerticesIfSameScore; } } }
/** * Converts a value of a lower domain numerical type to BigDecimal. * * @param value value * @param type type * * @return converted value */ private static BigDecimal bigDecimalValue(PropertyValue value, int type) { switch (type) { case SHORT: return BigDecimal.valueOf(value.getShort()); case INT: return BigDecimal.valueOf(value.getInt()); case LONG: return BigDecimal.valueOf(value.getLong()); case FLOAT: return BigDecimal.valueOf(value.getFloat()); default: return BigDecimal.valueOf(value.getDouble()); } }
@Override public GraphHead map(GraphHead graphHead) throws Exception { PropertyValue averageProperty = graphHead.getPropertyValue(propertyKeySumLocal); double sumLocal = averageProperty.isNull() ? 0.0 : averageProperty.getDouble(); long vertexCount = graphHead.getPropertyValue(propertyKeyVertexCount).getLong(); graphHead.setProperty(propertyKeyAverage, vertexCount == 0L ? 0.0 : (sumLocal / (double) vertexCount)); return graphHead; } }
@Override public GraphHead map(GraphHead graphHead) throws Exception { PropertyValue averageProperty = graphHead.getPropertyValue(propertyKeySumLocal); double sumLocal = averageProperty.isNull() ? 0.0 : averageProperty.getDouble(); long vertexCount = graphHead.getPropertyValue(propertyKeyVertexCount).getLong(); graphHead.setProperty(propertyKeyAverage, vertexCount == 0L ? 0.0 : (sumLocal / (double) vertexCount)); return graphHead; } }
@Override public void testNonConnectedGraph() throws Exception { validateGraphProperties(nonConnectedGraph); GraphHead head = nonConnectedGraph.getGraphHead().collect().get(0); double global = head.getPropertyValue(ClusteringCoefficientBase.PROPERTY_KEY_GLOBAL) .getDouble(); assertTrue("Wrong global value for not connected graph, should be 0 or NaN", Double.isNaN(global)); }
@Test public void testGetDouble() throws Exception { PropertyValue p = PropertyValue.create(DOUBLE_VAL_5); assertEquals(DOUBLE_VAL_5, p.getDouble(), 0); }
@Override public void testNonConnectedGraph() throws Exception { validateGraphProperties(nonConnectedGraph); GraphHead head = nonConnectedGraph.getGraphHead().collect().get(0); double global = head.getPropertyValue(ClusteringCoefficientBase.PROPERTY_KEY_GLOBAL) .getDouble(); assertTrue("Wrong global value for not connected graph, should be 0 or NaN", Double.isNaN(global)); }
@Override public void testFullyConnectedGraph() throws Exception { validateGraphProperties(fullGraph); GraphHead head = fullGraph.getGraphHead().collect().get(0); assertEquals("Wrong global value for fully connected graph, should be 1", 1d, head.getPropertyValue(ClusteringCoefficientBase.PROPERTY_KEY_GLOBAL).getDouble(), 0.0); }
@Override public void testFullyConnectedGraph() throws Exception { validateGraphProperties(fullGraph); GraphHead head = fullGraph.getGraphHead().collect().get(0); assertEquals("Wrong global value for fully connected graph, should be 1", 1d, head.getPropertyValue(ClusteringCoefficientBase.PROPERTY_KEY_GLOBAL).getDouble(), 0.0); }
@Test public void testSetDouble() throws Exception { PropertyValue p = new PropertyValue(); p.setDouble(DOUBLE_VAL_5); assertEquals(DOUBLE_VAL_5, p.getDouble(), 0); }
/** * Checks if the PageRank property exists and its value was initialized * * @param graph The result graph */ private void checkPageRankProperty(LogicalGraph graph) throws Exception { List<Vertex> vertices = graph.getVertices().collect(); for (Vertex vertex : vertices) { assertTrue(vertex.hasProperty(propertyKey)); assertTrue(vertex.getPropertyValue(propertyKey).getDouble() > 0d); } } }
/** * Test for a fully connected graph */ @Test public void testFullyConnectedGraph() throws Exception { LogicalGraph graph = loader.getLogicalGraphByVariable("clique"); LogicalGraph result = graph.callForGraph(new AverageClusteringCoefficient()); validateGraphProperties(result); GraphHead head = result.getGraphHead().collect().get(0); assertEquals("Wrong average value for fully connected graph, should be 1", 1d, head.getPropertyValue(AverageClusteringCoefficient.PROPERTY_KEY_AVERAGE) .getDouble(), 0.0); }
@Override public void testFullyConnectedGraph() throws Exception { validateGraphProperties(fullGraph); List<Vertex> vertices = fullGraph.getVertices().collect(); for (Vertex v : vertices) { assertEquals( "Wrong local value for clique-vertex '" + v.getId().toString() + "', should be 1", 1d, v.getPropertyValue(ClusteringCoefficientBase.PROPERTY_KEY_LOCAL).getDouble(), 0.0); } }
@Override public void testFullyConnectedGraph() throws Exception { validateGraphProperties(fullGraph); List<Vertex> vertices = fullGraph.getVertices().collect(); for (Vertex v : vertices) { assertEquals("Wrong local value for clique-vertex '" + v.getId().toString() + "', should be 1", 1d, v.getPropertyValue(ClusteringCoefficientBase.PROPERTY_KEY_LOCAL).getDouble(), 0.0); } }
/** * Test for a graph with no connections */ @Test public void testNonConnectedGraph() throws Exception { LogicalGraph graph = loader.getLogicalGraphByVariable("nonConnected"); LogicalGraph result = graph.callForGraph(new AverageClusteringCoefficient()); validateGraphProperties(result); GraphHead head = result.getGraphHead().collect().get(0); double average = head.getPropertyValue(AverageClusteringCoefficient.PROPERTY_KEY_AVERAGE) .getDouble(); assertEquals("Wrong average value for not connected graph, should be 0.0", 0.0, average, 0.0); }
/** * Test for a half connected graph */ @Test public void testHalfConnectedGraph() throws Exception { LogicalGraph graph = loader.getLogicalGraphByVariable("halfConnected"); LogicalGraph result = graph.callForGraph(new AverageClusteringCoefficient()); validateGraphProperties(result); GraphHead head = result.getGraphHead().collect().get(0); double average = head.getPropertyValue(AverageClusteringCoefficient.PROPERTY_KEY_AVERAGE) .getDouble(); assertEquals("graph has wrong average value, should be 0.2916", ((1d / 6d) + (1d / 2d) + (1d / 2d) + 0d) / 4d, average, 0.00001); }
@Override public void testNonConnectedGraph() throws Exception { validateGraphProperties(nonConnectedGraph); List<Vertex> vertices = nonConnectedGraph.getVertices().collect(); for (Vertex v : vertices) { assertEquals( "Wrong local value for not connected vertex: " + v.getId().toString() + ", should be 0", 0d, v.getPropertyValue(ClusteringCoefficientBase.PROPERTY_KEY_LOCAL).getDouble(), 0.0); } }
@Override public void testNonConnectedGraph() throws Exception { validateGraphProperties(nonConnectedGraph); List<Vertex> vertices = nonConnectedGraph.getVertices().collect(); for (Vertex v : vertices) { assertEquals( "Wrong local value for not connected vertex: " + v.getId().toString() + ", should be 0", 0d, v.getPropertyValue(ClusteringCoefficientBase.PROPERTY_KEY_LOCAL).getDouble(), 0.0); } }
@Override public Edge<GradoopId, Double> map(org.gradoop.common.model.impl.pojo.Edge epgmEdge) throws Exception { reuseEdge.setSource(epgmEdge.getSourceId()); reuseEdge.setTarget(epgmEdge.getTargetId()); //cast incoming numeric value to double PropertyValue value = epgmEdge.getPropertyValue(propertyKey); if (value.isDouble()) { reuseEdge.setValue(value.getDouble()); } else if (value.isFloat()) { reuseEdge.setValue((double) value.getFloat()); } else if (value.isInt()) { reuseEdge.setValue((double) value.getInt()); } else if (value.isLong()) { reuseEdge.setValue((double) value.getLong()); } return reuseEdge; } }