use of uk.gov.gchq.gaffer.data.IsEdgeValidator in project Gaffer by gchq.
the class LoadAndQuery7 method run.
public Iterable<Edge> 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 using an operation chain consisting of:
// generateElements - generating edges from the data (note these are directed edges)
// addElements - add the edges to the graph
// ---------------------------------------------------------
final OperationChain addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new DataGenerator7()).objects(DataUtils.loadData(getData())).build()).then(new AddElements()).build();
graph.execute(addOpChain, user);
// ---------------------------------------------------------
// Create some starting seeds for the sub graph.
final Iterable<EntitySeed> seeds = Lists.newArrayList(new EntitySeed("1"));
// Create a view to return only edges that have a count more than 1
// Note we could have used a different view for each hop in order to
// specify the edges we wish to hop down or to attempt to prevent caching
// duplicate edges.
final View view = new View.Builder().edge("data", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("count").execute(new IsMoreThan(1)).build()).build()).build();
// [extractor] Create a generator that will extract entity seeds
// This generator will extract just the destination vertices from edges
// and skip any entities.
// ---------------------------------------------------------
final EntitySeedExtractor destVerticesExtractor = new EntitySeedExtractor(new IsEdgeValidator(), new AlwaysValid<>(), true, IdentifierType.DESTINATION);
// ---------------------------------------------------------
// [get] Create a sub graph
// Start getting related edges with the given seeds.
// Then update the export with the results
// Between each hop we need to extract the destination vertices of the
// previous edges.
// Finally finish off by returning all the edges in the export.
// ---------------------------------------------------------
final OperationChain opChain = new OperationChain.Builder().first(new GetEdges.Builder<EntitySeed>().seeds(seeds).inOutType(IncludeIncomingOutgoingType.OUTGOING).view(view).build()).then(new ExportToSet()).then(new GenerateObjects<Edge, EntitySeed>(destVerticesExtractor)).then(new GetEdges.Builder<EntitySeed>().inOutType(IncludeIncomingOutgoingType.OUTGOING).view(view).build()).then(new ExportToSet()).then(new GetSetExport()).build();
final Iterable<Edge> subGraph = (Iterable<Edge>) graph.execute(opChain, user);
// ---------------------------------------------------------
log("\nSub graph:");
for (final Edge edge : subGraph) {
log("SUB_GRAPH", edge.toString());
}
return subGraph;
}
Aggregations