use of uk.gov.gchq.gaffer.operation.data.EdgeSeed in project Gaffer by gchq.
the class GetEntitiesTest method shouldSerialiseAndDeserialiseOperationWithEdgeSeed.
private void shouldSerialiseAndDeserialiseOperationWithEdgeSeed() throws SerialisationException {
// Given
final EdgeSeed seed1 = new EdgeSeed("source1", "destination1", true);
final EdgeSeed seed2 = new EdgeSeed("source2", "destination2", false);
final GetEntities op = new GetEntities(Arrays.asList(seed1, seed2));
// When
byte[] json = serialiser.serialise(op, true);
final GetEntities deserialisedOp = serialiser.deserialise(json, GetEntities.class);
// Then
final Iterator itr = deserialisedOp.getSeeds().iterator();
assertEquals(seed1, itr.next());
assertEquals(seed2, itr.next());
assertFalse(itr.hasNext());
}
use of uk.gov.gchq.gaffer.operation.data.EdgeSeed in project Gaffer by gchq.
the class GetEntitiesTest method shouldSetSeedMatchingTypeToRelatedWithEdgeSeed.
private void shouldSetSeedMatchingTypeToRelatedWithEdgeSeed() {
// Given
final EdgeSeed seed1 = new EdgeSeed("source1", "destination1", true);
// When
final GetEntities op = new GetEntities(Collections.singletonList(seed1));
// Then
assertEquals(GetOperation.SeedMatchingType.RELATED, op.getSeedMatching());
}
use of uk.gov.gchq.gaffer.operation.data.EdgeSeed in project Gaffer by gchq.
the class LoadAndQuery10 method run.
public Iterable<Entity> run() throws OperationException {
// [user] Create a user
// ---------------------------------------------------------
final User user = new User("user01");
// ---------------------------------------------------------
// [graph] create a graph using our schema and store properties
// ---------------------------------------------------------
final Graph graph = new Graph.Builder().addSchemas(getSchemas()).storeProperties(getStoreProperties()).build();
// ---------------------------------------------------------
// [add] add the edges to the graph
// ---------------------------------------------------------
final Set<String> dummyData = Collections.singleton("");
final OperationChain addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new DataGenerator10()).objects(dummyData).build()).then(new AddElements()).build();
graph.execute(addOpChain, user);
// ---------------------------------------------------------
log("Added an edge A-B 1000 times, each time with a LongsSketch containing a random long between 0 and 9.");
// [get] Get all edges
// ---------------------------------------------------------
Iterable<Edge> allEdges = graph.execute(new GetAllEdges(), user);
// ---------------------------------------------------------
log("\nAll edges:");
for (final Edge edge : allEdges) {
log("GET_ALL_EDGES_RESULT", edge.toString());
}
// [get frequencies of 1L and 9L] Get the edge A-B and print estimates of frequencies of 1L and 9L
// ---------------------------------------------------------
final GetEdges<EdgeSeed> query = new GetEdges.Builder<EdgeSeed>().addSeed(new EdgeSeed("A", "B", false)).build();
final Iterable<Edge> edges = graph.execute(query, user);
final Edge edge = edges.iterator().next();
final LongsSketch longsSketch = (LongsSketch) edge.getProperty("longsSketch");
final String estimates = "Edge A-B: 1L seen approximately " + longsSketch.getEstimate(1L) + " times, 9L seen approximately " + longsSketch.getEstimate(9L) + " times.";
// ---------------------------------------------------------
log("\nEdge A-B with estimates of the frequencies of 1 and 9");
log("GET_FREQUENCIES_OF_1_AND_9_FOR_EDGE_A_B", estimates);
return null;
}
use of uk.gov.gchq.gaffer.operation.data.EdgeSeed in project Gaffer by gchq.
the class LoadAndQuery11 method run.
public Iterable<Entity> run() throws OperationException {
// [user] Create a user
// ---------------------------------------------------------
final User user = new User("user01");
// ---------------------------------------------------------
// [graph] create a graph using our schema and store properties
// ---------------------------------------------------------
final Graph graph = new Graph.Builder().addSchemas(getSchemas()).storeProperties(getStoreProperties()).build();
// ---------------------------------------------------------
// [add] add the edges to the graph
// ---------------------------------------------------------
final Set<String> dummyData = Collections.singleton("");
final OperationChain addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new DataGenerator11()).objects(dummyData).build()).then(new AddElements()).build();
graph.execute(addOpChain, user);
// ---------------------------------------------------------
log("Added an edge A-B 1000 times, each time with a DoublesUnion containing a normally distributed" + " (mean 0, standard deviation 1) random double.");
// [get] Get all edges
// ---------------------------------------------------------
Iterable<Edge> allEdges = graph.execute(new GetAllEdges(), user);
// ---------------------------------------------------------
log("\nAll edges:");
for (final Edge edge : allEdges) {
log("GET_ALL_EDGES_RESULT", edge.toString());
}
// [get 0.25, 0.5, 0.75 percentiles] Get the edge A-B and print an estimate of the 0.25, 0.5 and 0.75 quantiles, i.e. the 25th, 50th and 75th percentiles
// ---------------------------------------------------------
final GetEdges<EdgeSeed> query = new GetEdges.Builder<EdgeSeed>().addSeed(new EdgeSeed("A", "B", false)).build();
final Iterable<Edge> edges = graph.execute(query, user);
final Edge edge = edges.iterator().next();
final DoublesUnion doublesUnion = (DoublesUnion) edge.getProperty("doublesUnion");
final double[] quantiles = doublesUnion.getResult().getQuantiles(new double[] { 0.25D, 0.5D, 0.75D });
final String quantilesEstimate = "Edge A-B with percentiles of double property - 25th percentile: " + quantiles[0] + ", 50th percentile: " + quantiles[1] + ", 75th percentile: " + quantiles[2];
// ---------------------------------------------------------
log("\nEdge A-B with an estimate of the median value");
log("GET_0.25,0.5,0.75_PERCENTILES_FOR_EDGE_A_B", quantilesEstimate);
// [get cdf] Get the edge A-B and print some values from the cumulative density function
// ---------------------------------------------------------
final GetEdges<EdgeSeed> query2 = new GetEdges.Builder<EdgeSeed>().addSeed(new EdgeSeed("A", "B", false)).build();
final Iterable<Edge> edges2 = graph.execute(query2, user);
final Edge edge2 = edges2.iterator().next();
final DoublesSketch doublesSketch2 = ((DoublesUnion) edge2.getProperty("doublesUnion")).getResult();
final double[] cdf = doublesSketch2.getCDF(new double[] { 0.0D, 1.0D, 2.0D });
final String cdfEstimate = "Edge A-B with CDF values at 0: " + cdf[0] + ", at 1: " + cdf[1] + ", at 2: " + cdf[2];
// ---------------------------------------------------------
log("\nEdge A-B with the cumulative density function values at 0, 1, 2");
log("GET_CDF_FOR_EDGE_A_B_RESULT", cdfEstimate);
return null;
}
use of uk.gov.gchq.gaffer.operation.data.EdgeSeed in project Gaffer by gchq.
the class GetJavaRDDOfElementsExample method getJavaRddOfElementsReturningEdgesOnly.
public void getJavaRddOfElementsReturningEdgesOnly(final JavaSparkContext sc, final Graph graph) throws OperationException {
ROOT_LOGGER.setLevel(Level.INFO);
log("#### get Java RDD of elements returning edges only\n");
printGraph();
ROOT_LOGGER.setLevel(Level.OFF);
final GetJavaRDDOfElements<ElementSeed> operation = new GetJavaRDDOfElements.Builder<>().addSeed(new EdgeSeed(1, 2, true)).addSeed(new EdgeSeed(2, 3, true)).includeEntities(false).javaSparkContext(sc).build();
final JavaRDD<Element> rdd = graph.execute(operation, new User("user01"));
final List<Element> elements = rdd.collect();
ROOT_LOGGER.setLevel(Level.INFO);
printJava("GetJavaRDDOfElements<ElementSeed> operation = new GetJavaRDDOfElements.Builder<>()\n" + " .addSeed(new EdgeSeed(1, 2, true))\n" + " .addSeed(new EdgeSeed(2, 3, true))\n" + " .includeEntities(false)\n" + " .javaSparkContext(sc)\n" + " .build();\n" + "JavaRDD<Element> rdd = graph.execute(operation, new User(\"user01\"));\n" + "List<Element> elements = rdd.collect();");
log("The results are:");
log("```");
for (final Element e : elements) {
log(e.toString());
}
log("```");
ROOT_LOGGER.setLevel(Level.OFF);
}
Aggregations