use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project Gaffer by gchq.
the class GetElementsHandlerTest method testGetElementsByEntityIdWithViewRestrictedByGroupAndAPostTransformFilter.
@Test
public void testGetElementsByEntityIdWithViewRestrictedByGroupAndAPostTransformFilter() throws OperationException {
// Given
final Graph graph = GetAllElementsHandlerTest.getGraph();
final AddElements addElements = new AddElements.Builder().input(getElements()).build();
graph.execute(addElements, new User());
// When
final GetElements getElements = new GetElements.Builder().input(new EntitySeed("A")).view(new View.Builder().edge(GetAllElementsHandlerTest.BASIC_EDGE1, new ViewElementDefinition.Builder().transformer(new ElementTransformer.Builder().select(GetAllElementsHandlerTest.COUNT).execute(new ExampleTransform()).project(GetAllElementsHandlerTest.COUNT).build()).postTransformFilter(new ElementFilter.Builder().select(GetAllElementsHandlerTest.COUNT).execute(new IsMoreThan(50)).build()).build()).build()).build();
final CloseableIterable<? extends Element> results = graph.execute(getElements, new User());
// Then
final Set<Element> resultsSet = new HashSet<>();
Streams.toStream(results).forEach(resultsSet::add);
final Set<Element> expectedResults = new HashSet<>();
getElements().stream().filter(e -> e.getGroup().equals(GetAllElementsHandlerTest.BASIC_EDGE1)).filter(e -> ((Edge) e).getSource().equals("A") || ((Edge) e).getDestination().equals("A")).map(element -> {
element.putProperty(GetAllElementsHandlerTest.COUNT, ((Integer) element.getProperty(GetAllElementsHandlerTest.COUNT)) + ExampleTransform.INCREMENT_BY);
return element;
}).filter(element -> ((Integer) element.getProperty(GetAllElementsHandlerTest.COUNT)) > 50).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
}
use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project gaffer-doc by gchq.
the class OrExample method isLessThan2EqualTo5OrIsMoreThan10.
public void isLessThan2EqualTo5OrIsMoreThan10() {
// ---------------------------------------------------------
final Or function = new Or<>(new IsLessThan(2), new IsEqual(5), new IsMoreThan(10));
// ---------------------------------------------------------
runExample(function, "When using an Or predicate with a single selected value you can just use the constructor new Or(predicates))'", 1, 2, 3, 5, 15, 1L, 3L, 5L);
}
use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project gaffer-doc by gchq.
the class OrExample method firstItemIsLessThan2OrSecondItemIsMoreThan10.
public void firstItemIsLessThan2OrSecondItemIsMoreThan10() {
// ---------------------------------------------------------
final Or function = new Or.Builder().select(0).execute(new IsLessThan(2)).select(1).execute(new IsMoreThan(10)).build();
// ---------------------------------------------------------
runExample(function, "When using an Or predicate with multiple selected values, you need to use the Or.Builder to build your Or predicate, using .select() then .execute(). " + "When selecting values in the Or.Builder you need to refer to the position in the input array. I.e to use the first value use position 0 - select(0)." + "You can select multiple values to give to a predicate like isXLessThanY, this is achieved by passing 2 positions to the select method - select(0, 1)", new Tuple2<>(1, 15), new Tuple2<>(1, 1), new Tuple2<>(15, 15), new Tuple2<>(15, 1), new Tuple2<>(1L, 15L), new Tuple1<>(1));
}
use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project gaffer-doc by gchq.
the class Filtering method run.
@Override
public CloseableIterable<? extends Element> run() throws OperationException, IOException {
// [generate] Create some edges from the simple data file using our Road Use generator class
// ---------------------------------------------------------
final List<Element> elements = new ArrayList<>();
final RoadAndRoadUseElementGenerator dataGenerator = new RoadAndRoadUseElementGenerator();
for (final String line : IOUtils.readLines(StreamUtil.openStream(getClass(), dataPath))) {
Iterables.addAll(elements, dataGenerator._apply(line));
}
// ---------------------------------------------------------
print("Elements generated from the data file.");
for (final Element element : elements) {
print("GENERATED_EDGES", element.toString());
}
print("");
// [graph] Create a graph using our schema and store properties
// ---------------------------------------------------------
final Graph graph = new Graph.Builder().config(getDefaultGraphConfig()).addSchemas(StreamUtil.openStreams(getClass(), schemaPath)).storeProperties(getDefaultStoreProperties()).build();
// ---------------------------------------------------------
// [user] Create a user
// ---------------------------------------------------------
final User user = new User("user01");
// ---------------------------------------------------------
// [add] add the edges to the graph
// ---------------------------------------------------------
final AddElements addElements = new AddElements.Builder().input(elements).build();
graph.execute(addElements, user);
// ---------------------------------------------------------
print("The elements have been added.");
print("\nRoadUse edges related to vertex 10. The counts have been aggregated\n");
// [get simple] get all the edges that contain the vertex "10"
// ---------------------------------------------------------
final GetElements getElements = new GetElements.Builder().input(new EntitySeed("10")).view(new View.Builder().edge("RoadUse").build()).build();
final CloseableIterable<? extends Element> results = graph.execute(getElements, user);
// ---------------------------------------------------------
printJsonAndPython("GET_SIMPLE", getElements);
for (final Element e : results) {
print("GET_ELEMENTS_RESULT", e.toString());
}
// [get] rerun previous query with a filter to return only edges with a count more than 2
// ---------------------------------------------------------
final GetElements getEdgesWithCountMoreThan2 = new GetElements.Builder().input(new EntitySeed("10")).view(new View.Builder().edge("RoadUse", new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select("count").execute(new IsMoreThan(2L)).build()).build()).build()).build();
final CloseableIterable<? extends Element> filteredResults = graph.execute(getEdgesWithCountMoreThan2, user);
// ---------------------------------------------------------
printJsonAndPython("GET", getEdgesWithCountMoreThan2);
print("\nAll edges containing the vertex 10 with an aggregated count more than than 2\n");
for (final Element e : filteredResults) {
print("GET_ELEMENTS_WITH_COUNT_MORE_THAN_2_RESULT", e.toString());
}
return filteredResults;
}
use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project gaffer-doc by gchq.
the class IsMoreThanExample method isMoreThanALong5.
public void isMoreThanALong5() {
// ---------------------------------------------------------
final IsMoreThan function = new IsMoreThan(5L);
// ---------------------------------------------------------
runExample(function, null, 1, 1L, 5, 5L, 10, 10L, "abc");
}
Aggregations