Package lupos.datastructures.items.literal

Examples of lupos.datastructures.items.literal.Literal


        if (v.equals(item)) {
          break;
        }
        pos++;
      }
      final Literal min = this.getMin(v, triplePattern);
      if (min != null){
        // collation order is already set by getMin(...) method!
        result.put(v, new Tuple<Literal, Literal>(min, this.getMax(triplePattern, pos)));
      }
    }
View Full Code Here


    final Iterator<Bindings> itb = qr.oneTimeIterator();
    if (!itb.hasNext()) {
      this.setTriplePatterns(ztp);
      return null;
    }
    final Literal min = itb.next().get(v);
    if (itb instanceof ParallelIterator) {
      ((ParallelIterator<Bindings>) itb).close();
    }

    this.setTriplePatterns(ztp);
View Full Code Here

    this.setTriplePatterns(ztp);
    return min;
  }

  public Literal getMax(final TriplePattern tp, final int pos) {
    Literal max = null;
    try {

      // get the graph constraint from the super class.
      // If it is null, a default graph is used, if not null a named one
      // is used
      final Item graphConstraintItem = this.getGraphConstraint();

      // 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)) {
                    max = intermediateMax;
                  }
                }
              }
            }
          }

          // if the graph constraint is an URILiteral fetch the
          // matching indices object
          // but do not bind anything
          else {
            for (final Indices indices : indicesC) {

              final URILiteral rdfName = indices.getRdfName();
              if (namedGraphs.contains(rdfName)) {
                final Literal intermediateMax = this.getMaxLiteral(
                    (SixIndices) indices, key, pos);
                if (intermediateMax != null
                    && (max == null || max
                        .compareToNotNecessarilySPARQLSpecificationConform(intermediateMax) < 0)) {
                  max = intermediateMax;
                }
              }

            }
          }
        } else {
          if (indicesC != null) {
            // deal with special case: several default graphs!
            // if (triplePatterns.size() != 1) {
            // log.error("Can only process one triple pattern!");
            // }

            for (final Indices indices : indicesC) {
              final Literal intermediateMax = this.getMaxLiteral(
                  (SixIndices) indices, key, pos);
              if (intermediateMax != null
                  && (max == null || max
                      .compareToNotNecessarilySPARQLSpecificationConform(intermediateMax) < 0)) {
                max = intermediateMax;
View Full Code Here

      if (vba != null) {
        intermediate = getVarBuckets(tp, vba);
        if (intermediate.keySet().containsAll(joinPartnersTP)) {
          boolean flag = true;
          for (final Variable v : joinPartnersTP) {
            final Literal min = (minima == null) ? null : minima
                .get(v);
            if (intermediate.get(v) == null
                || min != null
                && (intermediate.get(v).minimum == null || min
                    .compareToNotNecessarilySPARQLSpecificationConform(intermediate
                        .get(v).minimum) != 0)) {
              flag = false;
              break;
            }
            final Literal max = (maxima == null) ? null : maxima
                .get(v);
            if (max != null
                && (intermediate.get(v).maximum == null || max
                    .compareToNotNecessarilySPARQLSpecificationConform(intermediate
                        .get(v).maximum) != 0)) {
              flag = false;
              break;
            }
          }
          if (flag) {
            intermediate.keySet().retainAll(joinPartnersTP);
            // if (classBindings == BindingsArrayVarMinMax.class) {
            for (final Variable v : intermediate.keySet()) {
              final VarBucket vb = intermediate.get(v);
              final Literal l[] = new Literal[vb.selectivityOfInterval
                  .size()];
              int indexLiteral = 0;
              for (final Entry entry : vb.selectivityOfInterval) {
                l[indexLiteral] = entry.literal;
                indexLiteral++;
              }
              tp.addHistogram(v, l, vb.getSum());
            }
            // }
            return intermediate;
          }
        }
      }
    }
    final Map<Variable, VarBucket> result = new HashMap<Variable, VarBucket>();
    for (final Variable v : joinPartnersTP) {
      final Literal min = (minima == null) ? null : minima.get(v);
      final Literal max = (maxima == null) ? null : maxima.get(v);
      if (intermediate != null && intermediate.containsKey(v)) {
        boolean flag = true;
        if (intermediate.get(v) == null
            || min != null
            && (intermediate.get(v).minimum == null || min
                .compareToNotNecessarilySPARQLSpecificationConform(intermediate
                    .get(v).minimum) != 0)) {
          flag = false;
        }
        if (max != null
            && (intermediate.get(v).maximum == null || max
                .compareToNotNecessarilySPARQLSpecificationConform(intermediate
                    .get(v).maximum) != 0)) {
          flag = false;
        }
        if (flag) {
          result.put(v, intermediate.get(v));
          continue;
        }
      }
      try {

        // get the graph constraint from the super class.
        // If it is null, a default graph is used, if not null a named
        // one
        // is used
        final Item graphConstraintItem = this.getGraphConstraint();

        // 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);
                if (vb != null) {
                  vb.minimum = (minima == null) ? null
                      : minima.get(v);
                  vb.maximum = (maxima == null) ? null
                      : maxima.get(v);
                  final VarBucket previous_vb = result.get(v);
                  if (previous_vb != null) {
                    vb.add(previous_vb);
                  }
                  result.put(v, vb);
                }
              }
            }
          }
        }
      } catch (final Exception e) {
        System.err.println("Error while joining triple patterns: "+ e);
        e.printStackTrace();
        return null;
      }

    }
    // if (classBindings == BindingsArrayVarMinMax.class) {
    for (final Variable v : result.keySet()) {
      final VarBucket vb = result.get(v);
      final Literal l[] = new Literal[vb.selectivityOfInterval.size()];
      int indexLiteral = 0;
      for (final Entry entry : vb.selectivityOfInterval) {
        l[indexLiteral] = entry.literal;
        indexLiteral++;
      }
View Full Code Here

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

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

    // if the item is a variable, check if this variable
    // is bound
    if (item.isVariable()) {

      final Literal literal = bindings.get((Variable) item);

      // if the variable is bound, use the literal for the key used
      // later on to query the map
      if (literal != null) {
        key.append(literal.toString());
        return true;
      }

    }
View Full Code Here

        final Bindings b = itb.next();
        if (b != null) {
          final Iterator<BitVector> ibv = bloomFilters.iterator();
          for (final Variable v : vars) {
            final BitVector bv = ibv.next();
            Literal literal = b.get(v);
            if(literal!=null){
              bv.set((Math.abs(literal.hashCode()) % NUMBEROFBITSFORBLOOMFILTER));
            }
          }
          if (!itb.hasNext()) {
            for (final TriplePattern tp : ctp) {
              // inform triple patterns of bloom filter!
View Full Code Here

    final DBMergeSortedBag<Bindings> bag = new DBMergeSortedBag<Bindings>(
        sortConfiguration, new Comparator<Bindings>() {
          public int compare(final Bindings arg0, final Bindings arg1) {
            for (final Variable var : sortCriterium) {
              final Literal l1 = arg0.get(var);
              final Literal l2 = arg1.get(var);
              if (l1 != null && l2 != null) {
                final int compare = l1
                    .compareToNotNecessarilySPARQLSpecificationConform(l2);
                if (compare != 0)
                  return compare;
View Full Code Here

   * @param bindings the intermediate solution
   * @return the value in bindings if item is a variable and bound in bindings, otherwise just item
   */
  private Item getItem(final Item item, final Bindings bindings){
    if(item.isVariable()){
      final Literal literal = bindings.get((Variable)item);
      if(literal!=null){
        return literal;
      }
    }
    return item;
View Full Code Here

TOP

Related Classes of lupos.datastructures.items.literal.Literal

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.