Package lupos.sparql1_1

Examples of lupos.sparql1_1.ASTQuotedURIRef


    // return "PREFIX\t"+pref+":\t"+visitChild( node, 0 )+"\n";
    // }

    if (this.rules[BASE] && this.base != null) {
      final URI uri = URI.create(pref);
      final ASTQuotedURIRef content = (ASTQuotedURIRef) node
          .jjtGetChild(0);
      String qRef = content.getQRef();
      if (!uri.isAbsolute()) {
        // pref = "<"
        // + base.toString().substring(1,
        // base.toString().length() - 1) + pref + ">";
        try {
View Full Code Here


      final String name = blankNode.getIdentifier();
      literal = (allowLazyLiteral) ? LiteralFactory
          .createAnonymousLiteral(name) : LiteralFactory
          .createAnonymousLiteralWithoutLazyLiteral(name);
    } else if (n instanceof ASTQuotedURIRef) {
      final ASTQuotedURIRef uri = (ASTQuotedURIRef) n;
      final String name = uri.getQRef();

      if (URILiteral.isURI("<" + name + ">")) {
        try {
          literal = (allowLazyLiteral) ? LiteralFactory
              .createURILiteral("<" + name + ">")
              : LiteralFactory
                  .createURILiteralWithoutLazyLiteral("<"
                      + name + ">");
        } catch (final Exception e) {
          literal = (allowLazyLiteral) ? LiteralFactory
              .createLiteral("<" + name + ">") : LiteralFactory
              .createLiteralWithoutLazyLiteral("<" + name + ">");
        }
      } else {
        literal = (allowLazyLiteral) ? LiteralFactory.createLiteral("<"
            + name + ">") : LiteralFactory
            .createLiteralWithoutLazyLiteral("<" + name + ">");
      }
    } else if (n instanceof ASTRDFLiteral) {
      n = n.jjtGetChild(0);
    }

    if (literal != null) {
      return literal;
    }

    if (n instanceof ASTStringLiteral) {
      final ASTStringLiteral lit = (ASTStringLiteral) n;
      final String quotedContent = lit.getStringLiteral();

      literal = (allowLazyLiteral) ?
          LiteralFactory.createLiteral(quotedContent)
          : LiteralFactory.createLiteralWithoutLazyLiteral(quotedContent);
    } else if (n instanceof ASTInteger) {
      final ASTInteger lit = (ASTInteger) n;
      final String content = String.valueOf(lit.getValue());

      try {
        literal = (allowLazyLiteral) ? LiteralFactory
            .createTypedLiteral("\"" + content + "\"",
                "<http://www.w3.org/2001/XMLSchema#integer>")
            : TypedLiteralOriginalContent.createTypedLiteral("\""
                + content + "\"",
                "<http://www.w3.org/2001/XMLSchema#integer>");
      } catch (final URISyntaxException e) {
        literal = (allowLazyLiteral) ? LiteralFactory
            .createLiteral(content) : LiteralFactory
            .createLiteralWithoutLazyLiteral(content);
      }
    } else if (n instanceof ASTFloatingPoint) {
      final ASTFloatingPoint lit = (ASTFloatingPoint) n;
      final String content = lit.getValue();

      try {
        if (content.contains("e") || content.contains("E")) {
          literal = (allowLazyLiteral) ? LiteralFactory
              .createTypedLiteral("\"" + content + "\"",
                  "<http://www.w3.org/2001/XMLSchema#double>")
              : TypedLiteralOriginalContent
                  .createTypedLiteral("\"" + content + "\"",
                      "<http://www.w3.org/2001/XMLSchema#double>");
        } else {
          literal = (allowLazyLiteral) ? LiteralFactory
              .createTypedLiteral("\"" + content + "\"",
                  "<http://www.w3.org/2001/XMLSchema#decimal>")
              : TypedLiteralOriginalContent
                  .createTypedLiteral("\"" + content + "\"",
                      "<http://www.w3.org/2001/XMLSchema#decimal>");
        }
      } catch (final URISyntaxException e) {
        literal = (allowLazyLiteral) ? LiteralFactory
            .createLiteral(content) : LiteralFactory
            .createLiteralWithoutLazyLiteral(content);
      }
    } else if (n instanceof ASTBooleanLiteral) {
      final String content = ((ASTBooleanLiteral) n).getState() + "";

      try {
        literal = (allowLazyLiteral) ? LiteralFactory
            .createTypedLiteral("\"" + content + "\"",
                "<http://www.w3.org/2001/XMLSchema#boolean>")
            : TypedLiteralOriginalContent.createTypedLiteral("\""
                + content + "\"",
                "<http://www.w3.org/2001/XMLSchema#boolean>");
      } catch (final URISyntaxException e) {
        literal = (allowLazyLiteral) ? LiteralFactory
            .createLiteral(content) : LiteralFactory
            .createLiteralWithoutLazyLiteral(content);
      }
    } else if (n instanceof ASTDoubleCircumflex) {
      if (n.jjtGetNumChildren() != 2) {
        System.err.println(n + " is expected to have 2 children!");
      } else {
        final String content = getLiteral(n.jjtGetChild(0), false).toString();
        final String type = getLiteral(n.jjtGetChild(1), false).toString();

        try {
          literal = (allowLazyLiteral) ? LiteralFactory
              .createTypedLiteral(content, type)
              : TypedLiteralOriginalContent.createTypedLiteral(
                  content, type);
        } catch (final Exception e) {
          literal = (allowLazyLiteral) ? LiteralFactory
              .createLiteral(content + "^^" + type)
              : LiteralFactory
                  .createLiteralWithoutLazyLiteral(content
                      + "^^" + type);
        }
      }
    } else if (n instanceof ASTLangTag) {
      final String content = getLiteral(n.jjtGetChild(0), false).toString();
      final String lang = ((ASTLangTag) n).getLangTag();
      literal = (allowLazyLiteral) ? LiteralFactory
          .createLanguageTaggedLiteral(content, lang)
          : LanguageTaggedLiteralOriginalLanguage
              .createLanguageTaggedLiteral(content, lang);
    } else if (n instanceof ASTQName) {
      final ASTQName uri = (ASTQName) n;
      final String namespace = uri.getNameSpace();
      final String localName = uri.getLocalName();

      final String name = namespace + localName;

      if (URILiteral.isURI("<" + name + ">")) {
        try {
View Full Code Here

      // walk through first level children of AST...
      for (int i = 0; i < ast.jjtGetNumChildren(); ++i) {
        final Node child = ast.jjtGetChild(i); // get current child

        if (child instanceof ASTSelectQuery) {
          final ASTSelectQuery selectChild = (ASTSelectQuery) child;

          // SELECT is not the wildcard *...
          if (!selectChild.isSelectAll()) {
            // walk through select children...
            for (int j = 0; j < selectChild.jjtGetNumChildren(); ++j) {
              final Node selectChildChild = selectChild
              .jjtGetChild(j);

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

      }
    } else if(node instanceof ASTTripleSet){
      FederatedQuery.checkVariables(node, result);
    } else if(node instanceof ASTSelectQuery){
      // check embedded select queries recursively
      final ASTSelectQuery select = (ASTSelectQuery) node;
      final Set<Variable> innerQueryVariables = new HashSet<Variable>();
      final Set<Variable> innerQueryProjectedVariables = new HashSet<Variable>();
      for(final Node innerQueryChild: select.getChildren()){
        if(innerQueryChild instanceof ASTVar){
          final Variable v = new Variable(((ASTVar) innerQueryChild).getName());
          innerQueryProjectedVariables.add(v);
        } else if(innerQueryChild instanceof ASTGroupConstraint){
          innerQueryVariables.addAll(FederatedQuery.getSurelyBoundVariables(innerQueryChild));
        }
      }

      if(!select.isSelectAll()){
        innerQueryVariables.retainAll(innerQueryProjectedVariables);
      }
      result.addAll(innerQueryVariables);
    } else if(node instanceof ASTUnionConstraint){
      // Check union...
View Full Code Here

  }

  protected boolean handleHigherConstructToJoin(final Node n, final OperatorConnection connection, final Item graphConstraint){
    if (this.isHigherConstructToJoin(n)) {
      if(n instanceof ASTService){
        final ASTService service = (ASTService) n;
        if(this.serviceGenerator.countsAsJoinPartner(service)){
          this.serviceGenerator.insertIndependantFederatedQueryOperator(service, connection, this.indexScanCreator);
          return true;
        } else {
          return false;
View Full Code Here

  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

              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

  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

      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

      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

TOP

Related Classes of lupos.sparql1_1.ASTQuotedURIRef

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.