Package lupos.datastructures.items

Examples of lupos.datastructures.items.Triple


  }

  protected static Triple getKey(final TriplePattern tp,
      final Bindings bindings) {
    final Item[] items = tp.getItems();
    final Triple key = new Triple();
    for (int i = 0; i < 3; i++) {
      if (items[i].isVariable()) {
        if (bindings != null
            && bindings.getVariableSet().contains(items[i])) {
          key.setPos(i, bindings.get((Variable) items[i]));
        } else {
          key.setPos(i, null);
        }
      } else {
        key.setPos(i, (Literal) items[i]);
      }
    }
    return key;
  }
View Full Code Here


  protected Triple getKey(final TriplePattern tp, final Bindings bindings,
      final Map<Variable, Literal> minMax) {
    boolean flag = false;
    final Item[] items = tp.getItems();
    final Triple key = new Triple();
    for (int i = 0; i < 3; i++) {
      if (items[i].isVariable()) {
        if (bindings != null
            && bindings.getVariableSet().contains(items[i])) {
          key.setPos(i, bindings.get((Variable) items[i]));
        } else {
          final Literal l = (minMax == null) ? null : minMax
              .get(items[i]);
          key.setPos(i, l);
          if (l != null) {
            flag = true;
          }
        }
      } else {
        key.setPos(i, (Literal) items[i]);
      }
    }
    return flag ? key : null;
  }
View Full Code Here

    final SixIndices sixIndices = (SixIndices) indices;
    if (this.triplePatterns.size() != 1) {
      System.err.println("Can only process one triple pattern!");
    }
    final TriplePattern tp = this.triplePatterns.iterator().next();
    final Triple key = getKey(tp, bindings);
    final Triple keyMinimum = this.getKeyMinimum(tp, bindings);
    final Triple keyMaximum = this.getKeyMaximum(tp, bindings);
    final Iterator<Triple> it = this.getIterator(sixIndices, key, keyMinimum,
        keyMaximum);

    if (!it.hasNext()) {
      return null;
View Full Code Here

      // get a collection of indices using the determined graph constraint
      final Collection<Indices> indicesC = this.root.dataset.indexingRDFGraphs(
          graphConstraintItem, false, false, this.root);
      if ((indicesC != null) && !(indicesC.size() == 0)) {
        final Triple key = getKey(tp, null);
        final Collection<URILiteral> namedGraphs = new ArrayList<URILiteral>();

        // if the graph constraint is not null (which means that a named
        // graph is used)
        if (graphConstraintItem != null) {

          if (graphConstraintItem instanceof Variable) {

            final Variable graphConstraint = (Variable) graphConstraintItem;

            // check if named graphs were provided at query time
            if (this.root.namedGraphs != null
                && this.root.namedGraphs.size() > 0) {

              // Convert the named graphs' names into URILiterals
              // to be applicable
              // later on
              for (final String name : this.root.namedGraphs) {

                final Indices indices = this.root.dataset
                    .getNamedGraphIndices(LiteralFactory
                        .createURILiteralWithoutLazyLiteral(name));

                final URILiteral rdfName = indices.getRdfName();
                if (namedGraphs.contains(rdfName)) {
                  final TriplePattern ztp = new TriplePattern(
                      graphConstraint
                          .equals(tp.getPos(0)) ? rdfName
                          : tp.getPos(0),
                      graphConstraint
                          .equals(tp.getPos(1)) ? rdfName
                          : tp.getPos(1),
                      graphConstraint
                          .equals(tp.getPos(2)) ? rdfName
                          : tp.getPos(2));
                  final Triple zkey = getKey(ztp, null);
                  final Literal intermediateMax = this.getMaxLiteral(
                      (SixIndices) indices, zkey, pos);
                  if (intermediateMax != null
                      && (max == null || max
                          .compareToNotNecessarilySPARQLSpecificationConform(intermediateMax) < 0)) {
                    max = intermediateMax;
                  }
                }

              }

            }

            // 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 = this.root.dataset
                  .getNamedGraphIndices();
              if (dataSetIndices != null) {

                for (final Indices indices : dataSetIndices) {
                  final TriplePattern ztp = new TriplePattern(
                      graphConstraint
                          .equals(tp.getPos(0)) ? indices
                          .getRdfName()
                          : tp.getPos(0),
                      graphConstraint
                          .equals(tp.getPos(1)) ? indices
                          .getRdfName()
                          : tp.getPos(1),
                      graphConstraint
                          .equals(tp.getPos(2)) ? indices
                          .getRdfName()
                          : tp.getPos(2));
                  final Triple zkey = getKey(ztp, null);
                  final Literal intermediateMax = this.getMaxLiteral(
                      (SixIndices) indices, zkey, pos);
                  if (intermediateMax != null
                      && (max == null || max
                          .compareToNotNecessarilySPARQLSpecificationConform(intermediateMax) < 0)) {
View Full Code Here

        // get a collection of indices using the determined graph
        // constraint
        final Collection<Indices> indicesC = this.root.dataset.indexingRDFGraphs(
            graphConstraintItem, false, false, this.root);
        if ((indicesC != null) && !(indicesC.size() == 0)) {
          final Triple key = getKey(tp, null);
          final Collection<URILiteral> namedGraphs = new ArrayList<URILiteral>();

          // if the graph constraint is not null (which means that a
          // named
          // graph is used)
          if (graphConstraintItem != null) {

            if (graphConstraintItem instanceof Variable) {

              final Variable graphConstraint = (Variable) graphConstraintItem;

              // check if named graphs were provided at query time
              if (this.root.namedGraphs != null
                  && this.root.namedGraphs.size() > 0) {

                // Convert the named graphs' names into
                // URILiterals
                // to be applicable
                // later on
                for (final String name : this.root.namedGraphs) {

                  final Indices indices = this.root.dataset
                      .getNamedGraphIndices(LiteralFactory
                          .createURILiteralWithoutLazyLiteral(name));

                  final URILiteral rdfName = indices
                      .getRdfName();
                  if (namedGraphs.contains(rdfName)) {
                    final TriplePattern ztp = new TriplePattern(
                        graphConstraint.equals(tp
                            .getPos(0)) ? rdfName
                            : tp.getPos(0),
                        graphConstraint.equals(tp
                            .getPos(1)) ? rdfName
                            : tp.getPos(1),
                        graphConstraint.equals(tp
                            .getPos(2)) ? rdfName
                            : tp.getPos(2));
                    final Triple zkey = getKey(ztp, null);
                    final Triple keyMinimum = this.getKey(ztp,
                        null, minima);
                    final Triple keyMaximum = this.getKey(ztp,
                        null, maxima);

                    final VarBucket vb = this.getVarBucket(v,
                        ztp, zkey, keyMinimum,
                        keyMaximum,
                        (SixIndices) indices);
                    if (vb != null) {
                      final VarBucket previous_vb = result
                          .get(v);
                      if (previous_vb != null) {
                        vb.add(previous_vb);
                      }
                      vb.minimum = (minima == null) ? null
                          : minima.get(v);
                      vb.maximum = (maxima == null) ? null
                          : maxima.get(v);
                      result.put(v, vb);
                    }
                  }

                }

              }

              // 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 = this.root.dataset
                    .getNamedGraphIndices();
                if (dataSetIndices != null) {

                  for (final Indices indices : dataSetIndices) {
                    final TriplePattern ztp = new TriplePattern(
                        graphConstraint.equals(tp
                            .getPos(0)) ? indices
                            .getRdfName() : tp
                            .getPos(0),
                        graphConstraint.equals(tp
                            .getPos(1)) ? indices
                            .getRdfName() : tp
                            .getPos(1),
                        graphConstraint.equals(tp
                            .getPos(2)) ? indices
                            .getRdfName() : tp
                            .getPos(2));
                    final Triple zkey = getKey(ztp, null);
                    final Triple keyMinimum = this.getKey(ztp,
                        null, minima);
                    final Triple keyMaximum = this.getKey(ztp,
                        null, maxima);
                    final VarBucket vb = this.getVarBucket(v,
                        ztp, zkey, keyMinimum,
                        keyMaximum,
                        (SixIndices) indices);
                    if (vb != null) {
                      final VarBucket previous_vb = result
                          .get(v);
                      if (previous_vb != null) {
                        vb.add(previous_vb);
                      }
                      vb.minimum = (minima == null) ? null
                          : minima.get(v);
                      vb.maximum = (maxima == null) ? null
                          : maxima.get(v);
                      result.put(v, vb);
                    }
                  }
                }
              }
            }

            // if the graph constraint is an URILiteral fetch the
            // matching indices object
            // but do not bind anything
            else {
              final Triple keyMinimum = this.getKey(tp, null, minima);
              final Triple keyMaximum = this.getKey(tp, null, maxima);
              for (final Indices indices : indicesC) {

                final URILiteral rdfName = indices.getRdfName();
                if (namedGraphs.contains(rdfName)) {
                  final VarBucket vb = this.getVarBucket(v, tp,
                      key, keyMinimum, keyMaximum,
                      (SixIndices) indices);
                  if (vb != null) {
                    final VarBucket previous_vb = result
                        .get(v);
                    if (previous_vb != null) {
                      vb.add(previous_vb);
                    }
                    vb.minimum = (minima == null) ? null
                        : minima.get(v);
                    vb.maximum = (maxima == null) ? null
                        : maxima.get(v);
                    result.put(v, vb);
                  }
                }

              }
            }
          } else {
            if (indicesC != null) {
              // deal with special case: several default graphs!
              // if (triplePatterns.size() != 1) {
              //log.error("Can only process one triple pattern!");
              // }
              final Triple keyMinimum = this.getKey(tp, null, minima);
              final Triple keyMaximum = this.getKey(tp, null, maxima);

              for (final Indices indices : indicesC) {
                final VarBucket vb = this.getVarBucket(v, tp, key,
                    keyMinimum, keyMaximum,
                    (SixIndices) indices);
View Full Code Here

              this.retrieveNewTriples();
            }
            if (this.newTriples == null || !this.newTriples.hasNext()) {
              return null;
            }
            final Triple triple = this.newTriples.next();
            final Bindings cB = this.currentBindings.clone();
            for (int i = 0; i < 3; i++) {
              if (tp.getPos(i).isVariable()) {
                final Literal l = cB.get((Variable) tp.getPos(i));
                if (l != null) {
                  if (!triple.getPos(i).equals(l)) {
                    return this.computeNext();
                  }
                } else {
                  cB.add((Variable) tp.getPos(i), triple.getPos(i));
                }
              }
            }
            cB.addTriple(triple);
            return cB;
View Full Code Here

      }

      @Override
      public Triple next() {
        if(this.triple!=null){
          final Triple inter_triple = this.triple;
          this.triple = null;
          return inter_triple;
        }
        return this.nextTriple();
      }
View Full Code Here

              this.retrieveNewTriples();
            }
            if (this.newTriples == null || !this.newTriples.hasNext()) {
              return null;
            }
            final Triple triple = this.newTriples.next();
            final Bindings cB = this.currentBindings.clone();
            for (int i = 0; i < 3; i++) {
              if (tp.getPos(i).isVariable()) {
                final Literal l = cB.get((Variable) tp.getPos(i));
                if (l != null) {
                  if (!triple.getPos(i).equals(l)) {
                    return this.computeNext();
                  }
                } else {
                  cB.add((Variable) tp.getPos(i), triple.getPos(i));
                }
              }
            }
            cB.addTriple(triple);
            return cB;
View Full Code Here

      final RDF3XIndexScan.CollationOrder collationOrder) {
    this.comparator = new TripleComparator(collationOrder);
    this.heap = new SequentialHeap<HeapEntry>(itia.length, true);
    for (int i = 0; i < itia.length; i++) {
      if (itia[i] != null) {
        final Triple t = itia[i].next();
        if (t != null) {
          this.heap.add(new HeapEntry(t, itia[i]));
        }
      }
    }
View Full Code Here

    if (this.heap.isEmpty()) {
      return null;
    }
    final HeapEntry next = this.heap.pop();
    if (next != null) {
      final Triple t = next.itt.next();
      if (t != null) {
        this.heap.add(new HeapEntry(t, next.itt));
      }
      this.idOfLastElement = next.itt.getId();
      return next.t;
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.