Filter

See javadoc - uk.gov.gchq.gaffer.operation.impl.function.Filter

Available since Gaffer version 1.0.0

Required fields

No required fields

Examples

All elements with a count more than 2

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.

Using this directed graph:


    --> 4 <--
  /     ^     \
 /      |      \
1  -->  2  -->  3
         \
           -->  5

Java
JSON
Full JSON
Python
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();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "NamedOperation",
    "input" : [ {
      "class" : "EntitySeed",
      "class" : "EntitySeed",
      "vertex" : 1
    } ],
    "operationName" : "1-hop"
  }, {
    "class" : "Filter",
    "globalElements" : {
      "predicates" : [ {
        "selection" : [ "count" ],
        "predicate" : {
          "class" : "IsMoreThan",
          "orEqualTo" : false,
          "value" : 2
        }
      } ]
    }
  } ]
}
{
  "class" : "uk.gov.gchq.gaffer.operation.OperationChain",
  "operations" : [ {
    "class" : "uk.gov.gchq.gaffer.named.operation.NamedOperation",
    "input" : [ {
      "class" : "uk.gov.gchq.gaffer.operation.data.EntitySeed",
      "class" : "uk.gov.gchq.gaffer.operation.data.EntitySeed",
      "vertex" : 1
    } ],
    "operationName" : "1-hop"
  }, {
    "class" : "uk.gov.gchq.gaffer.operation.impl.function.Filter",
    "globalElements" : {
      "predicates" : [ {
        "selection" : [ "count" ],
        "predicate" : {
          "class" : "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan",
          "orEqualTo" : false,
          "value" : 2
        }
      } ]
    }
  } ]
}
g.OperationChain( 
  operations=[ 
    g.NamedOperation( 
      input=[ 
        g.EntitySeed( 
          vertex=1 
        ) 
      ], 
      operation_name="1-hop" 
    ), 
    g.Filter( 
      global_elements=g.GlobalElementFilterDefinition( 
        predicates=[ 
          g.PredicateContext( 
            selection=[ 
              "count" 
            ], 
            predicate=g.IsMoreThan( 
              value=2, 
              or_equal_to=False 
            ) 
          ) 
        ] 
      ) 
    ) 
  ] 
)

Result:

Java
JSON
Entity[vertex=1,group=entity,properties=Properties[count=<java.lang.Integer>3]]
Edge[source=1,destination=2,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>3]]
[ {
  "class" : "uk.gov.gchq.gaffer.data.element.Entity",
  "group" : "entity",
  "vertex" : 1,
  "properties" : {
    "count" : 3
  }
}, {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 1,
  "destination" : 2,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 3
  }
} ]


All edges of type edge with count more than 2

Similar to the previous example but this will only return Edges with group 'edge' that have a count more than 2.

Using this directed graph:


    --> 4 <--
  /     ^     \
 /      |      \
1  -->  2  -->  3
         \
           -->  5

Java
JSON
Full JSON
Python
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();
{
  "class" : "OperationChain",
  "operations" : [ {
    "class" : "NamedOperation",
    "input" : [ {
      "class" : "EntitySeed",
      "class" : "EntitySeed",
      "vertex" : 1
    } ],
    "operationName" : "1-hop"
  }, {
    "class" : "Filter",
    "edges" : {
      "edge" : {
        "predicates" : [ {
          "selection" : [ "count" ],
          "predicate" : {
            "class" : "IsMoreThan",
            "orEqualTo" : false,
            "value" : 2
          }
        } ]
      }
    }
  } ]
}
{
  "class" : "uk.gov.gchq.gaffer.operation.OperationChain",
  "operations" : [ {
    "class" : "uk.gov.gchq.gaffer.named.operation.NamedOperation",
    "input" : [ {
      "class" : "uk.gov.gchq.gaffer.operation.data.EntitySeed",
      "class" : "uk.gov.gchq.gaffer.operation.data.EntitySeed",
      "vertex" : 1
    } ],
    "operationName" : "1-hop"
  }, {
    "class" : "uk.gov.gchq.gaffer.operation.impl.function.Filter",
    "edges" : {
      "edge" : {
        "predicates" : [ {
          "selection" : [ "count" ],
          "predicate" : {
            "class" : "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan",
            "orEqualTo" : false,
            "value" : 2
          }
        } ]
      }
    }
  } ]
}
g.OperationChain( 
  operations=[ 
    g.NamedOperation( 
      operation_name="1-hop", 
      input=[ 
        g.EntitySeed( 
          vertex=1 
        ) 
      ] 
    ), 
    g.Filter( 
      edges=[ 
        g.ElementFilterDefinition( 
          predicates=[ 
            g.PredicateContext( 
              selection=[ 
                "count" 
              ], 
              predicate=g.IsMoreThan( 
                or_equal_to=False, 
                value=2 
              ) 
            ) 
          ], 
          group="edge" 
        ) 
      ] 
    ) 
  ] 
)

Result:

Java
JSON
Edge[source=1,destination=2,directed=true,matchedVertex=SOURCE,group=edge,properties=Properties[count=<java.lang.Integer>3]]
[ {
  "class" : "uk.gov.gchq.gaffer.data.element.Edge",
  "group" : "edge",
  "source" : 1,
  "destination" : 2,
  "directed" : true,
  "matchedVertex" : "SOURCE",
  "properties" : {
    "count" : 3
  }
} ]


results matching ""

    No results matching ""