Class QueryResults

  • Direct Known Subclasses:
    QueryResultUtil

    public class QueryResults
    extends Iterations
    Utility methods related to query results.
    • Field Detail

      • cleaner

        private static final java.lang.ref.Cleaner cleaner
    • Constructor Detail

      • QueryResults

        public QueryResults()
    • Method Detail

      • getAllValues

        public static java.util.List<Value> getAllValues​(TupleQueryResult result,
                                                         java.lang.String var)
                                                  throws QueryEvaluationException
        Returns a list of values of a particular variable out of the QueryResult.
        Parameters:
        result -
        var - variable for which list of values needs to be returned
        Returns:
        a list of Values of var
        Throws:
        QueryEvaluationException
      • distinctResults

        public static GraphQueryResult distinctResults​(GraphQueryResult queryResult)
        Returns a GraphQueryResult that filters out any duplicate solutions from the supplied queryResult.
        Parameters:
        queryResult - a queryResult containing possible duplicate statements.
        Returns:
        a GraphQueryResult with any duplicates filtered out.
      • distinctResults

        public static TupleQueryResult distinctResults​(TupleQueryResult queryResult)
        Returns a TupleQueryResult that filters out any duplicate solutions from the supplied queryResult.
        Parameters:
        queryResult - a queryResult containing possible duplicate solutions.
        Returns:
        a TupleQueryResult with any duplicates filtered out.
      • limitResults

        public static TupleQueryResult limitResults​(TupleQueryResult queryResult,
                                                    long limit,
                                                    long offset)
        Returns a TupleQueryResult that returns at most the specified maximum number of solutions, starting at the supplied offset.
        Parameters:
        queryResult - a query result possibly containing more solutions than the specified maximum.
        limit - the maximum number of solutions to return. If set to 0 or lower, no limit will be applied.
        offset - the number of solutions to skip at the beginning. If set to 0 or lower, no offset will be applied.
        Returns:
        A TupleQueryResult that will at return at most the specified maximum number of solutions. If neither limit nor offset are applied, this returns the original queryResult.
      • limitResults

        public static GraphQueryResult limitResults​(GraphQueryResult queryResult,
                                                    long limit,
                                                    long offset)
        Returns a GraphQueryResult that returns at most the specified maximum number of solutions, starting at the supplied offset.
        Parameters:
        queryResult - a query result possibly containing more solutions than the specified maximum.
        limit - the maximum number of solutions to return. If set to 0 or lower, no limit will be applied.
        offset - the number of solutions to skip at the beginning. If set to 0 or lower, no offset will be applied.
        Returns:
        A GraphQueryResult that will at return at most the specified maximum number of solutions. If neither limit nor offset are applied, this returns the original queryResult.
      • parseGraphBackground

        @Deprecated(since="4.1.2")
        public static GraphQueryResult parseGraphBackground​(java.io.InputStream in,
                                                            java.lang.String baseURI,
                                                            RDFFormat format,
                                                            java.lang.ref.WeakReference<?> callerReference)
                                                     throws UnsupportedRDFormatException
        Deprecated.
        WeakReference callerReference argument will be removed
        Parses an RDF document and returns it as a GraphQueryResult object, with parsing done on a separate thread in the background.
        IMPORTANT: As this method will spawn a new thread in the background, it is vitally important that the resulting GraphQueryResult be closed consistently when it is no longer required, to prevent resource leaks.
        Parameters:
        in - The InputStream containing the RDF document.
        baseURI - The base URI for the RDF document.
        format - The RDFFormat of the RDF document.
        Returns:
        A GraphQueryResult that parses in the background, and must be closed to prevent resource leaks.
        Throws:
        UnsupportedRDFormatException
      • parseGraphBackground

        @Deprecated(since="4.1.2")
        public static GraphQueryResult parseGraphBackground​(java.io.InputStream in,
                                                            java.lang.String baseURI,
                                                            RDFParser parser,
                                                            java.lang.ref.WeakReference<?> callerReference)
        Deprecated.
        WeakReference callerReference argument will be removed
        Parses an RDF document and returns it as a GraphQueryResult object, with parsing done on a separate thread in the background.
        IMPORTANT: As this method will spawn a new thread in the background, it is vitally important that the resulting GraphQueryResult be closed consistently when it is no longer required, to prevent resource leaks.
        Parameters:
        in - The InputStream containing the RDF document.
        baseURI - The base URI for the RDF document.
        parser - The RDFParser.
        Returns:
        A GraphQueryResult that parses in the background, and must be closed to prevent resource leaks.
      • equals

        public static boolean equals​(TupleQueryResult tqr1,
                                     TupleQueryResult tqr2)
                              throws QueryEvaluationException
        Compares two tuple query results and returns true if they are equal.Tuple query results are equal if they contain the same set of BindingSets and have the same headers. Blank nodes identifiers are not relevant for equality, they are matched by trying to find compatible mappings between BindingSets. Note that the method consumes both query results fully.
        Parameters:
        tqr1 - the first TupleQueryResult to compare.
        tqr2 - the second TupleQueryResult to compare.
        Returns:
        true if equal
        Throws:
        QueryEvaluationException
      • equals

        public static boolean equals​(GraphQueryResult result1,
                                     GraphQueryResult result2)
                              throws QueryEvaluationException
        Compares two graph query results and returns true if they are equal. Two graph query results are considered equal if they are isomorphic graphs. Note that the method consumes both query results fully.
        Parameters:
        result1 - the first query result to compare
        result2 - the second query result to compare.
        Returns:
        true if the supplied graph query results are isomorphic graphs, false otherwise.
        Throws:
        QueryEvaluationException
        See Also:
        Models.isomorphic(Iterable, Iterable)
      • matchBindingSets

        private static boolean matchBindingSets​(java.util.List<? extends BindingSet> queryResult1,
                                                java.lang.Iterable<? extends BindingSet> queryResult2)
      • matchBindingSets

        private static boolean matchBindingSets​(java.util.List<? extends BindingSet> queryResult1,
                                                java.lang.Iterable<? extends BindingSet> queryResult2,
                                                java.util.Map<BNode,​BNode> bNodeMapping,
                                                int idx)
        A recursive method for finding a complete mapping between blank nodes in queryResult1 and blank nodes in queryResult2. The algorithm does a depth-first search trying to establish a mapping for each blank node occurring in queryResult1.
        Returns:
        true if a complete mapping has been found, false otherwise.
      • findMatchingBindingSets

        private static java.util.List<BindingSet> findMatchingBindingSets​(BindingSet st,
                                                                          java.lang.Iterable<? extends BindingSet> model,
                                                                          java.util.Map<BNode,​BNode> bNodeMapping)
      • bindingSetsCompatible

        public static boolean bindingSetsCompatible​(BindingSet bs1,
                                                    BindingSet bs2)
        Check whether two BindingSets are compatible. Two binding sets are compatible if they have equal values for each variable that is bound in both binding sets.
        Parameters:
        bs1 -
        bs2 -
        Returns:
        true if compatible