Package lupos.datastructures.items

Examples of lupos.datastructures.items.Triple


    if (distance == 0) {
      // special treatment: only one element!
      final ParallelIterator<Triple> it = (minimum == null) ? (ParallelIterator<Triple>) this
          .prefixSearch(key)
          : (ParallelIterator<Triple>) this.prefixSearch(minimum);
      final Triple t = it.next();
      it.close();
      if (t == null) {
        return null;
      }
      result.maximum = t.getPos(pos);
      result.minimum = result.maximum;
      final lupos.optimizations.logical.statistics.Entry entry = new lupos.optimizations.logical.statistics.Entry();
      entry.literal = result.maximum;
      entry.distinctLiterals = 1;
      entry.selectivity = 1.0;
View Full Code Here


      return -1;
    }
    try {
      final InputStream in = new PageInputStream(filename, this.pageManager);
      final boolean leaf = InputHelper.readLuposBoolean(in);
      Triple lastTriple = null;
      if (leaf) { // leaf node reached!
        while (true) {
          DBBPTreeEntry<TripleKey, Triple> e = this.getNextLeafEntry(in,
              (lastTriple == null) ? null : new TripleKey(
                  lastTriple, this.order), lastTriple);
View Full Code Here

    final InputStream fis;
    try {
      final InputStream in = new PageInputStream(filename, this.pageManager);
      final boolean leaf = InputHelper.readLuposBoolean(in);
      if (leaf) { // leaf node reached!
        Triple lastTriple = null;
        while (true) {
          final DBBPTreeEntry<TripleKey, Triple> e = this.getNextLeafEntry(
              in, (lastTriple == null) ? null : new TripleKey(
                  lastTriple, this.order), lastTriple);
          if (e == null || e.key == null) {
View Full Code Here

      this.comparator = sortedMap.comparator();
    }
    final Iterator<Entry<TripleKey, Triple>> it = sortedMap.entrySet()
        .iterator();

    final Triple previousTriple = null;
    while (it.hasNext()) {
      final Entry<TripleKey, Triple> entry = it.next();
      if (leaf.newNodeForNextEntry()) {
        boolean subjectDifferentFromPreviousTriple = true;
        boolean predicateDifferentFromPreviousTriple = true;
        boolean objectDifferentFromPreviousTriple = true;
        if (previousTriple != null) {
          if (previousTriple.getPos(0)
              .compareToNotNecessarilySPARQLSpecificationConform(
                  entry.getValue().getPos(0)) == 0) {
            subjectDifferentFromPreviousTriple = false;
          } else {
            subjectDifferentFromPreviousTriple = true;
          }
          if (previousTriple.getPos(1)
              .compareToNotNecessarilySPARQLSpecificationConform(
                  entry.getValue().getPos(1)) == 0) {
            predicateDifferentFromPreviousTriple = false;
          } else {
            predicateDifferentFromPreviousTriple = true;
          }
          if (previousTriple.getPos(2)
              .compareToNotNecessarilySPARQLSpecificationConform(
                  entry.getValue().getPos(2)) == 0) {
            objectDifferentFromPreviousTriple = false;
          } else {
            objectDifferentFromPreviousTriple = true;
View Full Code Here

    this.size = set.size();
    final Container leaf = new Container(this.size, this.k_, true);
    this.firstLeafPage = leaf.getFileName();
    final Iterator<Entry<TripleKey, Triple>> it = set.iterator();

    Triple previousTriple = null;
    while (it.hasNext()) {
      final Entry<TripleKey, Triple> entry = it.next();
      if (leaf.newNodeForNextEntry()) {
        boolean subjectDifferentFromPreviousTriple = true;
        boolean predicateDifferentFromPreviousTriple = true;
        boolean objectDifferentFromPreviousTriple = true;
        if (previousTriple != null) {
          if (previousTriple.getPos(0)
              .compareToNotNecessarilySPARQLSpecificationConform(
                  entry.getValue().getPos(0)) == 0) {
            subjectDifferentFromPreviousTriple = false;
          } else {
            subjectDifferentFromPreviousTriple = true;
          }
          if (previousTriple.getPos(1)
              .compareToNotNecessarilySPARQLSpecificationConform(
                  entry.getValue().getPos(1)) == 0) {
            predicateDifferentFromPreviousTriple = false;
          } else {
            predicateDifferentFromPreviousTriple = true;
          }
          if (previousTriple.getPos(2)
              .compareToNotNecessarilySPARQLSpecificationConform(
                  entry.getValue().getPos(2)) == 0) {
            objectDifferentFromPreviousTriple = false;
          } else {
            objectDifferentFromPreviousTriple = true;
View Full Code Here

          literals[i] = literal;
        } else {
          literals[i] = (Literal) item;
        }
      }
      final Triple t = new Triple(literals);
      boolean flag = false;
      for(final Indices indices: this.basicIndex.getRoot().dataset.getDefaultGraphIndices()){
        flag = indices.contains(t);
        if(flag){
          break;
View Full Code Here

  public void writeInnerNodeEntry(final int fileName, final TripleKey key,
      final OutputStream out, final TripleKey lastKey)
      throws IOException {
    final BitVector bits = new BitVector(7);
    bits.set(0);
    final Triple lastValue = (lastKey == null) ? null : lastKey.getTriple();
    final Triple v = key.getTriple();
    final boolean mustWriteLazyLiteralOriginalContent = (v.getObject() instanceof LazyLiteralOriginalContent)
        && (lastValue == null || !(lastValue.getObject().equals(v
            .getObject())));
    if (mustWriteLazyLiteralOriginalContent) {
      bits.set(1);
    } else {
      bits.clear(1);
    }
    int value = 0;
    if (lastValue == null) {
      value = 3;
    } else {
      for (int i = 0; i < 3; i++) {
        if (lastValue != null
            && v.getPos(map[this.order.ordinal()][i]).equals(
                lastValue.getPos(map[this.order.ordinal()][i]))) {
          value++;
        } else {
          break;
        }
      }
    }
    if (value <= 1) {
      bits.clear(2);
    } else {
      bits.set(2);
    }
    if (value % 2 == 0) {
      bits.clear(3);
    } else {
      bits.set(3);
    }

    int index = 3;

    for (int i = 0; i < 3; i++) {
      if (lastValue == null
          || !v.getPos(map[this.order.ordinal()][i]).equals(
              lastValue.getPos(map[this.order.ordinal()][i]))) {
        if (lastValue != null) {
          // determine difference
          final int diff = ((LazyLiteral) v.getPos(map[this.order
              .ordinal()][i])).getCode()
              - ((LazyLiteral) lastValue.getPos(map[this.order
                  .ordinal()][i])).getCode();
          index = determineNumberOfBytesForRepresentation(diff, bits, index, out);
        }
        for (int j = i + ((value == 3) ? 0 : 1); j < 3; j++) {
          // deal with the "rest"
          index = determineNumberOfBytesForRepresentation(
              ((LazyLiteral) v.getPos(map[this.order.ordinal()][j]))
                  .getCode(), bits, index, out);
        }
        break;
      }
    }
    if (mustWriteLazyLiteralOriginalContent) {
      index = determineNumberOfBytesForRepresentation(
          ((LazyLiteralOriginalContent) v.getObject())
              .getCodeOriginalContent(), bits, index, out);
    }
    index = determineNumberOfBytesForRepresentation(fileName, bits, index,
        out);
    bits.writeWithoutSize(out);
    writeIntWithoutLeadingZeros(fileName, out);

    if (mustWriteLazyLiteralOriginalContent) {
      writeIntWithoutLeadingZeros(((LazyLiteralOriginalContent) v
          .getObject()).getCodeOriginalContent(), out);
    }

    for (int i = 0; i < 3; i++) {
      if (lastValue == null
          || !v.getPos(map[this.order.ordinal()][i]).equals(
              lastValue.getPos(map[this.order.ordinal()][i]))) {
        if (lastValue != null) {
          // determine difference
          final int diff = ((LazyLiteral) v.getPos(map[this.order
              .ordinal()][i])).getCode()
              - ((LazyLiteral) lastValue.getPos(map[this.order
                  .ordinal()][i])).getCode();
          writeIntWithoutLeadingZeros(diff, out);
        }
        for (int j = i + ((value == 3) ? 0 : 1); j < 3; j++) {
          // deal with the "rest"
          writeIntWithoutLeadingZeros(((LazyLiteral) v
              .getPos(map[this.order.ordinal()][j])).getCode(), out);
        }
        break;
      }
    }
View Full Code Here

        whereDifferentLiteral = 2;
      }
      if (bits.get(3)) {
        whereDifferentLiteral += 1;
      }
      final Triple t = new Triple();
      if(whereDifferentLiteral==3 && lastTriple!=null){
        for(int i=0; i<3; i++) {
          t.setPos(i, lastTriple.getPos(i));
        }
      } else {
        final int numberDifferent = (whereDifferentLiteral==3)?3:3 - whereDifferentLiteral;
        final int[] numberBytesForInt = new int[numberDifferent];
        int index = 3;
        for (int i = 0; i < numberDifferent; i++) {
          numberBytesForInt[i] = getIntSize(bits, index, in);
          index = (index + 2) % 8;
        }
        int codeForOriginalContent = 0;
        if (objectIsLazyLiteralOriginalContent) {
          codeForOriginalContent = getInt(
              getIntSize(bits, index, in) + 1, in);
        }

        int index2 = 0;
        for (int i = 0; i < 3; i++) {
          if (i < whereDifferentLiteral && whereDifferentLiteral != 3) {
            t.setPos(map[this.order.ordinal()][i], lastTriple
                .getPos(map[this.order.ordinal()][i]));
          } else {
            if (whereDifferentLiteral != 3) {
              final int diff = getInt(
                  numberBytesForInt[index2++] + 1, in);
              t.setPos(map[this.order.ordinal()][i], getLiteral(diff
                  + ((LazyLiteral) lastTriple.getPos(map[this.order
                      .ordinal()][i])).getCode(), map[this.order
                  .ordinal()][i], codeForOriginalContent,
                  objectIsLazyLiteralOriginalContent));
            }
            for (int j = i + ((whereDifferentLiteral != 3) ? 1 : 0); j < 3; j++) {
              final int code = getInt(
                  numberBytesForInt[index2++] + 1, in);
              t.setPos(map[this.order.ordinal()][j], getLiteral(code,
                  map[this.order.ordinal()][j],
                  codeForOriginalContent,
                  objectIsLazyLiteralOriginalContent));
            }
            break;
View Full Code Here

        return null;
      }
      if (!bits.get(0)) {
        return new Tuple<TripleKey, Integer>(null, readInt(bits, 1, in));
      }
      final Triple lastTriple = (lastKey == null) ? null : lastKey
          .getTriple();

      final boolean objectIsLazyLiteralOriginalContent = bits.get(1);
      int whereDifferentLiteral = 0;
      if (bits.get(2)) {
        whereDifferentLiteral = 2;
      }
      if (bits.get(3)) {
        whereDifferentLiteral += 1;
      }
      final int numberDifferent = (whereDifferentLiteral == 3) ? 3
          : 3 - whereDifferentLiteral;
      final int[] numberBytesForInt = new int[numberDifferent];
      int index = 3;
      for (int i = 0; i < numberDifferent; i++) {
        numberBytesForInt[i] = getIntSize(bits, index, in);
        index = (index + 2) % 8;
      }
      int codeForOriginalContent = 0;
      if (objectIsLazyLiteralOriginalContent) {
        codeForOriginalContent = getInt(
            getIntSize(bits, index, in) + 1, in);
        index = (index + 2) % 8;
      }

      final int fileName = getInt(getIntSize(bits, index, in) + 1, in);

      final Triple t = new Triple();
      int index2 = 0;
      for (int i = 0; i < 3; i++) {
        if (i < whereDifferentLiteral && whereDifferentLiteral != 3) {
          t.setPos(map[this.order.ordinal()][i], lastTriple
              .getPos(map[this.order.ordinal()][i]));
        } else {
          if (whereDifferentLiteral != 3) {
            final int diff = getInt(
                numberBytesForInt[index2++] + 1, in);
            t.setPos(map[this.order.ordinal()][i], getLiteral(diff
                + ((LazyLiteral) lastTriple.getPos(map[this.order
                    .ordinal()][i])).getCode(), map[this.order
                .ordinal()][i], codeForOriginalContent,
                objectIsLazyLiteralOriginalContent));
          }
          for (int j = i + ((whereDifferentLiteral != 3) ? 1 : 0); j < 3; j++) {
            final int code = getInt(
                numberBytesForInt[index2++] + 1, in);
            t.setPos(map[this.order.ordinal()][j], getLiteral(code,
                map[this.order.ordinal()][j],
                codeForOriginalContent,
                objectIsLazyLiteralOriginalContent));
          }
          break;
View Full Code Here

        }

        private Bindings computeNext() {
          while (itt.hasNext()) {
            // also consider inner joins in triple patterns like ?a ?a ?b.
            Triple t;
            if (tp.getBloomFilters() != null
                && (tp.getBloomFilters()[0] != null
                    || tp.getBloomFilters()[1] != null || tp
                    .getBloomFilters()[2] != null)) {
              do {
                boolean considerLastTriple;
                if (this.lastTriple == null) {
                  this.lastTriple = itt.next();
                  considerLastTriple = true;
                } else {
                  considerLastTriple = false;
                }
                final Literal[] keyTriple = new Literal[3];
                boolean useKey = false;
                for (int j = 0; j < 3; j++) {
                  final int i = positions[order.ordinal()][j];
                  if (!useKey
                      && tp.getBloomFilters()[i] != null) {
                    int index = (Math.abs(this.lastTriple
                        .getPos(i).hashCode()) % SIPFilterOperator.NUMBEROFBITSFORBLOOMFILTER);
                    if (!tp.getBloomFilters()[i].get(index)) {
                      final int startIndex = index;
                      index++;
                      while ((index % tp
                          .getBloomFilters()[i]
                          .size()) != startIndex
                          && !tp.getBloomFilters()[i]
                              .get(index
                                  % tp
                                      .getBloomFilters()[i]
                                      .size())) {
                        index++;
                      }
                      // All bits are set to 0 in the
                      // bloom filter?
                      if (index
                          % tp.getBloomFilters()[i]
                              .size() == startIndex) {
                        return null;
                      }
                      // calculate distancepreserving jump over the gap!
                      final int code = ((LazyLiteral) this.lastTriple
                          .getPos(i)).getCode()
                          + (index - startIndex);
                      // if (code >=
                      // LazyLiteral.maxID())
                      // keyTriple[i] = lastTriple
                      // .getPos(i);
                      // else {
                      keyTriple[i] = new LazyLiteral(code);
                      useKey = true;
                      // }
                    } else {
                      keyTriple[i] = null;
                    }
                  } else {
                    keyTriple[i] = null;
                  }
                }
                if (useKey) {
                  // do distancepreserving jump over the gap!
                  final TripleKey key = tp.getKey(keyTriple,
                      order);
                  t = itt.next(key);
                } else {
                  t = (considerLastTriple) ? this.lastTriple : itt
                      .next();
                }
                this.lastTriple = t;
                if (t == null) {
                  return null;
                }
              } while ((tp.getBloomFilters()[0] != null && !tp
                  .getBloomFilters()[0]
                  .get((Math.abs(this.lastTriple.getPos(0)
                      .hashCode()) % SIPFilterOperator.NUMBEROFBITSFORBLOOMFILTER)))
                  || (tp.getBloomFilters()[1] != null && !tp
                      .getBloomFilters()[1]
                      .get((Math.abs(this.lastTriple.getPos(1)
                          .hashCode()) % SIPFilterOperator.NUMBEROFBITSFORBLOOMFILTER)))
                  || (tp.getBloomFilters()[2] != null && !tp
                      .getBloomFilters()[2]
                      .get((Math.abs(this.lastTriple.getPos(2)
                          .hashCode()) % SIPFilterOperator.NUMBEROFBITSFORBLOOMFILTER))));
            } else {
              t = itt.next();
            }
            if (t != null) {
              this.lastTriple = t;
              final Bindings znext = tp.process(t, false);
              if (znext != null) {
                return znext;
              }
            }
          }
          return null;
        }

        private Bindings computeNext(final Bindings k) {
          if (!(itt instanceof SIPParallelIterator)) {
            return this.computeNext();
          }
          final TripleKey key = tp.getKey(k, order);
          while (itt.hasNext()) {
            // also consider inner joins in triple patterns like
            // ?a ?a ?b.
            // Furthermore, do distancepreserving jump over the gap
            // using bloom filters!
            if (tp.getBloomFilters() != null) {
              for (int i = 0; i < 3; i++) {
                if (tp.getBloomFilters()[i] != null
                    && key.getTriple().getPos(i) != null) {
                  int index = (Math.abs(key.getTriple()
                      .getPos(i).hashCode()) % SIPFilterOperator.NUMBEROFBITSFORBLOOMFILTER);
                  if (!tp.getBloomFilters()[i].get(index)) {
                    final int startIndex = index;
                    index++;
                    while ((index % tp.getBloomFilters()[i]
                        .size()) != startIndex
                        && !tp.getBloomFilters()[i]
                            .get(index
                                % tp
                                    .getBloomFilters()[i]
                                    .size())) {
                      index++;
                    }
                    // all bits in the bloom filter are
                    // set
                    // to 0?
                    if (index
                        % tp.getBloomFilters()[i]
                            .size() == startIndex) {
                      return null;
                    }
                    // distancepreserving jump over the
                    // gap!
                    final int code = ((LazyLiteral) key
                        .getTriple().getPos(i))
                        .getCode()
                        + (index - startIndex);
                    // if (code < LazyLiteral.maxID())
                    key.getTriple().setPos(i,
                        new LazyLiteral(code));
                  }
                }
              }
            }
            final Triple t = itt.next(key);
            if (t != null) {
              this.lastTriple = t;
              final Bindings znext = tp.process(t, false);
              if (znext != null) {
                return znext;
View Full Code Here

TOP

Related Classes of lupos.datastructures.items.Triple

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.