Search in sources :

Example 21 with Walk

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

the class ExtractWalkEdgesTest method shouldReturnEdgesFromWalkObject.

@Test
public void shouldReturnEdgesFromWalkObject() {
    // Given
    final Function<Walk, Iterable<Set<Edge>>> function = new ExtractWalkEdges();
    final Walk walk = new Walk.Builder().edge(EDGE_AB).entity(ENTITY_B).edge(EDGE_BC).entity(ENTITY_C).edge(EDGE_CA).build();
    // When
    final Iterable<Set<Edge>> results = function.apply(walk);
    // Then
    assertThat(results).containsOnly(Sets.newHashSet(EDGE_AB), Sets.newHashSet(EDGE_BC), Sets.newHashSet(EDGE_CA));
}
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 22 with Walk

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

the class GetWalksIT method shouldGetPathsWithWhileRepeat.

@Test
public void shouldGetPathsWithWhileRepeat() throws Exception {
    // Given
    final GetElements operation = new GetElements.Builder().directedType(DirectedType.DIRECTED).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().properties(TestPropertyNames.COUNT).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build();
    final GetWalks op = new GetWalks.Builder().input(seedA).operations(new While.Builder<>().operation(operation).maxRepeats(2).build()).build();
    // When
    final Iterable<Walk> results = graph.execute(op, getUser());
    // Then
    assertThat(getPaths(results)).isEqualTo("AED,ABC");
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) While(uk.gov.gchq.gaffer.operation.impl.While) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.Test)

Example 23 with Walk

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

the class GetWalksIT method shouldFilterWalksUsingWalkPredicateWithoutTransform.

@Test
public void shouldFilterWalksUsingWalkPredicateWithoutTransform() throws Exception {
    final Conditional conditional = new Conditional();
    conditional.setPredicate(new WalkPredicate());
    final Iterable<Walk> walks = executeGetWalksApplyingConditional(conditional);
    assertThat(getPaths(walks)).isEqualTo("AED");
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) Test(org.junit.Test)

Example 24 with Walk

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

the class GetWalksIT method shouldGetPartialPaths.

@Test
@TraitRequirement(StoreTrait.POST_AGGREGATION_FILTERING)
public void shouldGetPartialPaths() throws Exception {
    // Given
    final GetElements operation = new GetElements.Builder().directedType(DirectedType.DIRECTED).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().properties(TestPropertyNames.COUNT).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build();
    final OperationChain operationChain = new OperationChain.Builder().first(new GetElements.Builder().view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_1).execute(new IsMoreThan(3)).build()).build()).build()).build()).then(operation).build();
    final GetWalks op = new GetWalks.Builder().input(seedA).operations(operation, operationChain).includePartial().build();
    // When
    final Iterable<Walk> results = graph.execute(op, getUser());
    // Then
    assertThat(getPaths(results)).isEqualTo("AED,AB");
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 25 with Walk

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

the class GetWalksIT method getPaths.

private String getPaths(final Iterable<Walk> walks) {
    final StringBuilder sb = new StringBuilder();
    for (final Walk walk : walks) {
        sb.append(walk.getVerticesOrdered().stream().map(Object::toString).collect(Collectors.joining("")));
        sb.append(',');
    }
    if (sb.length() > 0) {
        sb.setLength(sb.length() - 1);
    }
    return sb.toString();
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk)

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