Package bst

Examples of bst.Queue$Node


  public TriplePattern getTriplePattern(final ASTTripleSet node) {
    final Item[] item = { null, null, null };

    for (int i = 0; i < 3; i++) {
      final Node n = node.jjtGetChild(i);
      if(n instanceof ASTObjectList){
        item[i] = getItem(n.jjtGetChild(0));
      } else {
        item[i] = getItem(n);
      }
    }
    final TriplePattern tpe = new TriplePattern(item[0], item[1], item[2]);
View Full Code Here


          realSubject = itm;
          subjectIsALiteral = true;
        } else {
          subject = (Variable) itm;
        }
        final Node subjectNode = tripleSet.jjtGetChild(0);

        itm = getItem(tripleSet.jjtGetChild(2));
        if (!itm.isVariable()){
          object = this.getVariable(getItem(tripleSet.jjtGetChild(0)).toString(), getItem(tripleSet.jjtGetChild(2)).toString(), "interimObject");
          realObject = itm;
          objectIsALiteral = true;
        } else {
          object = (Variable) itm;
        }
        final Node objectNode = tripleSet.jjtGetChild(2);


        final Node predicateNode = tripleSet.jjtGetChild(1);
        final BasicOperator startingOperator = predicateNode.accept(this, connection, graphConstraint, subject, object, subjectNode, objectNode);

        if(!subjectIsALiteral && !objectIsALiteral){
          startingOperator.addSucceedingOperator(connection.getOperatorIDTuple());
        }
        else
          if(subjectIsALiteral && !objectIsALiteral){
            final Filter filter = new Filter("(" + subject + " = " + realSubject +")");
            final Projection projection = new Projection();
            projection.addProjectionElement(object);
            if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
              projection.addProjectionElement((Variable)graphConstraint);
            }

            filter.addSucceedingOperator(new OperatorIDTuple(projection,0));
            projection.addSucceedingOperator(connection.getOperatorIDTuple());
            startingOperator.addSucceedingOperator(new OperatorIDTuple(filter,0));

          }
          else
            if(!subjectIsALiteral && objectIsALiteral){
              final Filter filter = new Filter("(" + object + " = " + realObject + ")");
              final Projection projection = new Projection();
              projection.addProjectionElement(subject);
              if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
                projection.addProjectionElement((Variable)graphConstraint);
              }

              filter.addSucceedingOperator(new OperatorIDTuple(projection,0));
              projection.addSucceedingOperator(connection.getOperatorIDTuple());
              startingOperator.addSucceedingOperator(new OperatorIDTuple(filter,0));

            }
            else
              if(subjectIsALiteral && objectIsALiteral){
                final Filter firstFilter = new Filter("(" + object + " = " + realObject + ")");
                final Filter secondFilter = new Filter("(" + subject + " = " + realSubject + ")");
                final Projection firstProjection = new Projection();
                firstProjection.addProjectionElement(subject);
                if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
                  firstProjection.addProjectionElement((Variable)graphConstraint);
                }
                final Projection secondProjection = new Projection();
                secondProjection.addProjectionElement(object);
                if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
                  secondProjection.addProjectionElement((Variable)graphConstraint);
                }

                firstFilter.addSucceedingOperator(new OperatorIDTuple(firstProjection,0));
                firstProjection.addSucceedingOperator(new OperatorIDTuple(secondFilter, 0));
                secondFilter.addSucceedingOperator(new OperatorIDTuple(secondProjection,0));
                secondProjection.addSucceedingOperator(connection.getOperatorIDTuple());
                startingOperator.addSucceedingOperator(new OperatorIDTuple(firstFilter,0));
              }
      }
      catch( final Exception e){
        e.printStackTrace();
        System.out.println(e);
      }
    } else {
      // alternative way to evaluate (...)?, (...)* and (...)+ without using the Closure and PathLengthZero operators!
      try{
        Variable subject;
        Variable object;
        Item realSubject = null;
        Item realObject = null;
        boolean subjectIsALiteral = false;
        boolean objectIsALiteral = false;
        Item itm = getItem(tripleSet.jjtGetChild(0));
        if (!itm.isVariable()){
          subject = this.getVariable(getItem(tripleSet.jjtGetChild(0)).toString(), getItem(tripleSet.jjtGetChild(2)).toString(), "interimSubject");
          realSubject = itm;
          subjectIsALiteral = true;
        } else {
          subject = (Variable) itm;
        }
        final Node subjectNode = tripleSet.jjtGetChild(0);
        itm = getItem(tripleSet.jjtGetChild(2));
        if (!itm.isVariable()){
          object = this.getVariable(getItem(tripleSet.jjtGetChild(0)).toString(), getItem(tripleSet.jjtGetChild(2)).toString(), "interimObject");
          realObject = itm;
          objectIsALiteral = true;
        } else {
          object = (Variable) itm;
        }
        final Node objectNode = tripleSet.jjtGetChild(2);
        final ReplaceVar replaceVar = new ReplaceVar();
        replaceVar.addSubstitution(object, subject);
        final Variable variable = this.getVariable(subject.toString(), object.toString(), "interimVariable");
        replaceVar.addSubstitution(variable, object);
        if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
View Full Code Here

  @Override
  public BasicOperator visit(final ASTOptionalOccurence node,
      final OperatorConnection connection, final Item graphConstraint,
      final Variable subject, final Variable object, final Node subjectNode, final Node objectNode) {
    if(USE_CLOSURE_AND_PATHLENGTHZERO_OPERATORS){
      Node predicateNode = node.jjtGetChild(0);
      while (predicateNode instanceof ASTOptionalOccurence){
        predicateNode = predicateNode.jjtGetChild(0);
      }
      final BasicOperator startingOperator = predicateNode.accept(this, connection, graphConstraint, subject, object, subjectNode, objectNode);

      final Item[] items = {subject,this.getVariable(subject.toString(),object.toString(),"predicate"),object};
      final TriplePattern tp = new TriplePattern(items);
      final LinkedList<TriplePattern> temp = new LinkedList<TriplePattern>();
      temp.add(tp);
View Full Code Here

  @Override
  public BasicOperator visit(final ASTArbitraryOccurences node,
      final OperatorConnection connection, final Item graphConstraint,
      final Variable subject, final Variable object, final Node subjectNode, final Node objectNode) {
    if(USE_CLOSURE_AND_PATHLENGTHZERO_OPERATORS){
      Node predicateNode = node.jjtGetChild(0);
      while (predicateNode instanceof ASTArbitraryOccurences ||
          predicateNode instanceof ASTArbitraryOccurencesNotZero){
        predicateNode = predicateNode.jjtGetChild(0);
      }
      final BasicOperator startingOperator = predicateNode.accept(this, connection, graphConstraint, subject, object, subjectNode, objectNode);
      // System.out.println(startingOperator);

      Set<Literal> allowedObjects = null;
      Set<Literal> allowedSubjects = null;
View Full Code Here

  @Override
  public BasicOperator visit(final ASTArbitraryOccurencesNotZero node,
      final OperatorConnection connection, final Item graphConstraint,
      final Variable subject, final Variable object, final Node subjectNode, final Node objectNode) {
    if(USE_CLOSURE_AND_PATHLENGTHZERO_OPERATORS){
      Node predicateNode = node.jjtGetChild(0);
      while (predicateNode instanceof ASTArbitraryOccurences ||
          predicateNode instanceof ASTArbitraryOccurencesNotZero){
        if(predicateNode instanceof ASTArbitraryOccurences){
          return predicateNode.accept(this, connection, graphConstraint, subject, object, subjectNode, objectNode);
        }
        predicateNode = predicateNode.jjtGetChild(0);
      }
      final BasicOperator startingOperator = predicateNode.accept(this, connection, graphConstraint, subject, object, subjectNode, objectNode);

      Set<Literal> allowedObjects = null;
      Set<Literal> allowedSubjects = null;

      if(node.jjtGetParent() instanceof ASTTripleSet){
View Full Code Here

    if (graphConstraint != null && graphConstraint.isVariable()
        && !(node instanceof ASTSelectQuery && ((ASTSelectQuery)node).isSelectAll())) {

      boolean graphVariableIsSelected = false;
      for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        final Node n = node.jjtGetChild(i);
        if (n instanceof ASTVar) {
          final ASTVar variable = (ASTVar) n;
          if (variable.getName().equals(graphConstraint.getName())) {
            graphVariableIsSelected = true;
          }
        }
      }
      // as a workaround we rename the graphvariable in the subquery
      if (!graphVariableIsSelected) {
        int index=0;
        do {
          graphConstraint = new Variable(graphConstraint.getName() + index);
          index++;
        } while (this.hasThisVariable(node, graphConstraint));
      }
    }
    final int numberChildren = node.jjtGetNumChildren();

    boolean onlyAggregations = true;

    // insert limit operator
    for (int i = 0; i < numberChildren; i++) {
      if (node.jjtGetChild(i) instanceof ASTLimit) {
        node.jjtGetChild(i).accept(this, connection);
      }
    }
    // insert offset operator
    for (int i = 0; i < numberChildren; i++) {
      if (node.jjtGetChild(i) instanceof ASTOffset) {
        node.jjtGetChild(i).accept(this, connection);
      }
    }

    if (node instanceof ASTSelectQuery && ((ASTSelectQuery)node).isDistinct()) {

      // or insert a DISTINCT operator into the operator graph:
      connection.connectAndSetAsNewOperatorConnection(new Distinct());
    }

    LinkedList<AddComputedBinding> listOACB = new LinkedList<AddComputedBinding>();
    boolean group = false;

    for (int i = 0; i < numberChildren; i++) {
      final Node childi = node.jjtGetChild(i);
      if (childi instanceof ASTGroup) {
        group = true;
      }
    }

    // insert projection operator

    if (!(node instanceof ASTSelectQuery && ((ASTSelectQuery)node).isSelectAll())) {
      final Projection p = new Projection();
      final LinkedList<AddComputedBinding> listOfAddComputedBindings = new LinkedList<AddComputedBinding>();
      for (int i = 0; i < numberChildren; i++) {
        if (node.jjtGetChild(i) instanceof ASTVar) {
          final ASTVar variable = (ASTVar) node.jjtGetChild(i);
          p.addProjectionElement(new Variable(variable.getName()));
          onlyAggregations = false;
        } else if (node.jjtGetChild(i) instanceof ASTAs) {
          final ASTVar variable = (ASTVar) node.jjtGetChild(i)
              .jjtGetChild(1);
          final lupos.sparql1_1.Node constraint = node.jjtGetChild(i)
              .jjtGetChild(0);
          /*
           * Detecting Errors in SelectQuery if aggregations are used
           * and additional variables are not bound by a GROUP BY
           * statement
           */
          // this.prooveBoundedGroup(node.jjtGetChild(i));

          if (!(constraint instanceof ASTAggregation)) {
            onlyAggregations = false;
          }
          final Variable var2 = new Variable(variable.getName());
          p.addProjectionElement(var2);
          final AddComputedBinding acb = group ? new GroupByAddComputedBinding()
              : new AddComputedBinding();
          acb.addProjectionElement(var2, constraint);
          listOfAddComputedBindings.add(acb);
        }
      }
      // deleting of values if there is only an aggregation statement
      if (onlyAggregations || group) {
        connection.connectAndSetAsNewOperatorConnection(new Distinct());
      }
      listOACB = this.topologicalSorting(listOfAddComputedBindings);
      connection.connectAndSetAsNewOperatorConnection(p);
    }

    // insert sort operator
    for (int i = 0; i < numberChildren; i++) {
      if (node.jjtGetChild(i) instanceof ASTOrderConditions) {
        node.jjtGetChild(i).accept(this, connection);
      }
    }

    for (final AddComputedBinding acb : listOACB) {
      connection.connectAndSetAsNewOperatorConnection(acb);
    }

    // Dealing with the HAVING clause
    for (int i = 0; i < numberChildren; i++) {
      final Node childi = node.jjtGetChild(i);
      if (childi instanceof ASTHaving) {
        for (int k = 0; k < childi.jjtGetNumChildren(); k++) {
          if (childi.jjtGetChild(k) instanceof ASTFilterConstraint) {
            final Having filter = new Having((ASTFilterConstraint) childi
                .jjtGetChild(k));
            this.processExistChildren(node, graphConstraint, filter);
            filter.setEvaluator(this.evaluator);
            connection.connectAndSetAsNewOperatorConnection(filter);
          }
        }

      }
    }

    // Dealing with the GROUP clause
    for (int j = 0; j < numberChildren; j++) {
      final Projection p = new Projection();
      final LinkedList<AddComputedBinding> listOfAddComputedBindings = new LinkedList<AddComputedBinding>();
      ASTVar variable = null;
      final Node childi = node.jjtGetChild(j);
      onlyAggregations = true;
      if (childi instanceof ASTGroup) {
        for (int i = 0; i < childi.jjtGetNumChildren(); i++) {
          if (childi.jjtGetChild(i) instanceof ASTAdditionNode
              || childi.jjtGetChild(i) instanceof ASTSubtractionNode
              || childi.jjtGetChild(i) instanceof ASTMultiplicationNode
              || childi.jjtGetChild(i) instanceof ASTDivisionNode) {
            throw new Error(
                "Error in GROUP BY statement: AS not found");

          } else if (childi.jjtGetChild(i) instanceof ASTAs) {

            variable = (ASTVar) childi.jjtGetChild(i).jjtGetChild(1);
            final lupos.sparql1_1.Node constraint = childi.jjtGetChild(i).jjtGetChild(0);

            /*
             * Detecting Errors in SelectQuery if aggregations are
             * used and additional variables are not bound by a
             * GROUP BY statement
View Full Code Here

  }

  private boolean hasThisVariable(final Node node, final Item variable) {
    boolean resultOfMethod = false;
    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
      final Node n = node.jjtGetChild(i);
      if (n instanceof ASTVar
          && ((ASTVar) n).getName().equals(variable.getName())) {
        return true;
      }
      resultOfMethod |= this.hasThisVariable(n, variable);
View Full Code Here

   *            this {@link Filter}
   */
  private void processExistChildren(final Node node, final Item graphConstraint,
      final Filter filter) {
    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
      final Node n = node.jjtGetChild(i);
      if (n instanceof ASTExists || n instanceof ASTNotExists) {
        // TODO support also stream-based evaluators!
        if(this.indexScanCreator instanceof IndexScanCreator_BasicIndex){
          final IndexScanCreator_BasicIndex isc = (IndexScanCreator_BasicIndex) this.indexScanCreator;

          final Root collectionClone = (Root) isc.getRoot().clone();
          collectionClone.setSucceedingOperators(new LinkedList<OperatorIDTuple>());

          this.indexScanCreator = new IndexScanCreator_BasicIndex(collectionClone);

          final Result newResult = new Result();
          final OperatorConnection connection = new OperatorConnection(newResult);
          this.visit((ASTGroupConstraint) n.jjtGetChild(0), connection, graphConstraint);

          collectionClone.deleteParents();
          collectionClone.setParents();
          collectionClone.detectCycles();
          collectionClone.sendMessage(new BoundVariablesMessage());
View Full Code Here

    for (int j = 0; j < node.jjtGetNumChildren(); j++) {
      if (node.jjtGetChild(j) instanceof ASTPlusNode) {
        binding = new BindingsMap();
        for (int m = 0; m < node.jjtGetChild(j)
            .jjtGetNumChildren(); m++) {
          final Node litNode = node.jjtGetChild(j)
              .jjtGetChild(m);
          if (!(litNode instanceof ASTUndef)) {
            final Literal lit = LazyLiteral.getLiteral(litNode,
                true);
            binding.add(varList.get(m), lit);
View Full Code Here

  @Override
  public void visit(final ASTGroupConstraint node, final OperatorConnection connection, final Item graphConstraint) {
    try {
      // ------------------------------------------------------------------
      for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        final Node n = node.jjtGetChild(i);
        if (n instanceof ASTFilterConstraint) {
          n.accept(this, connection, graphConstraint);
        }
      }
      for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        final Node n = node.jjtGetChild(i);
        if (n instanceof ASTBind) {
          final ASTVar variable = (ASTVar) n.jjtGetChild(1);
          final Variable variable2 = new Variable(variable.getName());
          final Bind b = new Bind(variable2);
          b.addProjectionElement(variable2, n.jjtGetChild(0));
          connection.connectAndSetAsNewOperatorConnection(b, 0);
        }
      }
      for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        final Node n = node.jjtGetChild(i);
        if (n instanceof ASTOptionalConstraint) {
          final Optional opt = new Optional();
          connection.connectAndSetAsNewOperatorConnection(opt, 1);
          n.accept(this, connection, graphConstraint);
          connection.setOperatorConnection(opt, 0);
        } else if (n instanceof ASTMinus) {
          Minus minus = null;
          if (useSortedMinus) {
            // insert sort operator to preprocess for SortedMinus
            final Sort sortLeft = new Sort();
            final Sort sortRight = new Sort();
            minus = new SortedMinus(sortLeft, sortRight);

            connection.connectAndSetAsNewOperatorConnection(minus, 1);
            connection.connectAndSetAsNewOperatorConnection(sortRight);
            n.accept(this, connection, graphConstraint);
            connection.setOperatorConnection(minus, 0);
            connection.connectAndSetAsNewOperatorConnection(sortLeft);
          } else {
            minus = new Minus();

            connection.connectAndSetAsNewOperatorConnection(minus, 1);
            n.accept(this, connection, graphConstraint);
            connection.setOperatorConnection(minus, 0);
          }
        }
      }

      for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        final Node n = node.jjtGetChild(i);
        if (n instanceof ASTService) {
          this.serviceGenerator.insertFederatedQueryOperator((ASTService)n, connection);
        }
      }

      int numberUnionOrGraphConstraints = 0;
      final LinkedList<TriplePattern> triplePatternToJoin = new LinkedList<TriplePattern>();
      final LinkedList<ASTTripleSet> multipleOccurencesToJoin = new LinkedList<ASTTripleSet>();
      for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        final Node n = node.jjtGetChild(i);
        if (n instanceof ASTTripleSet) {
          final Node predicate = n.jjtGetChild(1);
          if (predicate instanceof ASTArbitraryOccurencesNotZero || predicate instanceof ASTArbitraryOccurences || predicate instanceof ASTOptionalOccurence) {
            multipleOccurencesToJoin.add((ASTTripleSet) n);
          } else {
            final TriplePattern tp = this.getTriplePattern((ASTTripleSet) n);
            triplePatternToJoin.add(tp);
          }
        } else if (this.isHigherConstructToJoin(n)) {
          if(!(n instanceof ASTService) ||  this.serviceGenerator.countsAsJoinPartner((ASTService)n)){
            numberUnionOrGraphConstraints++;
          }
        }
      }
      int numberJoinPartner = numberUnionOrGraphConstraints;
      if (triplePatternToJoin.size() > 0) {
        numberJoinPartner++;
      }
      numberJoinPartner+=multipleOccurencesToJoin.size();

      if (numberJoinPartner > 1) {
        final Join joinOperator = new Join();
        connection.connect(joinOperator);
        int j = 0;
        for (int i = 0; i < node.jjtGetNumChildren(); i++) {
          final Node n = node.jjtGetChild(i);
          connection.setOperatorConnection(joinOperator, j);
          if(this.handleHigherConstructToJoin(n, connection, graphConstraint)){
            j++;
          }
        }
        if (triplePatternToJoin.size() > 0) {
          connection.setOperatorConnection(joinOperator, j);
          this.indexScanCreator.createIndexScanAndConnectWithRoot(connection.getOperatorIDTuple(), triplePatternToJoin, graphConstraint);
          j++;
        }
        for(int i = 0; i < multipleOccurencesToJoin.size(); i++){
          connection.setOperatorConnection(joinOperator, j);
          this.createMultipleOccurence(multipleOccurencesToJoin.get(i), connection, graphConstraint);
          j++;
        }
      } else if (numberJoinPartner == 0) {
        this.indexScanCreator.createEmptyIndexScanSubmittingQueryResultWithOneEmptyBindingsAndConnectWithRoot(connection.getOperatorIDTuple(), graphConstraint);
      } else { // There should be only triple patterns or one
        // higher construct to join
        for (int i = 0; i < node.jjtGetNumChildren(); i++) {
          final Node n = node.jjtGetChild(i);
          if (n instanceof ASTTripleSet) {
            if (multipleOccurencesToJoin.size() == 1){
              this.createMultipleOccurence(multipleOccurencesToJoin.get(i), connection, graphConstraint);
              break;
            }
View Full Code Here

TOP

Related Classes of bst.Queue$Node

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.