Class GraphFilter
- java.lang.Object
-
- org.apache.tinkerpop.gremlin.process.computer.GraphFilter
-
- All Implemented Interfaces:
Serializable
,Cloneable
public final class GraphFilter extends Object implements Cloneable, Serializable
GraphFilter is used byGraphComputer
implementations to prune the source graph data being loaded into the OLAP system. There are two types of filters: aVertex
filter and anEdge
filter. The vertex filter is aTraversal
that can only check the id, label, and properties of the vertex. The edge filter is aTraversal
that starts at the vertex are emits all legal incident edges. If no vertex filter is provided, then no vertices are filtered. If no edge filter is provided, then no edges are filtered. The use of a GraphFilter can greatly reduce the amount of data processed by theGraphComputer
. For instance, forg.V().count()
, there is no reason to load edges, and thus, the edge filter can bebothE().limit(0)
.- Author:
- Marko A. Rodriguez (http://markorodriguez.com)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GraphFilter.Legal
A enum denoting whether a particular result will be allowed or not.
-
Constructor Summary
Constructors Constructor Description GraphFilter()
GraphFilter(Computer computer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GraphFilter.Legal
checkEdgeLegality(Direction direction)
Get the legality of a particular edge direction.GraphFilter.Legal
checkEdgeLegality(Direction direction, String label)
Get the legality of a particular edge direction and label.GraphFilter
clone()
boolean
equals(Object o)
Traversal.Admin<Vertex,Edge>
getEdgeFilter()
Get the edge filter associated with this graph filter.Set<String>
getLegallyPositiveEdgeLabels(Direction direction)
For a particular edge directionality, get all theGraphFilter.Legal.YES
orGraphFilter.Legal.MAYBE
edge labels.Traversal.Admin<Vertex,Vertex>
getVertexFilter()
Get the vertex filter associated with this graph filter.Traversal.Admin<Vertex,? extends Property<?>>
getVertexPropertyFilter()
Get the vertex property filter associated with this graph filter.boolean
hasEdgeFilter()
Whether an edge filter has been defined.boolean
hasFilter()
Whether filters have been defined.int
hashCode()
boolean
hasVertexFilter()
Whether a vertex filter has been defined.boolean
hasVertexPropertyFilter()
Whether a vertex property filter has been defined.Iterator<Edge>
legalEdges(Vertex vertex)
Returns an iterator of legal edges incident to the provided vertex.boolean
legalVertex(Vertex vertex)
Returns true if the provided vertex meets the vertex-filter criteria.Iterator<? extends Property<?>>
legalVertexProperties(Vertex vertex)
Returns an iterator of legal vertex properties.void
setEdgeFilter(Traversal<Vertex,Edge> edgeFilter)
Set the filter for selecting edges from the source graph.void
setVertexFilter(Traversal<Vertex,Vertex> vertexFilter)
Set the filter for selecting vertices from the source graph.void
setVertexPropertyFilter(Traversal<Vertex,? extends Property<?>> vertexPropertyFilter)
Set the filter for selecting vertex properties from the vertices.String
toString()
-
-
-
Constructor Detail
-
GraphFilter
public GraphFilter()
-
GraphFilter
public GraphFilter(Computer computer)
-
-
Method Detail
-
setVertexFilter
public void setVertexFilter(Traversal<Vertex,Vertex> vertexFilter)
Set the filter for selecting vertices from the source graph. The vertex filter can only access the vertex, its properties, and its properties properties. Vertex filters can not access the incident edges of the vertex.- Parameters:
vertexFilter
- TheTraversal
that will either let the vertex pass or not.
-
setEdgeFilter
public void setEdgeFilter(Traversal<Vertex,Edge> edgeFilter)
Set the filter for selecting edges from the source graph. The edge filter can only access the local star graph (not adjacent vertices).- Parameters:
edgeFilter
- TheTraversal
that will generate the legal incident edges of the vertex.
-
setVertexPropertyFilter
public void setVertexPropertyFilter(Traversal<Vertex,? extends Property<?>> vertexPropertyFilter)
Set the filter for selecting vertex properties from the vertices.- Parameters:
vertexPropertyFilter
- TheTraversal
that will either let the vertex property pass or not.
-
legalVertex
public boolean legalVertex(Vertex vertex)
Returns true if the provided vertex meets the vertex-filter criteria. If no vertex filter is provided, then the vertex is considered legal.- Parameters:
vertex
- the vertex to test for legality- Returns:
- whether the vertex is
GraphFilter.Legal.YES
.
-
legalEdges
public Iterator<Edge> legalEdges(Vertex vertex)
Returns an iterator of legal edges incident to the provided vertex. If no edge filter is provided, then all incident edges are returned.- Parameters:
vertex
- the vertex whose legal edges are to be access.- Returns:
- an iterator of edges that are
GraphFilter.Legal.YES
.
-
legalVertexProperties
public Iterator<? extends Property<?>> legalVertexProperties(Vertex vertex)
Returns an iterator of legal vertex properties. If no vertex property filter is provided, then all vertex properties are returned.- Parameters:
vertex
- the vertex whose legal vertex properties are to be accessed.- Returns:
- an iterator of vertex properties that are
GraphFilter.Legal.YES
.
-
getVertexFilter
public final Traversal.Admin<Vertex,Vertex> getVertexFilter()
Get the vertex filter associated with this graph filter.- Returns:
- the vertex filter or null if no vertex filter was provided.
-
getEdgeFilter
public final Traversal.Admin<Vertex,Edge> getEdgeFilter()
Get the edge filter associated with this graph filter.- Returns:
- the edge filter or null if no edge filter was provided.
-
getVertexPropertyFilter
public Traversal.Admin<Vertex,? extends Property<?>> getVertexPropertyFilter()
Get the vertex property filter associated with this graph filter.- Returns:
- the vertex property filter or null if not provided.
-
hasFilter
public boolean hasFilter()
Whether filters have been defined.- Returns:
- true if either a vertex, edge filter, or vertex property filter has been provided.
-
hasEdgeFilter
public boolean hasEdgeFilter()
Whether an edge filter has been defined.- Returns:
- true if an edge filter was provided.
-
hasVertexFilter
public boolean hasVertexFilter()
Whether a vertex filter has been defined.- Returns:
- true if a vertex filter was provided.
-
hasVertexPropertyFilter
public boolean hasVertexPropertyFilter()
Whether a vertex property filter has been defined.- Returns:
- true if a vertex property filter was provided.
-
getLegallyPositiveEdgeLabels
public Set<String> getLegallyPositiveEdgeLabels(Direction direction)
For a particular edge directionality, get all theGraphFilter.Legal.YES
orGraphFilter.Legal.MAYBE
edge labels. If the label set containsnull
, then all edge labels for that direction are positively legal.- Parameters:
direction
- the direction to get the positively legal edge labels for.- Returns:
- the set of positively legal edge labels for the direction.
-
checkEdgeLegality
public GraphFilter.Legal checkEdgeLegality(Direction direction, String label)
Get the legality of a particular edge direction and label.- Parameters:
direction
- the direction of the edge.label
- the label of the edge.- Returns:
- the
GraphFilter.Legal
of the arguments.
-
checkEdgeLegality
public GraphFilter.Legal checkEdgeLegality(Direction direction)
Get the legality of a particular edge direction.- Parameters:
direction
- the direction of the edge.- Returns:
- the
GraphFilter.Legal
of the edge direction.
-
clone
public GraphFilter clone()
-
-