@Override public boolean filter(V v) throws Exception { return v.getPropertyValue(BusinessTransactionGraphs.SUPERTYPE_KEY) .getString().equals( BusinessTransactionGraphs.SUPERCLASS_VALUE_MASTER); } }
@Override public boolean filter(V v) throws Exception { return v.getPropertyValue(BusinessTransactionGraphs.SUPERTYPE_KEY) .getString().equals( BusinessTransactionGraphs.SUPERCLASS_VALUE_TRANSACTIONAL); } }
@Override public boolean filter(V v) throws Exception { return v.getPropertyValue(BusinessTransactionGraphs.SUPERTYPE_KEY) .getString().equals( BusinessTransactionGraphs.SUPERCLASS_VALUE_TRANSACTIONAL); } }
@Override public boolean filter(V v) throws Exception { return v.getPropertyValue(BusinessTransactionGraphs.SUPERTYPE_KEY) .getString().equals( BusinessTransactionGraphs.SUPERCLASS_VALUE_MASTER); } }
@Override public boolean test(T t) { PropertyValue value = t.getPropertyValue(getKey()); return value != null && value.isString() && getReg().matcher(value.getString()).matches(); }
/** * Relabel vertices and to drop properties. * * @param current current vertex * @param transformed copy of current except label and properties * @return current vertex with a new label depending on its type */ private static Vertex relabelVerticesAndRemoveProperties(Vertex current, Vertex transformed) { String label; if (current .getPropertyValue(BusinessTransactionGraphs.SUPERTYPE_KEY).getString() .equals(BusinessTransactionGraphs.SUPERCLASS_VALUE_TRANSACTIONAL)) { label = TRANSACTIONAL_PREFIX + current.getLabel(); } else { label = MASTER_PREFIX + current.getPropertyValue(SOURCEID_KEY).toString(); } transformed.setLabel(label); return transformed; }
@Test public void testGetString() throws Exception { PropertyValue p = PropertyValue.create(STRING_VAL_6); assertEquals(STRING_VAL_6, p.getString()); }
@Test public void testSetString() throws Exception { PropertyValue p = new PropertyValue(); p.setString(STRING_VAL_6); assertEquals(STRING_VAL_6, p.getString()); }
/** * Tests whether vertices are created properly even if not deduplicated. * * @throws Exception If the data could not be loaded or collected properly. */ @Test public void nonDeduplicationTest() throws Exception { LogicalGraph social = getSocialNetworkLoader().getLogicalGraph(); // this operation should create 6 vertices with the property values: // 'Berlin', 3 times 'Dresden', 2 times 'Leipzig' ExtractPropertyFromVertex extract = new ExtractPropertyFromVertex("Person", "city", "City", "name"); extract.setCondensation(false); LogicalGraph extractedGraph = social.callForGraph(extract); List<Vertex> vertices = new ArrayList<>(); extractedGraph .getVerticesByLabel("City") .output(new LocalCollectionOutputFormat<>(vertices)); getConfig().getExecutionEnvironment().execute(); Map<String, Integer> cityCountMap = new HashMap<>(); vertices.forEach(v -> cityCountMap.merge(v.getPropertyValue("name").getString(), 1, Integer::sum)); Assert.assertEquals(1, cityCountMap.get("Berlin").intValue()); Assert.assertEquals(3, cityCountMap.get("Dresden").intValue()); Assert.assertEquals(2, cityCountMap.get("Leipzig").intValue()); }
@Test public void createDefaultGraphTest() { GradoopId graphID = GradoopId.get(); String label = "A"; Properties props = Properties.create(); props.set("k1", "v1"); props.set("k2", "v2"); EPGMGraphHead graphHead = new GraphHeadFactory().initGraphHead(graphID, label, props); assertThat(graphHead.getId(), is(graphID)); assertEquals(label, graphHead.getLabel()); assertThat(graphHead.getPropertyCount(), is(2)); assertThat(graphHead.getPropertyValue("k1").getString(), Is.<Object>is("v1")); assertThat(graphHead.getPropertyValue("k2").getString(), Is.<Object>is("v2")); }
/** * Tests whether vertices are correctly deduplicated/condensed. * * @throws Exception If the data could not be loaded or collected properly. */ @Test public void cityDeduplicationTest() throws Exception { LogicalGraph social = getSocialNetworkLoader().getLogicalGraph(); // this operation should create 3 vertices with the property values: Berlin, Dresden, Leipzig // keep in mind that the default for condensation is 'true' UnaryGraphToGraphOperator extOne = new ExtractPropertyFromVertex("Person", "city", "City", "name"); LogicalGraph extOneGraph = social.callForGraph(extOne); List<Vertex> city = extOneGraph.getVerticesByLabel("City").collect(); Set<String> cityNames = new HashSet<>(); for (Vertex v : city) { String cityName = v.getPropertyValue("name").getString(); Assert.assertTrue(cityName.equals("Dresden") || cityName.equals("Berlin") || cityName.equals("Leipzig")); Assert.assertTrue(cityNames.add(cityName)); } Assert.assertEquals(3, cityNames.size()); // The number of edges should be the same as before. Assert.assertEquals(social.getEdges().count(), extOneGraph.getEdges().count()); }
/** * find all vertices by property equality * * @throws Throwable if error */ @Test public void vertexPropEquals() throws Throwable { doTest(TEST01, (loader, store, config) -> { List<Vertex> inputVertices = loader.getVertices().stream() .filter(it -> { assert it.getProperties() != null; return it.getProperties().get("gender") != null && Objects.equals(it.getProperties() .get("gender") .getString(), "f"); }) .collect(Collectors.toList()); List<Vertex> query = store .getVertexSpace( Query.elements() .fromAll() .where(AccumuloFilters.propEquals("gender", "f"))) .readRemainsAndClose(); GradoopTestUtils.validateEPGMElementCollections(inputVertices, query); }); }
/** * find all vertices by property value regex * * @throws Throwable if error */ @Test public void propRegex() throws Throwable { doTest(TEST03, (loader, store, config) -> { Pattern queryFormula = Pattern.compile("(Leipzig|Dresden)"); List<Vertex> inputVertices = loader.getVertices().stream() .filter(it -> { assert it.getProperties() != null; return it.getProperties().get("city") != null && it.getProperties().get("city").isString() && queryFormula .matcher(it.getProperties().get("city").getString()) .matches(); }) .collect(Collectors.toList()); List<Vertex> query = store .getVertexSpace( Query.elements() .fromAll() .where(AccumuloFilters.propReg("city", queryFormula))) .readRemainsAndClose(); GradoopTestUtils.validateEPGMElementCollections(inputVertices, query); }); }
/** * Tests whether list properties are extracted correctly. * * @throws Exception If collect doesn't work as expected. */ @Test public void listPropertyTest() throws Exception { VertexFactory vf = getConfig().getVertexFactory(); Vertex v1 = vf.createVertex("foo"); v1.setProperty("a", PropertyValue.create(Arrays.asList(PropertyValue.create("m"), PropertyValue.create("n")))); Vertex v2 = vf.createVertex("foo"); v2.setProperty("a", PropertyValue.create(Arrays.asList(PropertyValue.create("x"), PropertyValue.create("y"), PropertyValue.create("z")))); LogicalGraph input = getConfig().getLogicalGraphFactory().fromCollections(Arrays.asList(v1, v2), Collections.emptyList()); ExtractPropertyFromVertex ext = new ExtractPropertyFromVertex("foo", "a", "A", "key"); LogicalGraph output = input.callForGraph(ext); List<Vertex> createdVertices = new ArrayList<>(); output.getVertices() .filter(new ByLabel<>("A")) .output(new LocalCollectionOutputFormat<>(createdVertices)); input.getConfig().getExecutionEnvironment().execute(); ArrayList<String> properties = new ArrayList<>(); createdVertices.forEach(v -> properties.add(v.getPropertyValue("key").getString())); Assert.assertTrue(properties.containsAll(Arrays.asList("m", "n", "x", "y", "z"))); }
@Test public void createEdgePojoTest() { GradoopId edgeId = GradoopId.get(); GradoopId sourceId = GradoopId.get(); GradoopId targetId = GradoopId.get(); GradoopIdSet graphIds = GradoopIdSet .fromExisting(GradoopId.get(), GradoopId.get()); String label = "A"; Properties props = Properties.create(); props.set("k1", "v1"); props.set("k2", "v2"); EPGMEdge edge = new EdgeFactory() .initEdge(edgeId, label, sourceId, targetId, props, graphIds); assertThat(edge.getId(), is(edgeId)); assertEquals(label, edge.getLabel()); assertThat(edge.getSourceId(), is(sourceId)); assertThat(edge.getTargetId(), is(targetId)); assertThat(edge.getPropertyCount(), is(2)); assertThat(edge.getPropertyValue("k1").getString(), Is.<Object>is("v1")); assertThat(edge.getPropertyValue("k2").getString(), Is.<Object>is("v2")); assertThat(edge.getGraphCount(), is(2)); for (GradoopId graphId : graphIds) { assertTrue(edge.getGraphIds().contains(graphId)); } }
@Test public void createVertexPojoTest() { GradoopId vertexID = GradoopId.get(); String label = "A"; Properties props = Properties.create(); props.set("k1", "v1"); props.set("k2", "v2"); GradoopId graphId1 = GradoopId.get(); GradoopId graphId2 = GradoopId.get(); GradoopIdSet graphIds = new GradoopIdSet(); graphIds.add(graphId1); graphIds.add(graphId2); EPGMVertex vertex = new VertexFactory() .initVertex(vertexID, label, props, graphIds); assertThat(vertex.getId(), is(vertexID)); assertEquals(label, vertex.getLabel()); assertThat(vertex.getPropertyCount(), is(2)); assertThat(vertex.getPropertyValue("k1").getString(), Is.<Object>is("v1")); assertThat(vertex.getPropertyValue("k2").getString(), Is.<Object>is("v2")); assertThat(vertex.getGraphCount(), is(2)); assertTrue(vertex.getGraphIds().contains(graphId1)); assertTrue(vertex.getGraphIds().contains(graphId2)); }
@Test public void testAppendSingleIdAndProperties() { GradoopId id = GradoopId.get(); Embedding embedding = new Embedding(); embedding.add(id, PropertyValue.create("String"), PropertyValue.create(42)); assertEquals(1, embedding.size()); assertEquals(id, embedding.getId(0)); assertEquals("String", embedding.getProperty(0).getString()); assertEquals(42, embedding.getProperty(1).getInt()); }
@Test public void testAppendProjectionEntryToExistingEmbedding() { GradoopId id = GradoopId.get(); Embedding embedding = createEmbedding(4); embedding.add(id, PropertyValue.create("String"), PropertyValue.create(42)); assertEquals(5, embedding.size()); assertNotEquals(id, embedding.getId(3)); assertEquals(id, embedding.getId(4)); assertEquals("String", embedding.getProperty(0).getString()); assertEquals(42, embedding.getProperty(1).getInt()); }
/** * Returns the wrapped value as object. * * @return value or {@code null} if the value is empty */ public Object getObject() { return isBoolean() ? getBoolean() : isShort() ? getShort() : isInt() ? getInt() : isLong() ? getLong() : isFloat() ? getFloat() : isDouble() ? getDouble() : isString() ? getString() : isBigDecimal() ? getBigDecimal() : isGradoopId() ? getGradoopId() : isMap() ? getMap() : isList() ? getList() : isDate() ? getDate() : isTime() ? getTime() : isDateTime() ? getDateTime() : isSet() ? getSet() : null; } /**