Search in sources :

Example 1 with IsMoreThan

use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project gaffer-doc by gchq.

the class AddNamedViewExample method addNamedView.

public void addNamedView() {
    // ---------------------------------------------------------
    final AddNamedView op = new AddNamedView.Builder().name("isMoreThan10").description("example test NamedView").overwrite(true).view(new View.Builder().edge("testEdge", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("count").execute(new IsMoreThan(10)).build()).build()).build()).build();
    // ---------------------------------------------------------
    runExampleNoResult(op, null);
    try {
        getGraph().execute(new DeleteNamedView.Builder().name("isMoreThan10").build(), createContext());
    } catch (final OperationException e) {
        throw new RuntimeException("Unable to delete named view: isMoreThan", e);
    }
}
Also used : DeleteNamedView(uk.gov.gchq.gaffer.named.view.DeleteNamedView) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) AddNamedView(uk.gov.gchq.gaffer.named.view.AddNamedView) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 2 with IsMoreThan

use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project gaffer-doc by gchq.

the class FilterExample method allEdgesOfTypeEdgeWithCountMoreThan2.

public void allEdgesOfTypeEdgeWithCountMoreThan2() {
    // ---------------------------------------------------------
    final OperationChain<Iterable<? extends Element>> opChain = new OperationChain.Builder().first(new NamedOperation.Builder<EntitySeed, Iterable<? extends Element>>().name("1-hop").input(new EntitySeed(1)).build()).then(new Filter.Builder().edge("edge", new ElementFilter.Builder().select("count").execute(new IsMoreThan(2)).build()).build()).build();
    // ---------------------------------------------------------
    runExample(opChain, "Similar to the previous example but this will only return Edges with group 'edge' that have a count more than 2.");
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)

Example 3 with IsMoreThan

use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project gaffer-doc by gchq.

the class FilterExample method allElementsWithACountMoreThan2.

public void allElementsWithACountMoreThan2() {
    // ---------------------------------------------------------
    final OperationChain<Iterable<? extends Element>> opChain = new OperationChain.Builder().first(new NamedOperation.Builder<EntitySeed, Iterable<? extends Element>>().name("1-hop").input(new EntitySeed(1)).build()).then(new Filter.Builder().globalElements(new ElementFilter.Builder().select("count").execute(new IsMoreThan(2)).build()).build()).build();
    // ---------------------------------------------------------
    runExample(opChain, "The filter will only return elements (Entities and Edges) with a count more than 2. The results show the Edge 1->4 that has a count of 1 has been removed.");
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)

Example 4 with IsMoreThan

use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project gaffer-doc by gchq.

the class FullExample method run.

@Override
public Iterable<? extends String> run() throws OperationException, IOException {
    // [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");
    // ---------------------------------------------------------
    try (final CSVParser parser = CSVParser.parse(getClass().getResource("/FullExample/data.txt"), Charset.defaultCharset(), CSVFormat.DEFAULT.withFirstRecordAsHeader())) {
        final OperationChain<Void> addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<CSVRecord>().generator(new RoadTrafficCsvElementGenerator()).input(parser).build()).then(new AddElements()).build();
        graph.execute(addOpChain, user);
    }
    // ---------------------------------------------------------
    print("The elements have been added.");
    // [get] Get all road junctions in the South West that were heavily used by buses in the year 2000.
    // ---------------------------------------------------------
    final OperationChain<Iterable<? extends String>> opChain = new OperationChain.Builder().first(new GetAdjacentIds.Builder().input(new EntitySeed("South West")).view(new View.Builder().edge("RegionContainsLocation").build()).build()).then(new GetAdjacentIds.Builder().view(new View.Builder().edge("LocationContainsRoad").build()).build()).then(new ToSet<>()).then(new GetAdjacentIds.Builder().view(new View.Builder().edge("RoadHasJunction").build()).build()).then(new GetElements.Builder().view(new View.Builder().globalElements(new GlobalViewElementDefinition.Builder().groupBy().build()).entity("JunctionUse", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("startDate", "endDate").execute(new InDateRangeDual.Builder().start("2000/01/01").end("2001/01/01").build()).build()).postAggregationFilter(new ElementFilter.Builder().select("countByVehicleType").execute(new PredicateMap<>("BUS", new IsMoreThan(1000L))).build()).transientProperty("busCount", Long.class).transformer(new ElementTransformer.Builder().select("countByVehicleType").execute(new FreqMapExtractor("BUS")).project("busCount").build()).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build()).then(new Sort.Builder().comparators(new ElementPropertyComparator.Builder().groups("JunctionUse").property("busCount").reverse(true).build()).resultLimit(2).deduplicate(true).build()).then(new ToCsv.Builder().generator(new CsvGenerator.Builder().vertex("Junction").property("busCount", "Bus Count").build()).build()).build();
    // ---------------------------------------------------------
    printJsonAndPython("GET", opChain);
    final Iterable<? extends String> results = graph.execute(opChain, user);
    print("\nAll road junctions in the South West that were heavily used by buses in year 2000.");
    for (final String result : results) {
        print("RESULT", result);
    }
    return results;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ToSet(uk.gov.gchq.gaffer.operation.impl.output.ToSet) Sort(uk.gov.gchq.gaffer.operation.impl.compare.Sort) RoadTrafficCsvElementGenerator(uk.gov.gchq.gaffer.traffic.generator.RoadTrafficCsvElementGenerator) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) FreqMapExtractor(uk.gov.gchq.gaffer.types.function.FreqMapExtractor) CsvGenerator(uk.gov.gchq.gaffer.data.generator.CsvGenerator) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ElementPropertyComparator(uk.gov.gchq.gaffer.data.element.comparison.ElementPropertyComparator) InDateRangeDual(uk.gov.gchq.koryphe.impl.predicate.range.InDateRangeDual) Graph(uk.gov.gchq.gaffer.graph.Graph) CSVParser(org.apache.commons.csv.CSVParser) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)

Example 5 with IsMoreThan

use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project gaffer-doc by gchq.

the class TheBasics 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 RoadUseElementGenerator dataGenerator = new RoadUseElementGenerator();
    for (final String line : IOUtils.readLines(StreamUtil.openStream(getClass(), dataPath))) {
        elements.add(dataGenerator._apply(line));
    }
    // ---------------------------------------------------------
    print("Elements generated from the data file.");
    for (final Element element : elements) {
        print("GENERATED_EDGES", element.toString());
    }
    print("");
    Graph graph;
    // [graph from files] Create a graph using config, schema and store properties files
    // ---------------------------------------------------------
    graph = new Graph.Builder().config(StreamUtil.openStream(getClass(), graphConfigPath)).addSchemas(StreamUtil.openStreams(getClass(), schemaPath)).storeProperties(StreamUtil.openStream(getClass(), storePropertiesPath)).build();
    // ---------------------------------------------------------
    // [graph] Create a graph using config, schema and store properties from java
    // ---------------------------------------------------------
    final GraphConfig config = new GraphConfig.Builder().graphId(getClass().getSimpleName()).build();
    final Schema schema = new Schema.Builder().edge("RoadUse", new SchemaEdgeDefinition.Builder().description("A directed edge representing vehicles moving from junction A to junction B.").source("junction").destination("junction").directed("true").property("count", "count.long").build()).type("junction", new TypeDefinition.Builder().description("A road junction represented by a String.").clazz(String.class).build()).type("count.long", new TypeDefinition.Builder().description("A long count that must be greater than or equal to 0.").clazz(Long.class).validateFunctions(new IsMoreThan(0L, true)).aggregateFunction(new Sum()).build()).type("true", new TypeDefinition.Builder().description("A simple boolean that must always be true.").clazz(Boolean.class).validateFunctions(new IsTrue()).build()).build();
    final AccumuloProperties properties = new AccumuloProperties();
    properties.setStoreClass(SingleUseMockAccumuloStore.class);
    properties.setInstance("instance1");
    properties.setZookeepers("zookeeper1");
    properties.setUser("user01");
    properties.setPassword("password");
    graph = new Graph.Builder().config(config).addSchema(schema).storeProperties(properties).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.");
    // [get] Get all the edges that contain the vertex "10"
    // ---------------------------------------------------------
    final GetElements query = new GetElements.Builder().input(new EntitySeed("10")).view(new View.Builder().edge("RoadUse").build()).build();
    final CloseableIterable<? extends Element> results = graph.execute(query, user);
    // ---------------------------------------------------------
    print("\nAll edges containing the vertex 10. The counts have been aggregated.");
    for (final Element e : results) {
        print("GET_ELEMENTS_RESULT", e.toString());
    }
    return results;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) AccumuloProperties(uk.gov.gchq.gaffer.accumulostore.AccumuloProperties) Element(uk.gov.gchq.gaffer.data.element.Element) Schema(uk.gov.gchq.gaffer.store.schema.Schema) ArrayList(java.util.ArrayList) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) Sum(uk.gov.gchq.koryphe.impl.binaryoperator.Sum) Graph(uk.gov.gchq.gaffer.graph.Graph) IsTrue(uk.gov.gchq.koryphe.impl.predicate.IsTrue) RoadUseElementGenerator(uk.gov.gchq.gaffer.doc.user.generator.RoadUseElementGenerator) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)

Aggregations

IsMoreThan (uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)72 Test (org.junit.jupiter.api.Test)42 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)40 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)34 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)24 Element (uk.gov.gchq.gaffer.data.element.Element)22 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)22 Edge (uk.gov.gchq.gaffer.data.element.Edge)20 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)20 User (uk.gov.gchq.gaffer.user.User)20 Graph (uk.gov.gchq.gaffer.graph.Graph)19 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)19 ArrayList (java.util.ArrayList)18 HashSet (java.util.HashSet)16 Entity (uk.gov.gchq.gaffer.data.element.Entity)16 IsEqual (uk.gov.gchq.koryphe.impl.predicate.IsEqual)13 IsLessThan (uk.gov.gchq.koryphe.impl.predicate.IsLessThan)13 Set (java.util.Set)12 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)12 OperationException (uk.gov.gchq.gaffer.operation.OperationException)12