Package javolution.util

Examples of javolution.util.FastList$Node


  @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

    return getLiteral(n, false);
  }

  public static Literal getLiteral(final Node node, final boolean allowLazyLiteral) {
    Literal literal = null;
    Node n = node;

    if (n instanceof ASTNIL) {
      try {
        literal = (allowLazyLiteral) ? LiteralFactory
            .createURILiteral("<http://www.w3.org/1999/02/22-rdf-syntax-ns#nil>")
            : LiteralFactory
                .createURILiteralWithoutLazyLiteral("<http://www.w3.org/1999/02/22-rdf-syntax-ns#nil>");
      } catch (final URISyntaxException e1) {
        e1.printStackTrace();
      }
    } else if (n instanceof ASTBlankNode) {
      final ASTBlankNode blankNode = (ASTBlankNode) n;
      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 {
          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 ASTObjectList){
      literal = getLiteral(n.jjtGetChild(0), allowLazyLiteral);
    } else {
      System.err.println("Unexpected type! "
          + n.getClass().getSimpleName());
    }

    return literal;
  }
View Full Code Here

        String srcPath = versionableNode.getPath();
        String dstPath = getProperty("destination");
        wsp.copy(srcPath, dstPath);

        // check versionable
        Node v = (Node) ((org.apache.jackrabbit.api.jsr283.Session) superuser).getNode(dstPath);
        assertTrue("Copied Node.isNodeType(mix:simpleVersionable) must return true.",
                v.isNodeType(mixSimpleVersionable));
        assertFalse("Copied Node.isNodeType(mix:versionable) must return false.",
                v.isNodeType(mixVersionable));

        // check different version history
        VersionHistory vh1 = vMgr.getVersionHistory(srcPath);
        VersionHistory vh2 = vMgr.getVersionHistory(dstPath);
        assertFalse("Copied node needs a new version history.", vh1.isSame(vh2));
View Full Code Here

TOP

Related Classes of javolution.util.FastList$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.