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 byGraphComputerimplementations to prune the source graph data being loaded into the OLAP system. There are two types of filters: aVertexfilter and anEdgefilter. The vertex filter is aTraversalthat can only check the id, label, and properties of the vertex. The edge filter is aTraversalthat 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 classGraphFilter.LegalA 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.LegalcheckEdgeLegality(Direction direction)Get the legality of a particular edge direction.GraphFilter.LegalcheckEdgeLegality(Direction direction, String label)Get the legality of a particular edge direction and label.GraphFilterclone()booleanequals(Object object)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.YESorGraphFilter.Legal.MAYBEedge labels.Traversal.Admin<Vertex,Vertex>getVertexFilter()Get the vertex filter associated with this graph filter.booleanhasEdgeFilter()Whether an edge filter has been defined.booleanhasFilter()Whether filters have been defined.inthashCode()booleanhasVertexFilter()Whether a vertex filter has been defined.Iterator<Edge>legalEdges(Vertex vertex)Returns an iterator of legal edges incident to the provided vertex.booleanlegalVertex(Vertex vertex)Returns true if the provided vertex meets the vertex-filter criteria.voidsetEdgeFilter(Traversal<Vertex,Edge> edgeFilter)Set the filter for selecting edges from the source graph.voidsetVertexFilter(Traversal<Vertex,Vertex> vertexFilter)Set the filter for selecting vertices from the source graph.StringtoString()
-
-
-
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- TheTraversalthat 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- TheTraversalthat will generate the legal incident edges of the vertex.
-
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.
-
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.
-
hasFilter
public boolean hasFilter()
Whether filters have been defined.- Returns:
- true if either a vertex or edge 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.
-
getLegallyPositiveEdgeLabels
public Set<String> getLegallyPositiveEdgeLabels(Direction direction)
For a particular edge directionality, get all theGraphFilter.Legal.YESorGraphFilter.Legal.MAYBEedge 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.Legalof 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.Legalof the edge direction.
-
clone
public GraphFilter clone()
-
-