Interface CPQ

All Superinterfaces:
OutputFormal, OutputSQL, OutputXML, QueryFragment, QueryLanguageSyntax
All Known Implementing Classes:
ConcatCPQ, EdgeCPQ, IdentityCPQ, IntersectionCPQ

public interface CPQ extends QueryLanguageSyntax
Interface for conjunctive path queries (CPQs).
See Also:
  • Field Details

    • IDENTITY

      static final CPQ IDENTITY
      Constant for the special identity CPQ.
  • Method Details

    • toQueryGraph

      default QueryGraphCPQ toQueryGraph()
      Computes and returns the query graph for this CPQ.
      Returns:
      The query graph for this CPQ.
      See Also:
    • computeCore

      default QueryGraphCPQ computeCore()
      Computes and returns the core of the query graph for this CPQ.
      Returns:
      The core of this CPQ.
      See Also:
    • isHomomorphicTo

      default boolean isHomomorphicTo(CPQ other)
      Tests if the query graph for this CPQ is homomorphic to the query graph for the given other CPQ.
      Parameters:
      other - The other CPQ to test against.
      Returns:
      True if this CPQ is homorphic to the other CPQ.
      See Also:
    • getQueryLanguage

      default QueryLanguage getQueryLanguage()
      Description copied from interface: QueryLanguageSyntax
      Gets the concrete query language used to defined this query.
      Specified by:
      getQueryLanguage in interface QueryLanguageSyntax
      Returns:
      The query language for this query.
    • toQueryGraph

      Computes and returns the query graph for this CPQ using the given source and target vertices for the computation. Usually using toQueryGraph() instead should be sufficient for most use cases, using this version instead can lead to unexpected results.
      Parameters:
      source - The source vertex to use.
      target - The target vertex to use.
      Returns:
      The query graph for this CPQ.
      See Also:
    • getDiameter

      int getDiameter()
      Returns the diameter of this CPQ. The diameter of a CPQ is the largest number of labels to which the join operation is applied. A simpler way to think of this concept is the length of the largest path through the CPQ from source to target.
      Returns:
      The diameter of this CPQ.
    • isLoop

      boolean isLoop()
      Tests if this CPQ is a loop, meaning its source and target are the same. When visualised as a query graph this means that the source and target node are the same node. In its grammar form this means that there is an intersection with identity at the highest level in the CPQ.
      Returns:
      True if this CPQ is a loop.
      See Also:
    • id

      static CPQ id()
      Returns the identity CPQ.
      Returns:
      The identity CPQ.
      See Also:
    • intersect

      static CPQ intersect(Predicate... predicates) throws IllegalArgumentException
      Returns a CPQ representing the intersection (conjunction) of the two given single edge label traversals.
      Parameters:
      predicates - The labels to traverse.
      Returns:
      The intersection of the given label traversals.
      Throws:
      IllegalArgumentException - When less than 2 predicates are provided.
    • intersect

      static CPQ intersect(CPQ... cpqs) throws IllegalArgumentException
      Returns a CPQ representing the intersection of the given CPQs from left to right. For example ((q1 ∩ q2) ∩ q3).
      Parameters:
      cpqs - The CPQs to intersect.
      Returns:
      The intersection of the given CPQs.
      Throws:
      IllegalArgumentException - When less than 2 CPQs are provided.
    • intersect

      static CPQ intersect(List<CPQ> cpqs) throws IllegalArgumentException
      Returns a CPQ representing the intersection of the given CPQs from left to right. For example ((q1 ∩ q2) ∩ q3). Note that the given list is not copied.
      Parameters:
      cpqs - The CPQs to intersect.
      Returns:
      The intersection of the given CPQs.
      Throws:
      IllegalArgumentException - When less than 2 CPQs are provided.
    • concat

      static CPQ concat(CPQ... cpqs) throws IllegalArgumentException
      Returns a CPQ representing the concatenation in order of the given CPQs.
      Parameters:
      cpqs - The CPQs to concatenate (in order).
      Returns:
      The concatenation of the given CPQs.
      Throws:
      IllegalArgumentException - When the given list of CPQs is empty.
    • concat

      static CPQ concat(List<CPQ> cpqs) throws IllegalArgumentException
      Returns a CPQ representing the concatenation in order of the given CPQs. Note that the given list is not copied.
      Parameters:
      cpqs - The CPQs to concatenate (in order).
      Returns:
      The concatenation of the given CPQs.
      Throws:
      IllegalArgumentException - When the given list of CPQs is empty.
    • label

      static CPQ label(Predicate label)
      Returns a CPQ representing a single labelled edge traversal.
      Parameters:
      label - The label of the traversed edge.
      Returns:
      The label traversal CPQ.
    • labels

      static CPQ labels(Predicate... labels)
      Returns a CPQ representing a chain of labelled edge traversals.
      Parameters:
      labels - The labels of the traversed edges.
      Returns:
      The label traversal CPQ.
    • labels

      static CPQ labels(List<Predicate> labels)
      Returns a CPQ representing a chain of labelled edge traversals.
      Parameters:
      labels - The labels of the traversed edges.
      Returns:
      The label traversal CPQ.
    • generateRandomCPQ

      static CPQ generateRandomCPQ(int ruleApplications, int labels) throws IllegalArgumentException
      Generates a random CPQ created by applying the intersection (conjunction) and concatenation steps from the CPQ grammar the given number of times. A set of labels of the given size is automatically generated together with corresponding inverse labels for each label. Three relatively meaningless but technically valid patterns are intentionally never generated:
      1. Concatenation with identity.
      2. Intersection of identity with identity.
      3. The query consisting of only identity and nothing else.
      Parameters:
      ruleApplications - The number of times the intersection and concatenation steps are allowed to be applied.
      labels - The number of distinct labels to use (upper limit).
      Returns:
      The randomly generated CPQ.
      Throws:
      IllegalArgumentException - When the given number of labels is 0 or less.
      See Also:
    • parse

      static CPQ parse(String query) throws IllegalArgumentException
      Parses the given CPQ in string form to a CPQ instance. The input is assumed to use brackets where possible and to use the 'id', ''\u25e6'', ''\u2229'' and ''\u207b'' symbols to denote operations. Example input: (0◦(((1◦0) ∩ (1◦1))◦1⁻)).
      Parameters:
      query - The CPQ to parse.
      Returns:
      The parsed CPQ.
      Throws:
      IllegalArgumentException - When the given string is not a valid CPQ.
      See Also:
    • parse

      static CPQ parse(QueryTree ast) throws IllegalArgumentException
      Attempts to parse the given AST to a CPQ.
      Parameters:
      ast - The AST to parse to a CPQ.
      Returns:
      The CPQ represented by the given AST.
      Throws:
      IllegalArgumentException - When the given AST does not represent a valid CPQ.
      See Also: