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");
}
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;
}
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);
}
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);
}
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);
}
Aggregations