Examples of ASTVar


Examples of lupos.sparql1_1.ASTVar

  private void handleProjections(final SimpleNode node,
      final RetrieveDataWithProjectionAndSolutionModifier operator) {
    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
      if (node.jjtGetChild(i) instanceof ASTVar) {
        final ASTVar var = (ASTVar) node.jjtGetChild(i);

        try {
          operator.addProjectionElement(var.toQueryString());
        } catch (final ModificationException e) {
          e.printStackTrace();
        }
      } else if (node.jjtGetChild(i) instanceof ASTQuotedURIRef) {
        final ASTQuotedURIRef var = (ASTQuotedURIRef) node
        .jjtGetChild(i);

        try {
          operator.addProjectionElement(var.toQueryString());
        } catch (final ModificationException e) {
          e.printStackTrace();
        }
      }
    }
View Full Code Here

Examples of lupos.sparql1_1.ASTVar

              final Node selectChildChild = selectChild
              .jjtGetChild(j);

              // child of select is variable...
              if (selectChildChild instanceof ASTVar) {
                final ASTVar var = (ASTVar) selectChildChild;

                // add name of variable to order...
                if (!resultOrder.contains(var.getName())) {
                  resultOrder.add(var.getName());
                }
              } else if (selectChildChild instanceof ASTAs) {
                for (int j1 = 0; j1 < selectChildChild
                .jjtGetNumChildren(); ++j1) {
                  final Node selectChildChildChild = selectChildChild
                  .jjtGetChild(j1);
                  if (selectChildChildChild instanceof ASTVar) {
                    final ASTVar var = (ASTVar) selectChildChildChild;

                    // add name of variable to order...
                    if (!resultOrder.contains(var
                        .getName())) {
                      resultOrder.add(var
                          .getName());
                    }
                  }
                }
              }
View Full Code Here

Examples of lupos.sparql1_1.ASTVar

  public static Item getItem(final Node n) {
    if(n instanceof ASTObjectList) {
      return getItem(n.jjtGetChild(0));
    }
    if (n instanceof ASTVar) {
      final ASTVar var = (ASTVar) n;
      final String name = var.getName();
      return new Variable(name);
    } else {
      return LazyLiteral.getLiteral(n, true);
    }
  }
View Full Code Here

Examples of lupos.sparql1_1.ASTVar

      projection.addProjectionElement(subject);
      projection.addProjectionElement(object);
      if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
        projection.addProjectionElement((Variable)graphConstraint);
      }
      final ASTVar n = new ASTVar(100);
      n.setName(subject.toString().substring(1));
      final Bind bind = new Bind(subject);
      bind.addProjectionElement(object,n);
      union.addSucceedingOperator(new OperatorIDTuple(bind,0));
      bind.addSucceedingOperator(new OperatorIDTuple(projection,0));
      final InMemoryDistinct memoryDistinct = new InMemoryDistinct();
View Full Code Here

Examples of lupos.sparql1_1.ASTVar

      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
             */
            this.prooveBoundedGroup(constraint);

            if (!(constraint instanceof ASTAggregation)) {
              onlyAggregations = false;
            }
            final Variable var2 = new Variable(variable.getName());
            p.addProjectionElement(var2);

            final AddComputedBinding acb = new GroupByAddComputedBinding();
            acb.addProjectionElement(var2, constraint);
            listOfAddComputedBindings.add(acb);
View Full Code Here

Examples of lupos.sparql1_1.ASTVar

   */
  private void groupNegativeSyntaxTest(final lupos.sparql1_1.Node childi, final lupos.sparql1_1.Node node) {
    final LinkedList<Variable> groupVariables = new LinkedList<Variable>();
    for (int k = 0; k < childi.jjtGetNumChildren(); k++) {
      if (childi.jjtGetChild(k) instanceof ASTVar) {
        final ASTVar variable = (ASTVar) childi.jjtGetChild(k);
        groupVariables.add(new Variable(variable.getName()));
      } else if (childi.jjtGetChild(k) instanceof ASTAs) {
        final ASTVar variable = (ASTVar) childi.jjtGetChild(k).jjtGetChild(1);
        groupVariables.add(new Variable(variable.getName()));
      }
    }
    final LinkedList<Variable> selectVariables = new LinkedList<Variable>();
    for (int k = 0; k < node.jjtGetNumChildren(); k++) {
      if (node.jjtGetChild(k) instanceof ASTVar) {
        final ASTVar variable = (ASTVar) node.jjtGetChild(k);
        selectVariables.add(new Variable(variable.getName()));
      }
    }
    for (int k = 0; k < groupVariables.size(); k++) {
      boolean allVariablesFound = false;
      for (int l = 0; l < selectVariables.size(); l++) {
View Full Code Here

Examples of lupos.sparql1_1.ASTVar

  public void prooveBoundedGroup(final lupos.sparql1_1.Node node) {
    if (node.jjtGetChild(0) instanceof ASTAggregation) {
      for (int index = 0; index < node.jjtGetNumChildren(); index++) {
        if (node.jjtGetParent().jjtGetChild(index) instanceof ASTVar) {
          ASTVar varNode = (ASTVar) node.jjtGetParent().jjtGetChild(index);
          final Variable selectVar = new Variable(varNode.getName());
          boolean varChecked = false;
          for (int g = 0; g < node.jjtGetParent().jjtGetNumChildren(); g++) {
            if (node.jjtGetParent().jjtGetChild(g) instanceof ASTGroup) {
              if (node.jjtGetParent().jjtGetChild(g).jjtGetChild(0) instanceof ASTAs) {
                varNode = (ASTVar) node.jjtGetParent().jjtGetChild(g).jjtGetChild(0).jjtGetChild(1);
              } else {
                varNode = (ASTVar) node.jjtGetParent().jjtGetChild(g).jjtGetChild(0);
              }
              final Variable groupVar = new Variable(varNode.getName());
              if (groupVar.equals(selectVar)) {
                varChecked = true;
              }
            }
          }
View Full Code Here

Examples of lupos.sparql1_1.ASTVar

    // Getting the variables which are used in the BINDINGS clause
    final LinkedList<Variable> varList = new LinkedList<Variable>();

    for (int k = 0; k < node.jjtGetNumChildren(); k++) {
      if (node.jjtGetChild(k) instanceof ASTVar) {
        final ASTVar var2 = (ASTVar) node.jjtGetChild(k);
        final Variable variable = new Variable(var2.getName());
        varList.add(variable);
      }
    }

    // Creating the bindings with the variables and the literals
View Full Code Here

Examples of lupos.sparql1_1.ASTVar

        }
      }
      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);
        }
      }
View Full Code Here

Examples of org.openrdf.query.parser.serql.ast.ASTVar

        ASTProjectionElem projElemNode = new ASTProjectionElem(
            SyntaxTreeBuilderTreeConstants.JJTPROJECTIONELEM);
        selectNode.jjtAppendChild(projElemNode);
        projElemNode.jjtSetParent(selectNode);

        ASTVar varNode = new ASTVar(SyntaxTreeBuilderTreeConstants.JJTVAR);
        varNode.setName(varName);
        projElemNode.jjtAppendChild(varNode);
        varNode.jjtSetParent(projElemNode);
      }

      selectNode.setWildcard(false);
    }
    else {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.