Search in sources :

Example 1 with EntitySeedExtractor

use of uk.gov.gchq.gaffer.operation.data.generator.EntitySeedExtractor in project Gaffer by gchq.

the class EntitySeedExtractorTest method shouldGetDestinationFromEdge.

@Test
public void shouldGetDestinationFromEdge() {
    // Given
    final EntitySeedExtractor extractor = new EntitySeedExtractor(IdentifierType.DESTINATION);
    final Edge edge = new Edge(TestGroups.EDGE, "source", "destination", false);
    // When
    final EntitySeed seed = extractor.getObject(edge);
    // Then
    assertEquals("destination", seed.getVertex());
}
Also used : EntitySeedExtractor(uk.gov.gchq.gaffer.operation.data.generator.EntitySeedExtractor) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Example 2 with EntitySeedExtractor

use of uk.gov.gchq.gaffer.operation.data.generator.EntitySeedExtractor in project Gaffer by gchq.

the class EntitySeedExtractorTest method shouldThrowIllegalArgumentExceptionFromEdgeWhenIdTypeIsDirected.

@Test
public void shouldThrowIllegalArgumentExceptionFromEdgeWhenIdTypeIsDirected() {
    // Given
    final EntitySeedExtractor extractor = new EntitySeedExtractor(IdentifierType.DIRECTED);
    final Edge edge = new Edge(TestGroups.EDGE, "source", "destination", false);
    // When / Then
    try {
        extractor.getObject(edge);
        fail("Exception expected");
    } catch (final IllegalArgumentException e) {
        assertNotNull(e);
    }
}
Also used : EntitySeedExtractor(uk.gov.gchq.gaffer.operation.data.generator.EntitySeedExtractor) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Example 3 with EntitySeedExtractor

use of uk.gov.gchq.gaffer.operation.data.generator.EntitySeedExtractor 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;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) ExportToSet(uk.gov.gchq.gaffer.operation.impl.export.set.ExportToSet) GetSetExport(uk.gov.gchq.gaffer.operation.impl.export.set.GetSetExport) IsEdgeValidator(uk.gov.gchq.gaffer.data.IsEdgeValidator) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) DataGenerator7(uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator7) Graph(uk.gov.gchq.gaffer.graph.Graph) EntitySeedExtractor(uk.gov.gchq.gaffer.operation.data.generator.EntitySeedExtractor) GetEdges(uk.gov.gchq.gaffer.operation.impl.get.GetEdges) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) IsMoreThan(uk.gov.gchq.gaffer.function.filter.IsMoreThan) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 4 with EntitySeedExtractor

use of uk.gov.gchq.gaffer.operation.data.generator.EntitySeedExtractor in project Gaffer by gchq.

the class EntitySeedExtractorTest method shouldGetIdentifierFromEntity.

@Test
public void shouldGetIdentifierFromEntity() {
    // Given
    final EntitySeedExtractor extractor = new EntitySeedExtractor();
    final Entity entity = new Entity(TestGroups.ENTITY, "identifier");
    // When
    final EntitySeed seed = extractor.getObject(entity);
    // Then
    assertSame("identifier", seed.getVertex());
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) EntitySeedExtractor(uk.gov.gchq.gaffer.operation.data.generator.EntitySeedExtractor) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Test(org.junit.Test)

Example 5 with EntitySeedExtractor

use of uk.gov.gchq.gaffer.operation.data.generator.EntitySeedExtractor in project Gaffer by gchq.

the class EntitySeedExtractorTest method shouldGetSourceFromEdge.

@Test
public void shouldGetSourceFromEdge() {
    // Given
    final EntitySeedExtractor extractor = new EntitySeedExtractor(IdentifierType.SOURCE);
    final Edge edge = new Edge(TestGroups.EDGE, "source", "destination", false);
    // When
    final EntitySeed seed = extractor.getObject(edge);
    // Then
    assertEquals("source", seed.getVertex());
}
Also used : EntitySeedExtractor(uk.gov.gchq.gaffer.operation.data.generator.EntitySeedExtractor) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Aggregations

EntitySeedExtractor (uk.gov.gchq.gaffer.operation.data.generator.EntitySeedExtractor)6 Test (org.junit.Test)5 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)5 Edge (uk.gov.gchq.gaffer.data.element.Edge)4 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)2 Graph (uk.gov.gchq.gaffer.graph.Graph)2 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)2 GetEdges (uk.gov.gchq.gaffer.operation.impl.get.GetEdges)2 User (uk.gov.gchq.gaffer.user.User)2 SimpleEntityDataObject (uk.gov.gchq.gaffer.arrayliststore.data.SimpleEntityDataObject)1 SimpleEntityGenerator (uk.gov.gchq.gaffer.arrayliststore.data.generator.SimpleEntityGenerator)1 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)1 IsEdgeValidator (uk.gov.gchq.gaffer.data.IsEdgeValidator)1 Entity (uk.gov.gchq.gaffer.data.element.Entity)1 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)1 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)1 DataGenerator7 (uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator7)1 IsLessThan (uk.gov.gchq.gaffer.function.filter.IsLessThan)1 IsMoreThan (uk.gov.gchq.gaffer.function.filter.IsMoreThan)1 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)1