Search in sources :

Example 1 with ExtractWalkEdgesFromHop

use of uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEdgesFromHop in project gaffer-doc by gchq.

the class ExtractWalkEdgesFromHopExample method extractSingleSetOfEdgesFromWalk.

public void extractSingleSetOfEdgesFromWalk() {
    // ---------------------------------------------------------
    final ExtractWalkEdgesFromHop function = new ExtractWalkEdgesFromHop(1);
    // ---------------------------------------------------------
    runExample(function, null, new Walk.Builder().entity(new Entity.Builder().group("BasicEntity").vertex("A").build()).edge(new Edge.Builder().group("BasicEdge").source("A").dest("B").directed(true).build()).entity(new Entity.Builder().group("BasicEntity").vertex("B").build()).edges(new Edge.Builder().group("BasicEdge").source("B").dest("C").directed(true).build(), new Edge.Builder().group("EnhancedEdge").source("B").dest("C").directed(true).build()).entity(new Entity.Builder().group("BasicEntity").vertex("C").build()).edge(new Edge.Builder().group("BasicEdge").source("C").dest("A").directed(true).build()).entity(new Entity.Builder().group("BasicEntity").vertex("A").build()).build());
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) ExtractWalkEdgesFromHop(uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEdgesFromHop) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 2 with ExtractWalkEdgesFromHop

use of uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEdgesFromHop 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)

Aggregations

Walk (uk.gov.gchq.gaffer.data.graph.Walk)2 ExtractWalkEdgesFromHop (uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEdgesFromHop)2 Set (java.util.Set)1 Test (org.junit.jupiter.api.Test)1 Edge (uk.gov.gchq.gaffer.data.element.Edge)1 Map (uk.gov.gchq.gaffer.operation.impl.Map)1 ToSet (uk.gov.gchq.gaffer.operation.impl.output.ToSet)1 ToVertices (uk.gov.gchq.gaffer.operation.impl.output.ToVertices)1 OperationChainValidator (uk.gov.gchq.gaffer.store.operation.OperationChainValidator)1 OperationChainOptimiser (uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser)1 ValidationResult (uk.gov.gchq.koryphe.ValidationResult)1 FirstItem (uk.gov.gchq.koryphe.impl.function.FirstItem)1 IterableFunction (uk.gov.gchq.koryphe.impl.function.IterableFunction)1