Class GraphFilter

  • All Implemented Interfaces:
    Serializable, Cloneable

    public final class GraphFilter
    extends Object
    implements Cloneable, Serializable
    GraphFilter is used by GraphComputer implementations to prune the source graph data being loaded into the OLAP system. There are two types of filters: a Vertex filter and an Edge filter. The vertex filter is a Traversal that can only check the id, label, and properties of the vertex. The edge filter is a Traversal 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 the GraphComputer. For instance, for g.V().count(), there is no reason to load edges, and thus, the edge filter can be bothE().limit(0).
    Author:
    Marko A. Rodriguez (http://markorodriguez.com)
    See Also:
    Serialized Form
    • 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 - The Traversal 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 - The Traversal 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 - The Traversal 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 the GraphFilter.Legal.YES or GraphFilter.Legal.MAYBE edge labels. If the label set contains null, 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.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object