Interface CPQ

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

public interface CPQ extends OutputSQL, OutputXML
Interface for conjunctive path queries (CPQs).
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final char
    The character used to denote the intersection/conjunction operator.
    static final char
    The character used to denote the join/concatenation operator.
    static final CPQ
    Constant for the special identity CPQ.
  • Method Summary

    Modifier and Type
    Method
    Description
    Computes and returns the core of the query graph for this CPQ.
    static CPQ
    concat(CPQ... cpqs)
    Returns a CPQ representing the concatenation in order of the given CPQs.
    static CPQ
    concat(List<CPQ> cpqs)
    Returns a CPQ representing the concatenation in order of the given CPQs.
    static CPQ
    generateRandomCPQ(int ruleApplications, int labels)
    Generates a random CPQ created by applying the intersection (conjunction) and concatenation steps from the CPQ grammar the given number of times.
    int
    Returns the diameter of this CPQ.
    static CPQ
    id()
    Returns the identity CPQ.
    static CPQ
    intersect(CPQ... cpqs)
    Returns a CPQ representing the intersection of the given CPQs from left to right.
    static CPQ
    intersect(Predicate... predicates)
    Returns a CPQ representing the intersection (conjunction) of the two given single edge label traversals.
    static CPQ
    Returns a CPQ representing the intersection of the given CPQs from left to right.
    default boolean
    Tests if the query graph for this CPQ is homomorphic to the query graph for the given other CPQ.
    boolean
    Tests if this CPQ is a loop, meaning its source and target are the same.
    static CPQ
    Returns a CPQ representing a single labelled edge traversal.
    static CPQ
    labels(Predicate... labels)
    Returns a CPQ representing a chain of labelled edge traversals.
    static CPQ
    Returns a CPQ representing a chain of labelled edge traversals.
    static CPQ
    parse(String query)
    Parses the given CPQ in string form to a CPQ instance.
    Computes and returns the query graph for this CPQ.
    Computes and returns the query graph for this CPQ using the given source and target vertices for the computation.

    Methods inherited from interface dev.roanh.gmark.output.OutputSQL

    toSQL

    Methods inherited from interface dev.roanh.gmark.output.OutputXML

    toXML, writeXML
  • Field Details

    • CHAR_CAP

      static final char CHAR_CAP
      The character used to denote the intersection/conjunction operator.
      See Also:
    • CHAR_JOIN

      static final char CHAR_JOIN
      The character used to denote the join/concatenation operator.
      See Also:
    • 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:
    • 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 list of labels is empty.
      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: