Class GeneratorCPQ

java.lang.Object
dev.roanh.gmark.conjunct.cpq.GeneratorCPQ
All Implemented Interfaces:
ConjunctGenerator

public class GeneratorCPQ extends Object implements ConjunctGenerator
Generator for CPQs (Conjunctive Path Queries).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private SchemaGraph
    The schema graph to use to generate CPQs.
    private WorkloadCPQ
    The workload specifying what CPQs to generate.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new CPQ generator using the given workload.
  • Method Summary

    Modifier and Type
    Method
    Description
    generateConjunct(SelectivityGraph gSel, SelectivityType start, SelectivityType end, Variable source, Variable target, boolean star)
    Generates a single conjunct using the given selectivity graph and with the start of the conjunct being the given start selectivity type and the end of the conjunct the given end selectivity type.
    private static CPQ
    generatePlainCPQ(int ruleApplications, boolean allowId, List<Predicate> labels)
    Generates a random CPQ created by applying the intersection (conjunction) and concatenation steps from the CPQ grammar the given number of times.
    static CPQ
    generatePlainCPQ(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.
    static CPQ
    generatePlainCPQ(int ruleApplications, List<Predicate> labels)
    Generates a random CPQ created by applying the intersection (conjunction) and concatenation steps from the CPQ grammar the given number of times.
    static CPQ
    parse(String query)
    Parses the given CPQ in string form to a CPQ instance.
    static CPQ
    parse(String query, char join, char intersect, char inverse)
    Parses the given CPQ in string form to a CPQ instance.
    static CPQ
    parse(String query, Map<String,Predicate> labels, char join, char intersect, char inverse)
    Parses the given CPQ in string form to a CPQ instance.
    protected static List<String>
    split(String str, char symbol)
    Splits the given string into parts on the given character.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • gs

      private SchemaGraph gs
      The schema graph to use to generate CPQs.
    • workload

      private WorkloadCPQ workload
      The workload specifying what CPQs to generate.
  • Constructor Details

    • GeneratorCPQ

      public GeneratorCPQ(WorkloadCPQ wl)
      Constructs a new CPQ generator using the given workload.
      Parameters:
      wl - The workload specification.
      See Also:
  • Method Details

    • generatePlainCPQ

      public static CPQ generatePlainCPQ(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:
    • generatePlainCPQ

      public static CPQ generatePlainCPQ(int ruleApplications, List<Predicate> 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. Labels and inverse labels are drawn from the given set of labels. 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 set of labels to draw from.
      Returns:
      The randomly generated CPQ.
      Throws:
      IllegalArgumentException - When the list of labels is empty.
      See Also:
    • generatePlainCPQ

      private static CPQ generatePlainCPQ(int ruleApplications, boolean allowId, List<Predicate> labels)
      Generates a random CPQ created by applying the intersection (conjunction) and concatenation steps from the CPQ grammar the given number of times. Labels and inverse labels are drawn from the given set of labels. Two relatively meaningless but technically valid patterns are intentionally never generated:
      1. Concatenation with identity.
      2. Intersection of identity with identity.
      Parameters:
      ruleApplications - The number of times the intersection and concatenation steps are allowed to be applied.
      allowId - Whether the result of this call is allowed to be the identity CPQ.
      labels - The set of labels to draw from.
      Returns:
      The randomly generated CPQ.
    • parse

      public 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

      public static CPQ parse(String query, char join, char intersect, char inverse) throws IllegalArgumentException
      Parses the given CPQ in string form to a CPQ instance. Unlike parse(String) this subroutine allows custom symbols to be used to input the CPQ.
      Parameters:
      query - The CPQ to parse.
      join - The symbol to use for the join/concatenation operation.
      intersect - The symbol to use for the intersection/conjunction operation.
      inverse - The symbol to use for the inverse edge label operation.
      Returns:
      The parsed CPQ.
      Throws:
      IllegalArgumentException - When the given string is not a valid CPQ.
      See Also:
    • parse

      public static CPQ parse(String query, Map<String,Predicate> labels, char join, char intersect, char inverse) throws IllegalArgumentException
      Parses the given CPQ in string form to a CPQ instance. Unlike parse(String) this subroutine allows custom symbols to be used to input the CPQ.
      Parameters:
      query - The CPQ to parse.
      labels - A map with predicates found so far.
      join - The symbol to use for the join/concatenation operation.
      intersect - The symbol to use for the intersection/conjunction operation.
      inverse - The symbol to use for the inverse edge label operation.
      Returns:
      The parsed CPQ.
      Throws:
      IllegalArgumentException - When the given string is not a valid CPQ.
    • split

      protected static List<String> split(String str, char symbol) throws IllegalArgumentException
      Splits the given string into parts on the given character. The given character will not be returned in any parts and the found parts will be trimmed of leading and trailing whitespace. This method will ignore any regions of the input string that are enclosed in (nested) round brackets.
      Parameters:
      str - The string to split.
      symbol - The character to split on.
      Returns:
      The input string split on the given character.
      Throws:
      IllegalArgumentException - When brackets are present in the given string, but not balanced properly.
    • generateConjunct

      public Conjunct generateConjunct(SelectivityGraph gSel, SelectivityType start, SelectivityType end, Variable source, Variable target, boolean star) throws GenerationException
      Description copied from interface: ConjunctGenerator
      Generates a single conjunct using the given selectivity graph and with the start of the conjunct being the given start selectivity type and the end of the conjunct the given end selectivity type.
      Specified by:
      generateConjunct in interface ConjunctGenerator
      Parameters:
      gSel - The selectivity graph to use (if required).
      start - The starting selectivity type of the conjunct to generate.
      end - The end selectivity type of the conjunct to generate.
      source - The source variable of the conjunct.
      target - The target variable of the conjunct.
      star - True if the conjunct should have a Kleene star above it.
      Returns:
      The randomly generated conjunct.
      Throws:
      GenerationException - When some exception occurred that prevented a conjunct from begin generated.