Package lupos.datastructures.queryresult

Examples of lupos.datastructures.queryresult.QueryResult


  public Message preProcessMessageDebug(EndOfEvaluationMessage msg, final DebugStep debugstep) {

    if (!this.isSortable || this.operands[1].isEmpty()) {
      return super.preProcessMessage(msg);
    } else if (!this.operands[0].isEmpty() && !this.operands[1].isEmpty()) {
      QueryResult result = QueryResult.createInstance();

      Iterator<Bindings> leftIt = this.operands[0].getQueryResult().iterator();
      Iterator<Bindings> rightIt = this.operands[1].getQueryResult().iterator();
      Bindings leftBindings = null, rightBindings = null;
      if (leftIt.hasNext()) {
        leftBindings = leftIt.next();
      }
      if (rightIt.hasNext()) {
        rightBindings = rightIt.next();
      }

      while (rightBindings != null && leftBindings != null) {
        int difference = this.comp.compare(leftBindings, rightBindings);
        if (difference > 0) {
          rightBindings = rightIt.hasNext() ? rightIt.next() : null;
        } else if (difference == 0) {
          leftBindings = leftIt.hasNext() ? leftIt.next() : null;
        } else if (difference < 0) {
          result.add(leftBindings);
          leftBindings = leftIt.hasNext() ? leftIt.next() : null;
        }

      }

      while (leftBindings != null) {
        result.add(leftBindings);
        leftBindings = leftIt.hasNext() ? leftIt.next() : null;
      }

      for (final OperatorIDTuple opId : this.succeedingOperators) {
        opId.processAllDebug(result, debugstep);
View Full Code Here


        }

        // now another result is available
        while (!this.resultList.isEmpty()) {
          // take the first element
          final QueryResult res = this.resultList.remove(0);
          if (res != null) {
            this.currentIter = res.oneTimeIterator();
            if (this.currentIter.hasNext()) {
              return true;
            }
          }
        }
View Full Code Here

  public static QueryResult joinBindings(final Bindings bindings1,
      final Bindings bindings2) {

    // create a new instance of a query result object to take up
    // the combination of the two bindings object
    final QueryResult qResult = QueryResult.createInstance();

    // if the bindings can be combined (they contain no conflicting
    // bindings) return the new query result object. Otherwise
    // return null
    return (joinBindings(qResult, bindings1, bindings2)) ? qResult : null;
View Full Code Here

   * result=QueryResult.createInstance(); result.add(b); return result; }
   */

  public static QueryResult joinBindings(final QueryResult qr) {

    final QueryResult result = QueryResult.createInstance();
    final Iterator<Bindings> ib = qr.iterator();

    if (ib.hasNext()) {
      final Bindings bindings1 = ib.next().clone();
      while (ib.hasNext()) {
        final Bindings bindings2 = ib.next();
        // only the keys of the second bindings object have to be
        // checked since the the first bindings object is updated
        for (final Variable b2key : bindings2.getVariableSet()) {

          final Literal literalB2 = bindings2.get(b2key);
          final Literal literalB1 = bindings1.get(b2key);

          // if the literal computed from the second bindings
          // conflicts with
          // the corresponding one located in the first bindings
          // object,
          // null is returned to indicate an unsolvable conflict
          if (literalB1 != null) {
            if (!literalB1.valueEquals(literalB2)) {
              return null;
            }
          }

          // otherwise add the new binding of the key and literal to
          // the first bindings object
          else {
            bindings1.add(b2key, literalB2);
          }
        }
        bindings1.addAllTriples(bindings2);
        bindings1.addAllPresortingNumbers(bindings2);
      }
      result.add(bindings1);
    }
    if (result.size() > 0)
      return result;
    else
      return null;
  }
View Full Code Here

      if (operandID == 0) {
        if (or != null && or.getJoinPartnerFromLeftOperand() != null) {
          bindings.removeAll(or.getJoinPartnerFromLeftOperand());
        }
        if (this.notJoinedFromLeftOperand == null) {
          this.notJoinedFromLeftOperand = new QueryResult();
        }
        this.notJoinedFromLeftOperand.addAll(bindings);
      } else if (or != null && or.getJoinPartnerFromLeftOperand() != null) {
        if (this.notJoinedFromLeftOperand != null) {
          this.notJoinedFromLeftOperand.removeAll(or
View Full Code Here

      if (this.left != null && this.right != null) {       

        final Iterator<Bindings> currentResult = MergeJoin.mergeOptionalIterator(this.left.oneTimeIterator(), this.right.oneTimeIterator(), this.comp);

        if (currentResult != null && currentResult.hasNext()) {
          final QueryResult result = QueryResult.createInstance(currentResult);
          return result;         
        } else
          return null;
      } else
        return null;
View Full Code Here

                  + localqueryfile);

          final String query = FileHelper
              .fastReadFile(localqueryfile);

          final QueryResult result2 = ((evaluator.debug) == DEBUG.ALL || (evaluator.debug) == DEBUG.WITHOUTRESULT) ? evaluator
              .getResult(query, localqueryfile)
              : evaluator.getResult(query);
          final QueryResult result1 = ((evaluator.debug) == DEBUG.ALL || (evaluator.debug) == DEBUG.WITHOUTRESULT) ? qe
              .getResult(query, localqueryfile)
              : qe.getResult(query);
          if ((evaluator.debug) == DEBUG.ONLYFINAL) {
            evaluator
                .displayOperatorGraph("Final Operatorgraph for query "
                    + localqueryfile
                    + " of engine "
                    + evaluator.getClass().getSimpleName());
            qe
                .displayOperatorGraph("Final Operatorgraph for query "
                    + localqueryfile
                    + " of engine "
                    + qe.getClass().getSimpleName());
          }

          int resultSize1;
          int resultSize2;
          if (result1 == null) {
            resultSize1 = 0;
          } else {
            resultSize1 = result1.size();
          }
          if (result2 == null) {
            resultSize2 = 0;
          } else {
            resultSize2 = result2.size();
          }
          System.out
              .println("Number of results engine 1 versus number of results of engine 2:"
                  + resultSize1
                  + (resultSize1 == resultSize2 ? "=" : "!=")
                  + resultSize2);
          if ((resultSize1 == 0 && resultSize2 == 0)
              || (result1 != null && result2 != null && result1
                  .equals(result2))) {
              System.out.println("The results match exactly!");

            if (resultSize1 == 0)
              System.out
                  .println("However, the results are empty. Please check more carefully!");
            else {
              if (result1.sameOrder(result2))
                System.out
                    .println("\nThe results are in the same order!");
            }
          } else {
              System.out
                  .println("Results mismatch!\n\nPlease set the logger's level to DEBUG to see more detailed information");

            if (result1 != null)
              System.out
                  .println("Size of query result of engine 1:"
                      + result1.size());
            if (result2 != null)
              System.out
                  .println("Size of query result of engine 2:"
                      + result2.size());

            if (result1 != null
                && result2 != null
                && result1
                    .containsAllExceptAnonymousLiterals(result2)
                && result2
                    .containsAllExceptAnonymousLiterals(result1)) {
              System.out
                  .println("\n\nIt seems to be that the results are equivalent except of anonymous literals.");
              System.out
                  .println("It must be more carefully checked!");

              if (result1
                  .sameOrderExceptAnonymousLiterals(result2))
                System.out
                    .println("\nThe results are in the same order ignoring anonymous literals!");
            }
          }
        }
      } else {
        final int times = evaluator.times;
        if (times == 0) {
          System.out.println("Evaluate a query in "
              + queryfile
              + " on data in "
              + datafile
              + " using the "
              + evaluator.getClass().getSimpleName().replace(
                  "QueryEvaluator", "") + " Engine\n");
          System.out.println("Read input data from file " + datafile
              + " ...");
          evaluator.prepareInputData(defaultGraphs, namedGraphs);

            for (final String localqueryfile : queryFiles) {
              System.out.println("\nQuery in file:"
                  + localqueryfile);
              System.out.println("Compile query...");
              evaluator.compileQueryFromFile(localqueryfile);

              System.out.println("Logical optimization...");
              evaluator.logicalOptimization();
              System.out.println("Physical optimization...");
              evaluator.physicalOptimization();

              System.out.println("Evaluate query ...");
              final QueryResult resultQueryEvaluator = evaluator
                  .getResult();
              System.out.println("\nQuery Result:");
              System.out.println(resultQueryEvaluator);
              System.out.println("Number of results: "
                  + resultQueryEvaluator.size());
              if ((evaluator.debug) == DEBUG.ONLYFINAL)
                evaluator
                    .displayOperatorGraph("Final Operatorgraph for query "
                        + localqueryfile);
              System.out.println("----------------Done.");
View Full Code Here

   *            unused parameter
   * @return the result of the performed join
   */
  @Override
  public QueryResult process(final Dataset dataset) {
    final QueryResult queryResult = this.join(dataset);
    if (queryResult == null) {
      return null;
    }
    return queryResult;
  }
View Full Code Here

  public QueryResult join(final Dataset dataset) {
    try {

      // create a query result object which will gather the results of the
      // inner join
      QueryResult queryResult = null;

      // get the graph constraint from the super class.
      // If it is null, a default graph is used, if not null a named one
      // is used
      final Item graphConstraintItem = this.getGraphConstraint();

      // get a collection of indices using the determined graph constraint
      final Collection<Indices> indicesC = dataset.indexingRDFGraphs(
          graphConstraintItem, false, false, this.root);
      if ((indicesC != null) && !(indicesC.size() == 0)) {

        // if the graph constraint is not null (which means that a named
        // graph is used)
        if (graphConstraintItem != null) {

          if (graphConstraintItem instanceof Variable) {

            final Variable graphConstraint = (Variable) graphConstraintItem;

            // check if named graphs were provided at query time
            if (this.root.namedGraphs != null
                && this.root.namedGraphs.size() > 0) {

              // Convert the named graphs' names into URILiterals
              // to be applicable
              // later on
              for (final String name : this.root.namedGraphs) {

                final Indices indices = dataset.getNamedGraphIndices(LiteralFactory.createURILiteralWithoutLazyLiteral(name));

                final Bindings graphConstraintBindings = this.bindingsFactory.createInstance();
                final URILiteral rdfName = indices.getRdfName();
                graphConstraintBindings.add(graphConstraint, rdfName);
                if (queryResult == null) {
                  queryResult = QueryResult.createInstance(new AddConstantBindingIterator(graphConstraint, rdfName, this.join(indices,
                      graphConstraintBindings).oneTimeIterator()));
                } else {
                  queryResult.addAll(QueryResult.createInstance(new AddConstantBindingIterator(graphConstraint, rdfName, this.join(indices,
                      graphConstraintBindings).oneTimeIterator())));
                }

              }

            }

            // otherwise there might have been named graphs added
            // during the evaluation
            else {

              // get all indices of named graphs and bind them to
              // the graph constraint
              final Collection<Indices> dataSetIndices = dataset.getNamedGraphIndices();
              if (dataSetIndices != null) {

                for (final Indices indices : dataSetIndices) {
                  final Bindings graphConstraintBindings = this.bindingsFactory.createInstance();
                  graphConstraintBindings.add(graphConstraint, indices.getRdfName());
                  if (queryResult == null) {
                    queryResult = QueryResult.createInstance(new AddConstantBindingIterator(graphConstraint, indices.getRdfName(), this.join(indices,
                        graphConstraintBindings).oneTimeIterator()));
                  } else {
                    queryResult.addAll(QueryResult.createInstance(new AddConstantBindingIterator(graphConstraint, indices.getRdfName(), this.join(indices,
                        graphConstraintBindings).oneTimeIterator())));
                  }
                }
              }
            }
View Full Code Here

   * Performs a join over a collection of triple patterns
   * @param indicesC all the the index structures which contains the data
   * @return the result of the join
   */
  public QueryResult join(final Collection<Indices> indicesC){
    QueryResult queryResult = null;
    for (final Indices indices : indicesC) {
      if(queryResult == null) {
        queryResult = this.join(indices, this.bindingsFactory.createInstance());
      } else {
        queryResult.addAll(this.join(indices, this.bindingsFactory.createInstance()));
      }
    }
    return queryResult;
  }
View Full Code Here

TOP

Related Classes of lupos.datastructures.queryresult.QueryResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.