Search in sources :

Example 16 with Walk

use of uk.gov.gchq.gaffer.data.graph.Walk in project Gaffer by gchq.

the class MapHandlerTest method shouldProcessWalksWithEdgeExtraction.

@Test
public void shouldProcessWalksWithEdgeExtraction() throws OperationException {
    // Given
    final Iterable<Walk> walks = Arrays.asList(walk, walk1);
    final Map<Iterable<Walk>, Iterable<Edge>> map = new Map.Builder<Iterable<Walk>>().input(walks).first(new IterableFunction.Builder<Walk>().first(new ExtractWalkEdgesFromHop(1)).then(new FirstItem<>()).build()).build();
    final ToVertices toVertices = new ToVertices.Builder().edgeVertices(ToVertices.EdgeVertices.SOURCE).build();
    final ToSet<Object> toSet = new ToSet<>();
    final OperationChain<Set<?>> opChain = new OperationChain.Builder().first(map).then(toVertices).then(toSet).build();
    final OperationChainValidator opChainValidator = mock(OperationChainValidator.class);
    final List<OperationChainOptimiser> opChainOptimisers = Collections.emptyList();
    given(opChainValidator.validate(any(), any(), any())).willReturn(new ValidationResult());
    final OperationChainHandler<Set<?>> opChainHandler = new OperationChainHandler<>(opChainValidator, opChainOptimisers);
    given(store.handleOperation(map, context)).willReturn(Arrays.asList(EDGE_BC, EDGE_BD));
    given(store.handleOperation(toVertices, context)).willReturn(Arrays.asList("B", "B"));
    given(store.handleOperation(toSet, context)).willReturn(Sets.newHashSet("B", "B"));
    // When
    final Iterable<?> results = opChainHandler.doOperation(opChain, context, store);
    // Then
    assertThat((Iterable<String>) results).contains("B");
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) ToSet(uk.gov.gchq.gaffer.operation.impl.output.ToSet) Set(java.util.Set) ToVertices(uk.gov.gchq.gaffer.operation.impl.output.ToVertices) OperationChainValidator(uk.gov.gchq.gaffer.store.operation.OperationChainValidator) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) OperationChainOptimiser(uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser) ExtractWalkEdgesFromHop(uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEdgesFromHop) ToSet(uk.gov.gchq.gaffer.operation.impl.output.ToSet) IterableFunction(uk.gov.gchq.koryphe.impl.function.IterableFunction) FirstItem(uk.gov.gchq.koryphe.impl.function.FirstItem) Map(uk.gov.gchq.gaffer.operation.impl.Map) Test(org.junit.jupiter.api.Test)

Example 17 with Walk

use of uk.gov.gchq.gaffer.data.graph.Walk in project Gaffer by gchq.

the class GetWalksHandler method walk.

private List<Walk> walk(final Object curr, final Object prev, final GraphWindow graphWindow, final LinkedList<Set<Edge>> edgeQueue, final LinkedList<Set<Entity>> entityQueue, final int hops, final boolean includePartial) {
    final List<Walk> walks = new ArrayList<>();
    if (null != prev && hops != edgeQueue.size()) {
        edgeQueue.offer(graphWindow.getAdjacencyMaps().get(edgeQueue.size()).getEdges(prev, curr));
    }
    entityQueue.offer(graphWindow.getEntityMaps().get(entityQueue.size()).get(curr));
    if (hops == edgeQueue.size()) {
        final Walk walk = buildWalk(edgeQueue, entityQueue);
        walks.add(walk);
    } else {
        final Set<Object> dests = graphWindow.getAdjacencyMaps().get(edgeQueue.size()).getDestinations(curr);
        if (dests.isEmpty()) {
            if (includePartial) {
                final Walk walk = buildWalk(edgeQueue, entityQueue);
                walks.add(walk);
            }
        } else {
            for (final Object obj : dests) {
                walks.addAll(walk(obj, curr, graphWindow, edgeQueue, entityQueue, hops, includePartial));
            }
        }
    }
    if (!edgeQueue.isEmpty()) {
        edgeQueue.pollLast();
    }
    if (!entityQueue.isEmpty()) {
        entityQueue.pollLast();
    }
    return walks;
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) ArrayList(java.util.ArrayList)

Example 18 with Walk

use of uk.gov.gchq.gaffer.data.graph.Walk in project Gaffer by gchq.

the class ExtractWalkEdgesFromHopTest method shouldReturnEdgesFromWalkObject.

@Test
public void shouldReturnEdgesFromWalkObject() {
    // Given
    final Function<Walk, Set<Edge>> function = new ExtractWalkEdgesFromHop(1);
    final Walk walk = new Walk.Builder().edge(EDGE_AB).entity(ENTITY_B).edge(EDGE_BC).entity(ENTITY_C).edge(EDGE_CA).build();
    // When
    final Set<Edge> results = function.apply(walk);
    // Then
    assertThat(results).containsExactly(EDGE_BC);
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) Set(java.util.Set) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.jupiter.api.Test)

Example 19 with Walk

use of uk.gov.gchq.gaffer.data.graph.Walk in project Gaffer by gchq.

the class ExtractWalkEntitiesFromHopTest method shouldReturnEdgesFromWalkObject.

@Test
public void shouldReturnEdgesFromWalkObject() {
    // Given
    final Function<Walk, Set<Entity>> function = new ExtractWalkEntitiesFromHop(2);
    final Walk walk = new Walk.Builder().edge(EDGE_AB).entity(ENTITY_B).edge(EDGE_BC).entity(ENTITY_C).edge(EDGE_CA).build();
    // When
    final Set<Entity> results = function.apply(walk);
    // Then
    assertThat(results).containsExactly(ENTITY_C);
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) Entity(uk.gov.gchq.gaffer.data.element.Entity) Set(java.util.Set) Test(org.junit.jupiter.api.Test)

Example 20 with Walk

use of uk.gov.gchq.gaffer.data.graph.Walk in project Gaffer by gchq.

the class ExtractWalkVertexTest method shouldReturnVertexFromWalkObject.

@Test
public void shouldReturnVertexFromWalkObject() {
    final Function<Walk, Object> function = new ExtractWalkVertex();
    final Walk walk = new Walk.Builder().entity(ENTITY_A).edge(EDGE_AB).entity(ENTITY_B).edge(EDGE_BC).entity(ENTITY_C).edge(EDGE_CA).entity(ENTITY_A).build();
    final Object result = function.apply(walk);
    assertEquals("A", result);
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) Test(org.junit.jupiter.api.Test)

Aggregations

Walk (uk.gov.gchq.gaffer.data.graph.Walk)36 Test (org.junit.Test)25 GetWalks (uk.gov.gchq.gaffer.operation.impl.GetWalks)19 Builder (uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder)19 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)19 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)17 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)13 Test (org.junit.jupiter.api.Test)7 Set (java.util.Set)6 Conditional (uk.gov.gchq.gaffer.operation.util.Conditional)5 CollectionContains (uk.gov.gchq.koryphe.impl.predicate.CollectionContains)5 IsMoreThan (uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)5 HashMap (java.util.HashMap)4 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)4 Map (uk.gov.gchq.gaffer.operation.impl.Map)4 Edge (uk.gov.gchq.gaffer.data.element.Edge)3 Entity (uk.gov.gchq.gaffer.data.element.Entity)3 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)3 OperationException (uk.gov.gchq.gaffer.operation.OperationException)3 List (java.util.List)2