Class QueryAlgebraUtil


  • public class QueryAlgebraUtil
    extends Object
    Various static functions for query handling and parsing (alegbra expression).
    Author:
    Andreas Schwarte
    • 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
      • 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
      • 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