Search in sources :

Example 1 with RoadUseCsvGenerator

use of uk.gov.gchq.gaffer.doc.user.generator.RoadUseCsvGenerator in project gaffer-doc by gchq.

the class OperationChains method run.

@Override
public Iterable<? extends String> run() throws OperationException, IOException {
    // [graph] create a graph using our schema and store properties
    // ---------------------------------------------------------
    final Graph graph = new Graph.Builder().config(getDefaultGraphConfig()).addSchemas(StreamUtil.openStreams(getClass(), schemaPath)).storeProperties(getDefaultStoreProperties()).build();
    // ---------------------------------------------------------
    // [user] Create a user
    // ---------------------------------------------------------
    final User user = new User("user01");
    // ---------------------------------------------------------
    // [add] Create a data generator and 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<Void> addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new RoadAndRoadUseElementGenerator()).input(IOUtils.readLines(StreamUtil.openStream(getClass(), dataPath))).build()).then(new AddElements()).build();
    graph.execute(addOpChain, user);
    // ---------------------------------------------------------
    print("The elements have been added.");
    // [get] Create and execute an operation chain consisting of 2 operations:
    // GetAdjacentIds - starting at vertex M5 get all adjacent vertices (vertices at other end of outbound edges)
    // GetElements - get outbound edges
    // ---------------------------------------------------------
    final OperationChain<? extends Iterable<? extends Element>> opChain = new OperationChain.Builder().first(new GetAdjacentIds.Builder().input(new EntitySeed("M5")).inOutType(IncludeIncomingOutgoingType.OUTGOING).build()).then(new GetElements.Builder().inOutType(IncludeIncomingOutgoingType.OUTGOING).build()).build();
    final Iterable<? extends Element> results = graph.execute(opChain, user);
    // ---------------------------------------------------------
    print("\n2nd hop edges\n");
    for (final Element result : results) {
        print("RESULT", result.toString());
    }
    // [get and convert] Create and execute an operation chain consisting of 3 operations:
    // GetAdjacentIds - starting at vertex 1 get all adjacent vertices (vertices at other end of outbound edges)
    // GetElements - get outbound edges
    // GenerateObjects - convert the edges into csv
    // ---------------------------------------------------------
    final OperationChain<Iterable<? extends String>> opChainWithCSV = new OperationChain.Builder().first(new GetAdjacentIds.Builder().input(new EntitySeed("M5")).inOutType(IncludeIncomingOutgoingType.OUTGOING).build()).then(new GetElements.Builder().inOutType(IncludeIncomingOutgoingType.OUTGOING).build()).then(new GenerateObjects.Builder<String>().generator(new RoadUseCsvGenerator()).build()).build();
    final Iterable<? extends String> csvResults = graph.execute(opChainWithCSV, user);
    // ---------------------------------------------------------
    print("\n2nd hop edges converted back into comma separated strings.\n");
    for (final String result : csvResults) {
        print("CSV_RESULT", result);
    }
    return csvResults;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) RoadAndRoadUseElementGenerator(uk.gov.gchq.gaffer.doc.user.generator.RoadAndRoadUseElementGenerator) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) RoadUseCsvGenerator(uk.gov.gchq.gaffer.doc.user.generator.RoadUseCsvGenerator) Graph(uk.gov.gchq.gaffer.graph.Graph) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed)

Aggregations

Element (uk.gov.gchq.gaffer.data.element.Element)1 RoadAndRoadUseElementGenerator (uk.gov.gchq.gaffer.doc.user.generator.RoadAndRoadUseElementGenerator)1 RoadUseCsvGenerator (uk.gov.gchq.gaffer.doc.user.generator.RoadUseCsvGenerator)1 Graph (uk.gov.gchq.gaffer.graph.Graph)1 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)1 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)1 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)1 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)1 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)1 User (uk.gov.gchq.gaffer.user.User)1