Package lupos.datastructures.items.literal

Examples of lupos.datastructures.items.literal.Literal


        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
          // object,
          // null is returned to indicate an unsolvable conflict
          if (literalB1 != null) {
            if (!literalB1.valueEquals(literalB2)) {
              return null;
            }
          }

          // otherwise add the new binding of the key and literal to
View Full Code Here


            }
            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

      if (vba != null) {
        intermediate = getVarBuckets(tp, vba);
        if (intermediate.keySet().containsAll(joinPartnersTP)) {
          boolean flag = true;
          for (final Variable v : joinPartners) {
            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;
              break;
            }
            final Literal max = maxima.get(v);
            if (max != null
                && (intermediate.get(v).maximum == null || !max
                    .equals(intermediate.get(v).maximum))) {
              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;
          }
        }
      }
    }
    // first determine the result size of the triple pattern!
    final Map<Variable, VarBucket> result = new HashMap<Variable, VarBucket>();
    final Collection<TriplePattern> ztp = this.getTriplePattern();
    final Collection<TriplePattern> ctp = new LinkedList<TriplePattern>();
    ctp.add(tp);
    this.setTriplePatterns(ctp);
    if (this instanceof RDF3XIndexScan) {
      ((RDF3XIndexScan) this).setCollationOrder(RDF3XOperatorGraphGenerator.getCollationOrder(tp, joinPartners));
      ((RDF3XIndexScan) this).setMinimaMaxima(minima, maxima);

    }
    final QueryResult qrSize = this.join(this.root.dataset);
    if (qrSize == null) {
      // System.out.println("No result for " + tp);
      return null;
    }

    int size = 0;

    if (classBindings == BindingsArrayVarMinMax.class) {
      final Map<Variable, Integer> hmvi = this.bindingsFactory.getPosVariables();
      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);
          }
        }
      }
      qr.release();
      result.put(v, vb);
      if (intermediate != null) {
        intermediate.put(v, vb);
      }
    }
    this.setTriplePatterns(ztp);

    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 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

          inter = this.originalIterator.next();
        } else {
          return null;
        }
        for(Variable v: this.bindingsToAdd.getVariableSet()){
          Literal literal = inter.get(v);
          if(literal!=null){
            flag = (literal.compareToNotNecessarilySPARQLSpecificationConform(this.bindingsToAdd.get(v))!=0);
          }
          inter.add(v, this.bindingsToAdd.get(v));
        }
        inter.addAllTriples(this.bindingsToAdd.getTriples());
      } while(flag);
View Full Code Here

      return false;
   
    do {
   
      Variable v=add.getVar();
      Literal l=add.getLiteral();
     
      lupos.sparql1_1.Node n = filter.getNodePointer();
      if (n.jjtGetNumChildren() > 0) {
        n = n.jjtGetChild(0);
        if (n instanceof lupos.sparql1_1.ASTEqualsNode) {
          lupos.sparql1_1.Node left = n.jjtGetChild(0);
          lupos.sparql1_1.Node right = n.jjtGetChild(1);
          if (right instanceof lupos.sparql1_1.ASTVar) {
            final lupos.sparql1_1.Node tmp = left;
            left = right;
            right = tmp;
          }
          if (left instanceof lupos.sparql1_1.ASTVar) {
            final String varname = ((lupos.sparql1_1.ASTVar) left)
                .getName();
            Variable var = new Variable(varname);
            VariableInInferenceRule varInference = new VariableInInferenceRule(varname);
 
            if (right instanceof lupos.sparql1_1.ASTQName
                || right instanceof lupos.sparql1_1.ASTQuotedURIRef
                || right instanceof lupos.sparql1_1.ASTFloatingPoint
                || right instanceof lupos.sparql1_1.ASTInteger
                || right instanceof lupos.sparql1_1.ASTStringLiteral
                || right instanceof lupos.sparql1_1.ASTDoubleCircumflex) {
              Literal constant = LazyLiteral.getLiteral(right);
             
              if(var.equals(v) || varInference.equals(v)){
                if(!l.equals(constant))
                  return true;
              }
View Full Code Here

      @Override
      public Bindings next() {
        final Bindings b = this.itb.next();
        if (b != null) {
          final Literal literal = b.get(AddBinding.this.var);
          if (literal == null) {
            b.add(AddBinding.this.var, AddBinding.this.literalName);
          }
          // if the item is a variable which is already bound
          // and the value differs from the value of the triple
          // which would be used as binding, a conflict is
          // detected
          else if (!literal.valueEquals(AddBinding.this.literalName)) {
            System.err.println("AddBinding received a bindings, where the variable is already bound to another value!");
            return null;
          }

        }
View Full Code Here

    this.sortCriterium = sortCriterium;
    compLocal = new Comparator<Bindings>() {

      public int compare(final Bindings o1, final Bindings o2) {
        for (final Variable var : sortCriterium) {
          final Literal l1 = o1.get(var);
          final Literal l2 = o2.get(var);
          if (l1 != null && l2 != null) {
            final int compare = l1
                .compareToNotNecessarilySPARQLSpecificationConform(l2);
            if (compare != 0)
              return compare;
View Full Code Here

      if(vars.size()>0) {
        final Map<Variable, Tuple<Literal, Literal>> localExtrema = indexScan.getMinMax(tp, vars);
        if(localExtrema!=null){
          for(final Entry<Variable, Tuple<Literal, Literal>> entry: localExtrema.entrySet()){
            final Variable var = entry.getKey();
            final Literal min = minima.get(var);
            final Literal otherMin = entry.getValue().getFirst();
            if(min==null || min.compareToNotNecessarilySPARQLSpecificationConform(otherMin)>0) {
              minima.put(var, otherMin);
            }

            final Literal max = maxima.get(var);
            final Literal otherMax = entry.getValue().getSecond();
            if(max==null || max.compareToNotNecessarilySPARQLSpecificationConform(otherMax)<0) {
              maxima.put(var, otherMax);
            }
          }
        }
View Full Code Here

      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;
          }
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.