Package lupos.engine.operators.tripleoperator

Examples of lupos.engine.operators.tripleoperator.TriplePattern


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


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

public class RuleInsertGenerateAddEnv extends Rule {

  @Override
  protected void init() {
    final TriplePattern pat1 = new TriplePattern();
    final ReplaceLit repLit = new ReplaceLit();
    final TriplePattern pat2 = new TriplePattern();
    final BasicOperator succ = new BasicOperator();

    pat1.setSucceedingOperator(new OperatorIDTuple(repLit, 0));

    repLit.setPrecedingOperator(pat1);
    repLit.setSucceedingOperator(new OperatorIDTuple(succ, -1));

    pat2.addSucceedingOperator(new OperatorIDTuple(succ, -1));

    succ.setPrecedingOperator(repLit);
    succ.addPrecedingOperator(pat2);

    subGraphMap = new HashMap<BasicOperator, String>();
View Full Code Here

      System.out
          .println("ReplaceLit has more than one precessor => Change RuleInsertGenerateAddEnv!!!");
      return false;
    }

    final TriplePattern pat1 = (TriplePattern) mso.get("pat1");
    final TriplePattern pat2 = (TriplePattern) mso.get("pat2");
    if (!isSpecialCase(pat2.getItems(), pat1.getItems())) {
      return false;
    }

    // ReplaceLit should add the minimum of the extras from general to
    // special TriplePattern
    if (!replaceLitAddsExtras(pat2.getItems(), pat1.getItems(), repLit)) {
      return false;
    }

    final LinkedList<OperatorIDTuple> succsRepLit = (LinkedList<OperatorIDTuple>) repLit
        .getSucceedingOperators();
    final LinkedList<OperatorIDTuple> succsPat2 = (LinkedList<OperatorIDTuple>) pat2
        .getSucceedingOperators();
    // And they have got only the same successors with same operand-IDs
    return (equal(succsRepLit, succsPat2));
  }
View Full Code Here

  public List<List<LeafNodePlan>> split(List<LeafNodePlan> initialPlans) {
    // We split the plan at star-shaped joins!
    final HashMap<Item, LinkedList<LeafNodePlan>> starJoins = new HashMap<Item, LinkedList<LeafNodePlan>>();
    final HashMap<Item, LinkedList<LeafNodePlan>> helperStarJoins = new HashMap<Item, LinkedList<LeafNodePlan>>();
    for (final LeafNodePlan lnp : initialPlans) {
      TriplePattern tp = lnp.getTriplePatterns().iterator().next();
      final Item subject = tp.getPos(0);
      LinkedList<LeafNodePlan> list = starJoins.get(subject);
      if (list == null){
        list = new LinkedList<LeafNodePlan>();
     
      list.add(lnp);
      starJoins.put(subject, list);
      final Item predicate = tp.getPos(1);
      if (predicate instanceof Variable) {
        list = helperStarJoins.get(predicate);
        if (list == null)
          list = new LinkedList<LeafNodePlan>();
        list.add(lnp);
        helperStarJoins.put(predicate, list);
      }
      final Item object = tp.getPos(2);
      if (object instanceof Variable) {
        list = helperStarJoins.get(object);
        if (list == null)
          list = new LinkedList<LeafNodePlan>();
        list.add(lnp);
        helperStarJoins.put(object, list);
      }
    }
    final Collection<LinkedList<LeafNodePlan>> lltp = new LinkedList<LinkedList<LeafNodePlan>>();
    lltp.addAll(starJoins.values());
    for (final LinkedList<LeafNodePlan> ltp : lltp) {
      if (ltp.size() == 1) {
        // look if the object or predicate can be joined with other
        // triple patterns!
        final LeafNodePlan lnp = ltp.get(0);
        final TriplePattern tp = lnp.getTriplePatterns().iterator().next();
        if (tp.getPos(2) instanceof Variable) {
          if (starJoins.get(tp.getPos(2)) != null) {
            if (!tp.getPos(2).equals(tp.getPos(0))) {
              starJoins.get(tp.getPos(2)).add(lnp);
              starJoins.remove(tp.getPos(0));
              continue;
            }
          }
          if (helperStarJoins.get(tp.getPos(0)) != null) {
            boolean flagCont = false;
            for (final LeafNodePlan lnp2 : helperStarJoins.get(tp.getPos(0))) {
              final TriplePattern tp2 = lnp2.getTriplePatterns().iterator().next();
              if (!tp2.equals(tp)) {
                starJoins.get(tp2.getPos(0)).add(lnp);
                starJoins.remove(tp.getPos(0));
                flagCont = true;
                break;
              }
            }
            if (flagCont)
              continue;
          }
          if (helperStarJoins.get(tp.getPos(2)) != null) {
            boolean flagCont = false;
            for (final LeafNodePlan lnp2 : helperStarJoins.get(tp.getPos(2))) {
              final TriplePattern tp2 = lnp2.getTriplePatterns().iterator().next();
              if (!tp2.equals(tp)) {
                starJoins.get(tp2.getPos(0)).add(lnp);
                starJoins.remove(tp.getPos(0));
                flagCont = true;
                break;
              }
            }
            if (flagCont)
              continue;
          }
        }
        if (tp.getPos(1) instanceof Variable) {
          if (starJoins.get(tp.getPos(1)) != null) {
            if (!tp.getPos(1).equals(tp.getPos(0))) {
              starJoins.get(tp.getPos(1)).add(lnp);
              starJoins.remove(tp.getPos(0));
              continue;
            }
          }
          if (helperStarJoins.get(tp.getPos(0)) != null) {
            boolean flagCont = false;
            for (final LeafNodePlan lnp2 : helperStarJoins.get(tp.getPos(0))) {
              final TriplePattern tp2 = lnp2.getTriplePatterns().iterator().next();
              if (!tp2.equals(tp)) {
                starJoins.get(tp2.getPos(0)).add(lnp);
                starJoins.remove(tp.getPos(0));
                flagCont = true;
                break;
              }
            }
            if (flagCont)
              continue;
          }
          if (helperStarJoins.get(tp.getPos(1)) != null) {
            boolean flagCont = false;
            for (final LeafNodePlan lnp2 : helperStarJoins.get(tp.getPos(1))) {
              final TriplePattern tp2 = lnp2.getTriplePatterns().iterator().next();
              if (!tp2.equals(tp)) {
                starJoins.get(tp2.getPos(0)).add(lnp);
                starJoins.remove(tp.getPos(0));
                flagCont = true;
                break;
              }
            }
            if (flagCont)
              continue;
          }
        }
      }
    }
    @SuppressWarnings("unchecked")
    final LinkedList<LeafNodePlan>[] solution = new LinkedList[starJoins.size()];
    final Iterator<LinkedList<LeafNodePlan>> starJoinsIterator = starJoins
        .values().iterator();
    for (int i = 0; i < starJoins.size(); i++){
      solution[i] = starJoinsIterator.next();
    }

    if (solution.length == 1) {
      // We have to split one huge star-shaped join!

      // find out the two triple patterns with the smallest
      // cardinalities to split the join!
      final LeafNodePlan[] initialPlansArray = initialPlans.toArray(new LeafNodePlan[0]);
      int max0;
      int max1;
      if (initialPlansArray[0].getCardinality() <= initialPlansArray[1].getCardinality()) {
        max0 = 0;
        max1 = 1;
      } else {
        max0 = 1;
        max1 = 0;
      }
      for (int i = 2; i < initialPlansArray.length; i++) {
        if (initialPlansArray[i].getCardinality() < initialPlansArray[max1].getCardinality()) {
          if (initialPlansArray[i].getCardinality() < initialPlansArray[max0].getCardinality()) {
            max1 = max0;
            max0 = i;
          } else
            max1 = i;
        }
      }
      final LinkedList<LeafNodePlan> left = new LinkedList<LeafNodePlan>();
      left.add(initialPlansArray[max0]);
      final LinkedList<LeafNodePlan> right = new LinkedList<LeafNodePlan>();
      right.add(initialPlansArray[max1]);
      // now split the join by putting the current triple pattern to
      // the one, which will have the smallest
      // cardinality when joined with max0 or with max1!
      for (int i = 0; i < initialPlansArray.length; i++) {
        if (i == max0 || i == max1){
          continue;
        }
       
        Map<Variable, VarBucket> selectivityMax0 = Statistics.estimateJoinSelectivity(initialPlansArray[max0].getSelectivity(), initialPlansArray[i].getSelectivity());
        // compute the cardinality of the join result as well as its cost
        double cardMax0 = 0.0;
        if (selectivityMax0 != null) {
          if (selectivityMax0.size() > 0) {
            cardMax0 = selectivityMax0.values().iterator().next().getSum();
          }
        }       
       
        Map<Variable, VarBucket> selectivityMax1 = Statistics.estimateJoinSelectivity(initialPlansArray[max1].getSelectivity(), initialPlansArray[i].getSelectivity());
        // compute the cardinality of the join result as well as its cost
        double cardMax1 = 0.0;
        if (selectivityMax1 != null) {
          if (selectivityMax1.size() > 0) {
            cardMax1 = selectivityMax1.values().iterator().next().getSum();
          }
        }       
       
        if(cardMax0 < cardMax1){
          left.add(initialPlansArray[i]);
        } else {
          right.add(initialPlansArray[i]);
        }       
      }
      if (left.size() == 1 || right.size() == 1) {
        // greedy: just have two similar big subgraphs! Just distribute the leaf nodes with small sizes in the two subgraphs!
        Collections.sort(initialPlans,
            new Comparator<LeafNodePlan>() {
              @Override
              public int compare(final LeafNodePlan o1, final LeafNodePlan o2) {
                if (o1.getCardinality() == o2.getCardinality()){
                  return 0;
                } else if (o1.getCardinality() < o2.getCardinality()){
                  return -1;
                } else {
                  return 1;
                }
              }
            });
        left.clear();
        right.clear();
        boolean leftIsNext = true;
        for(LeafNodePlan lnp: initialPlans){
          if(leftIsNext){
            left.add(lnp);
          } else {
            right.add(lnp);
          }
          leftIsNext = !leftIsNext;
        }
        return this.generateResult(left, right);       
      } else {
        return this.generateResult(left, right);
      }
    } else {

      int max = 0;

      for (int i = 1; i < solution.length; i++) {
        if (solution[i].size() > solution[max].size())
          max = i;
      }
      if (solution[max].size() == 1) {
        // join is a path join

        // generate plans for paths by dividing the path in the middle:
        HashMap<Item, LeafNodePlan> subjects = new HashMap<Item, LeafNodePlan>();
        for(final LeafNodePlan lnp: initialPlans){
          TriplePattern tp=lnp.getTriplePatterns().iterator().next();
          subjects.put(tp.getPos(0), lnp);
        }
        LeafNodePlan startingLeafNode = null;
        // find the starting triple pattern of the path:
        for(final LeafNodePlan lnp: initialPlans){
          TriplePattern tp=lnp.getTriplePatterns().iterator().next();
          if(!subjects.containsKey(tp.getPos(2))){
            // found starting triple pattern of the path!
            startingLeafNode = lnp;
            break;
          }
        }
        // join path is a ring?! => just take one of the leaf nodes as starting point!
        if(startingLeafNode==null){
          startingLeafNode = initialPlans.get(0);
        }
        LinkedList<LeafNodePlan> splittedPart = new LinkedList<LeafNodePlan>();
        splittedPart.add(startingLeafNode);
        LeafNodePlan current = startingLeafNode;
        // now follow the path
        for(int i=1; i<initialPlans.size()/2; i++){
          TriplePattern tp = current.getTriplePatterns().iterator().next();
          LeafNodePlan lnp = subjects.get(tp.getPos(2));
          if(lnp!=null){
            splittedPart.add(lnp);
            current = lnp;
          } else {
            throw new RuntimeException("Expected that the join is a path join, but obviously it is not!");
View Full Code Here

    for (final TriplePattern pattern : this.triplePatterns) {
      final QueryResult iResult = result;
      result = QueryResult.createInstance();

      for(final Bindings b: iResult){
        final TriplePattern tpWithReplacedVariables = this.determineTriplePatternToEvaluate(pattern, b);
        final QueryResult resultOfTP = queryClientIndices.evaluateTriplePattern(tpWithReplacedVariables);
        if(resultOfTP!=null){
          result.addAll(this.addBindings(b, resultOfTP));
        }
      }
View Full Code Here

      }
    });
  }

  private TriplePattern determineTriplePatternToEvaluate(final TriplePattern pattern, final Bindings b) {
    return new TriplePattern(this.getItem(pattern.getPos(0), b), this.getItem(pattern.getPos(1), b), this.getItem(pattern.getPos(2), b));
  }
View Full Code Here

  public Tuple<Collection<BasicOperator>, Collection<BasicOperator>> transformOperatorGraph(
      final Map<String, BasicOperator> mso,
      final BasicOperator rootOperator) {
    final Collection<BasicOperator> deleted = new LinkedList<BasicOperator>();
    final Collection<BasicOperator> added = new LinkedList<BasicOperator>();
    final TriplePattern pat1 = (TriplePattern) mso.get("pat1");
    final ReplaceLit repLit = (ReplaceLit) mso.get("repLit");
    final TriplePattern pat2 = (TriplePattern) mso.get("pat2");

    final LinkedList<OperatorIDTuple> succs = (LinkedList<OperatorIDTuple>) repLit
        .getSucceedingOperators();

    final HashMap<Variable, Literal> constants = new HashMap<Variable, Literal>();

    final LinkedList<Variable> repLitLeft = repLit
        .getSubstitutionsLiteralLeft();
    final LinkedList<Literal> repLitRight = repLit
        .getSubstitutionsLiteralRight();
    for (int i = 0; i < repLitLeft.size(); i++) {
      constants.put(repLitLeft.get(i), repLitRight.get(i));
    }

    final HashMap<Variable, Literal> conditions = new HashMap<Variable, Literal>();
    final Item[] pat1Items = pat1.getItems();
    final Item[] pat2Items = pat2.getItems();
    Item i1;
    Item i2;
    for (int i = 0; i < 3; i++) {
      i1 = pat1Items[i];
      i2 = pat2Items[i];
      if ((!i1.isVariable()) && (i2.isVariable())) {
        conditions.put((Variable) i2, (Literal) i1);
      }
    }

    final GenerateAddEnv genAdd = new GenerateAddEnv(conditions, constants);

    pat1.removeSucceedingOperator(repLit);

    pat2.setSucceedingOperator(new OperatorIDTuple(genAdd, 0));

    genAdd.setPrecedingOperator(pat2);
    genAdd.setSucceedingOperators(succs);

    BasicOperator succ;
View Full Code Here

    final JSONArray itemsJson = (JSONArray) triplePatternJson.get("triple_pattern");
    final Item[] items = new Item[3];
    for (int h = 0; h < 3; h++) {
      items[h] = Helper.createItemFromJSON(itemsJson.getJSONObject(h));
    }
    return new TriplePattern(items[0], items[1], items[2]);
  }
View Full Code Here

public class RuleDeleteNotConnectedToResultOperator extends Rule {

  @Override
  protected void init() {
    final BasicOperator bo = new TriplePattern();

    subGraphMap = new HashMap<BasicOperator, String>();
    subGraphMap.put(bo, "bo");

    startNode = bo;
View Full Code Here

TOP

Related Classes of lupos.engine.operators.tripleoperator.TriplePattern

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.