Package lupos.datastructures.bindings

Examples of lupos.datastructures.bindings.Bindings


                return currentResult.hasNext();
              }

              @Override
              public Bindings next() {
                final Bindings b = currentResult.next();
                if (b != null) {
                  this.number++;
                }
                if (!currentResult.hasNext()) {
                  NAryMergeJoinWithoutSorting.this.realCardinality = this.number;
                  this.close();
                }
                return b;
              }

              public Bindings getNext(final Bindings k) {
                @SuppressWarnings("unchecked")
                final Bindings b = ((SIPParallelIterator<Bindings, Bindings>) currentResult)
                    .next(k);
                if (b != null) {
                  this.number++;
                }
View Full Code Here


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

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

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

              // 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,
View Full Code Here

              return true;
            }
            final Iterator<Bindings> itb = qr.oneTimeIterator();
            try {
              while (itb.hasNext()) {
                final Bindings b = itb.next();
                Literal literal = b.get(var);
                if (literal.originalStringDiffers()){
                  return false;
                } else if(!LiteralFactory.semanticInterpretationOfLiterals){
                  if(literal instanceof LazyLiteral){
                    literal = ((LazyLiteral) literal).getLiteral();
View Full Code Here

      final Integer[] minArray = new Integer[hmvi.size()];
      final Integer[] maxArray = new Integer[hmvi.size()];

      final Iterator<Bindings> itbSize = qrSize.oneTimeIterator();
      while (itbSize.hasNext()) {
        final Bindings b = itbSize.next();
        for (final Variable v : b.getVariableSet()) {
          final LazyLiteral ll = (LazyLiteral) b.get(v);
          final int pos = hmvi.get(v);
          if (minArray[pos] == null || minArray[pos] > ll.getCode()) {
            minArray[pos] = ll.getCode();
          }
          if (maxArray[pos] == null || maxArray[pos] < ll.getCode()) {
            maxArray[pos] = ll.getCode();
          }
        }
        size++;

        for (int i = 0; i < minArray.length; i++) {
          if (minArray[i] != null) {
            tp.addMinMaxLazyLiteral(i, minArray[i], maxArray[i]);
          }
        }
      }
    } else {
      int maxId = 1;
      if (qrSize instanceof IdIteratorQueryResult) {
        maxId = ((IdIteratorQueryResult) qrSize).getMaxId();
      }

      final int[][] min = new int[maxId][];
      final int[][] max = new int[maxId][];

      size = qrSize.oneTimeSize();

      for (int id = 0; id < maxId; id++) {
        if (min[id] != null) {
          for (int i = 0; i < min[id].length; i++) {
            tp.addMinMaxPresortingNumbers(i, min[id].length,
                id, min[id][i], max[id][i]);
          }
        }
      }
    }

    qrSize.release();

    if (size == 0) {
      System.out.println("No result for " + tp);
      return null;
    }

    // System.out.println("(Statistics) " + tp + ", " + size
    // + " triples retrieved");
    tp.setCardinality(size);

    for (final Variable v : joinPartnersTP) {
      if (intermediate != null && intermediate.containsKey(v)) {
        boolean flag = true;
        final Literal min = minima.get(v);
        if (intermediate.get(v) == null
            || min != null
            && (intermediate.get(v).minimum == null || !min
                .equals(intermediate.get(v).minimum))) {
          flag = false;
        }
        final Literal max = maxima.get(v);
        if (max != null
            && (intermediate.get(v).maximum == null || !max
                .equals(intermediate.get(v).maximum))) {
          flag = false;
        }
        if (flag) {
          result.put(v, intermediate.get(v));
          continue;
        }
      }
      // get result of triple pattern in the correct sorted way!
      final Collection<Variable> cv = new LinkedList<Variable>();
      cv.add(v);
      if (this instanceof RDF3XIndexScan) {
        ((RDF3XIndexScan) this).setCollationOrder(CollationOrder.getCollationOrder(tp, cv));
      }

      QueryResult qr = this.join(this.root.dataset);

      if (this instanceof MemoryIndexScan) {
        // additional sorting phase according to variable v needed
        // for memory index approach!
        final DBMergeSortedBag<Bindings> sort = new DBMergeSortedBag<Bindings>(
            new SortConfiguration(), new Comparator<Bindings>() {
              @Override
              public int compare(final Bindings arg0, final Bindings arg1) {
                return arg0.get(v).compareToNotNecessarilySPARQLSpecificationConform(arg1.get(v));
              }
            }, Bindings.class);
        final Iterator<Bindings> itb = qr.oneTimeIterator();
        while (itb.hasNext()) {
          sort.add(itb.next());
        }
        qr = QueryResult.createInstance(sort.iterator());
      }
      if (qr == null) {
        return result;
      }

      if (size == 0) {
        qr.release();
        return result;
      }
      final double bucketSize = (double) size / MaxNumberBuckets;
      final Iterator<Bindings> ib = qr.oneTimeIterator();
      final VarBucket vb = new VarBucket();
      vb.minimum = minima.get(v);
      vb.maximum = maxima.get(v);
      Entry currentEntry = new Entry();
      Literal lastLiteral = null;
      while (ib.hasNext()) {
        final Bindings b = ib.next();
        final Literal next = b.get(v);
        if (lastLiteral == null
            || lastLiteral
                .compareToNotNecessarilySPARQLSpecificationConform(next) != 0) {
          currentEntry.distinctLiterals += 1.0;
          lastLiteral = next;
        }
        currentEntry.selectivity += 1.0;
        if (currentEntry.selectivity >= bucketSize) {
          currentEntry.literal = b.get(v);
          if (ib.hasNext()) {
            Bindings b2 = ib.next();
            while (ib.hasNext()
                && b2
                    .get(v)
                    .compareToNotNecessarilySPARQLSpecificationConform(
                        currentEntry.literal) == 0) {
              currentEntry.selectivity += 1.0;
              b2 = ib.next();
            }
            vb.selectivityOfInterval.add(currentEntry);
            currentEntry = new Entry();
            currentEntry.distinctLiterals = 1.0;
            currentEntry.selectivity = 1.0;
            if (!ib.hasNext()
                && b2
                    .get(v)
                    .compareToNotNecessarilySPARQLSpecificationConform(
                        next) != 0) {
              currentEntry.literal = b2.get(v);
              vb.selectivityOfInterval.add(currentEntry);
            }
          } else {
            vb.selectivityOfInterval.add(currentEntry);
          }
View Full Code Here

        }
        return this.localIterator.next();
      }
     
      public ParallelIterator<Bindings> computeNextIterator(){
        final Bindings currentBindings = it.next();
        if(currentBindings==null){
          return null;
        }
        if(BasicIndexScanOptional.this.rdfGraph!=null && BasicIndexScanOptional.this.rdfGraph.isVariable()){
          Literal result = currentBindings.get((Variable)BasicIndexScanOptional.this.rdfGraph);
          if(result!=null){
            BasicIndexScanOptional.this.indexScanOperator.setGraphConstraint(result);
          } else {
            BasicIndexScanOptional.this.indexScanOperator.setGraphConstraint(BasicIndexScanOptional.this.rdfGraph);
          }
        }
       
        Collection<TriplePattern> tps = BasicIndexScanOptional.this.indexScanOperator.getTriplePattern();
        LinkedList<TriplePattern> tps_new = new LinkedList<TriplePattern>();
        for(TriplePattern tp: tps){
          Item[] items = new Item[3];
          for(int i=0; i<3; i++){
            Item currentItem = tp.getPos(i);
            if(currentItem.isVariable()){
              Literal result = currentBindings.get((Variable)currentItem);
              if(result!=null){
                items[i] = result;
              } else {
                items[i] = currentItem;
              }
View Full Code Here

    }

    @Override
    public Bindings next() {
      if(this.next!=null){
        final Bindings znext = this.next;
        this.next = null;
        return znext;
      } else {
        return this.computeNext();
      }
View Full Code Here

        return this.computeNext();
      }
    }

    public Bindings computeNext(){
      Bindings inter;
      do {
        inter = this.originalIterator.next();
        if(inter==null) {
          return null;
        }
      } while(inter.get(this.var)!= null && inter.get(this.var).compareToNotNecessarilySPARQLSpecificationConform(this.literal)!=0 && inter.get(this.var).compareToNotNecessarilySPARQLSpecificationConform(emptyURI)!=0);
      // comparison with emptyURI for running W3C testcases successfully (import of relative URI was meant to be the URI of the named graph!)
      inter.add(this.var, this.literal);
      return inter;
    }
View Full Code Here

TOP

Related Classes of lupos.datastructures.bindings.Bindings

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.