org.eclipse.rdf4j.federated.util

## Class QueryAlgebraUtil

- java.lang.Object
- - org.eclipse.rdf4j.federated.util.QueryAlgebraUtil

-     public class QueryAlgebraUtil
      extends Object

  Various static functions for query handling and parsing (alegbra expression).
  Author:
    Andreas Schwarte

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `QueryAlgebraUtil()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected static Var` | `appendVar(Var var, Set<String> varNames, BindingSet bindings)` Clone the specified variable and attach bindings.
    `protected static Var` | `appendVarId(Var var, String varID, Set<String> varNames, BindingSet bindings)` Clone the specified variable and attach bindings, moreover change name of variable by appending "_varId" to it.
    `protected static Union` | `constructInnerUnion(StatementPattern stmt, int outerID, Set<String> varNames, List<BindingSet> bindings)`
    `protected static StatementPattern` | `constructStatement(StatementPattern stmt, Set<String> varNames, BindingSet bindings)` Construct the statement string, i.e.
    `protected static TupleExpr` | `constructStatementCheckId(StatementPattern stmt, int varID, Set<String> varNames, BindingSet bindings)` Construct the statement string, i.e.
    `protected static StatementPattern` | `constructStatementId(StatementPattern stmt, String varID, Set<String> varNames, BindingSet bindings)` Construct the statement string, i.e.
    `static Collection<String>` | `getFreeVars(TupleExpr tupleExpr)` Computes the collection of free variables in the given `TupleExpr`.
    `static Value` | `getVarValue(Var var, BindingSet bindings)` Return the `Value` of the variable which is either taken from the variable itself (bound) or from the bindingsset (unbound).
    `static boolean` | `hasFreeVars(StatementPattern stmt, BindingSet bindings)` returns true iff there is at least one free variable, i.e.
    `static TupleExpr` | `selectQuery(ExclusiveGroup group, BindingSet bindings, FilterValueExpr filterExpr, AtomicBoolean evaluated)` Construct a SELECT query for the provided `ExclusiveGroup`.
    `static TupleExpr` | `selectQuery(StatementPattern stmt, BindingSet bindings, FilterValueExpr filterExpr, AtomicBoolean evaluated)` Construct a SELECT query for the provided statement.
    `static TupleExpr` | `selectQueryBoundUnion(StatementPattern stmt, List<BindingSet> unionBindings, FilterValueExpr filterExpr, Boolean evaluated)` Construct a SELECT query expression for a bound union.
    `static TupleExpr` | `selectQueryStringBoundCheck(StatementPattern stmt, List<BindingSet> unionBindings)` Construct a SELECT query for a grouped bound check.
    `static Statement` | `toStatement(StatementPattern stmt)`
    `static Statement` | `toStatement(StatementPattern stmt, BindingSet bindings)`
    `static StatementPattern` | `toStatementPattern(Resource subj, IRI pred, Value obj)`
    `static StatementPattern` | `toStatementPattern(Statement stmt)`
    `static TupleExpr` | `toTupleExpr(ArbitraryLengthPath node, Set<String> varNames, BindingSet bindings)` Convert the given `ArbitraryLengthPath` to a fresh `TupleExpr` where all provided bindings are bound.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### QueryAlgebraUtil

          public QueryAlgebraUtil()

  - ### Method Detail

    - #### hasFreeVars

          public static boolean hasFreeVars(StatementPattern stmt,
                                            BindingSet bindings)

      returns true iff there is at least one free variable, i.e. there is no binding for any variable
      Parameters:
        `stmt` -
        `bindings` -
      Returns:
        whether there is at least one free variable

    - #### getVarValue

          public static Value getVarValue(Var var,
                                          BindingSet bindings)

      Return the `Value` of the variable which is either taken from the variable itself (bound) or from the bindingsset (unbound).
      Parameters:
        `var` -
        `bindings` - the bindings, must not be null, use `EmptyBindingSet` instead
      Returns:
        the value or null

    - #### toTupleExpr

          public static TupleExpr toTupleExpr(ArbitraryLengthPath node,
                                              Set<String> varNames,
                                              BindingSet bindings)

      Convert the given `ArbitraryLengthPath` to a fresh `TupleExpr` where all provided bindings are bound.
      Parameters:
        `node` -
        `varNames` -
        `bindings` -
      Returns:
        the fresh and bound expression

    - #### toStatementPattern

          public static StatementPattern toStatementPattern(Statement stmt)

    - #### toStatementPattern

          public static StatementPattern toStatementPattern(Resource subj,
                                                            IRI pred,
                                                            Value obj)

    - #### toStatement

          public static Statement toStatement(StatementPattern stmt)

    - #### toStatement

          public static Statement toStatement(StatementPattern stmt,
                                              BindingSet bindings)

    - #### selectQuery

          public static TupleExpr selectQuery(StatementPattern stmt,
                                              BindingSet bindings,
                                              FilterValueExpr filterExpr,
                                              AtomicBoolean evaluated)
                                       throws IllegalQueryException

      Construct a SELECT query for the provided statement.
      Parameters:
        `stmt` -
        `bindings` -
        `filterExpr` -
        `evaluated` - parameter can be used outside this method to check whether FILTER has been evaluated, false in beginning
      Returns:
        the SELECT query
      Throws:
        `IllegalQueryException`

    - #### selectQuery

          public static TupleExpr selectQuery(ExclusiveGroup group,
                                              BindingSet bindings,
                                              FilterValueExpr filterExpr,
                                              AtomicBoolean evaluated)

      Construct a SELECT query for the provided `ExclusiveGroup`. Note that bindings and filterExpr are applied whenever possible.
      Parameters:
        `group` - the expression for the query
        `bindings` - the bindings to be applied
        `filterExpr` - a filter expression or null
        `evaluated` - parameter can be used outside this method to check whether FILTER has been evaluated, false in beginning
      Returns:
        the SELECT query

    - #### selectQueryBoundUnion

          public static TupleExpr selectQueryBoundUnion(StatementPattern stmt,
                                                        List<BindingSet> unionBindings,
                                                        FilterValueExpr filterExpr,
                                                        Boolean evaluated)

      Construct a SELECT query expression for a bound union. Pattern: SELECT ?v_1 ?v_2 ?v_N WHERE { { ?v_1 p o } UNION { ?v_2 p o } UNION ... } Note that the filterExpr is not evaluated at the moment.
      Parameters:
        `stmt` -
        `unionBindings` -
        `filterExpr` -
        `evaluated` - parameter can be used outside this method to check whether FILTER has been evaluated, false in beginning
      Returns:
        the SELECT query

    - #### selectQueryStringBoundCheck

          public static TupleExpr selectQueryStringBoundCheck(StatementPattern stmt,
                                                              List<BindingSet> unionBindings)

      Construct a SELECT query for a grouped bound check. Pattern: SELECT DISTINCT ?o_1 .. ?o_N WHERE { { s1 p1 ?o_1 FILTER ?o_1=o1 } UNION ... UNION { sN pN ?o_N FILTER ?o_N=oN }}
      Parameters:
        `stmt` -
        `unionBindings` -
      Returns:
        the SELECT query

    - #### constructInnerUnion

          protected static Union constructInnerUnion(StatementPattern stmt,
                                                     int outerID,
                                                     Set<String> varNames,
                                                     List<BindingSet> bindings)

    - #### constructStatement

          protected static StatementPattern constructStatement(StatementPattern stmt,
                                                               Set<String> varNames,
                                                               BindingSet bindings)

      Construct the statement string, i.e. "s p o . " with bindings inserted wherever possible. Note that the free variables are added to the varNames set for further evaluation.
      Parameters:
        `stmt` -
        `varNames` -
        `bindings` -
      Returns:
        the `StatementPattern`

    - #### constructStatementId

          protected static StatementPattern constructStatementId(StatementPattern stmt,
                                                                 String varID,
                                                                 Set<String> varNames,
                                                                 BindingSet bindings)

      Construct the statement string, i.e. "s p o . " with bindings inserted wherever possible. Variables are renamed to "var_"+varId to identify query results in bound queries. Note that the free variables are also added to the varNames set for further evaluation.
      Parameters:
        `stmt` -
        `varNames` -
        `bindings` -
      Returns:
        the `StatementPattern`

    - #### constructStatementCheckId

          protected static TupleExpr constructStatementCheckId(StatementPattern stmt,
                                                               int varID,
                                                               Set<String> varNames,
                                                               BindingSet bindings)

      Construct the statement string, i.e. "s p ?o_varID FILTER ?o_N=o ". This kind of statement pattern is necessary to later on identify available results.
      Parameters:
        `stmt` -
        `varID` -
        `varNames` -
        `bindings` -
      Returns:
        the expression

    - #### appendVar

          protected static Var appendVar(Var var,
                                         Set<String> varNames,
                                         BindingSet bindings)

      Clone the specified variable and attach bindings.
      Parameters:
        `var` -
        `varNames` -
        `bindings` -
      Returns:
        the variable

    - #### appendVarId

          protected static Var appendVarId(Var var,
                                           String varID,
                                           Set<String> varNames,
                                           BindingSet bindings)

      Clone the specified variable and attach bindings, moreover change name of variable by appending "_varId" to it.
      Parameters:
        `var` -
        `varID` -
        `varNames` -
        `bindings` -
      Returns:
        the variable

    - #### getFreeVars

          public static Collection<String> getFreeVars(TupleExpr tupleExpr)

      Computes the collection of free variables in the given `TupleExpr`.
      Parameters:
        `tupleExpr` - the expression
      Returns:
        the free variables
      See Also:
        `VariableExpr`

Copyright © 2015-2021 Eclipse Foundation. All Rights Reserved.