Package lupos.engine.operators.singleinput

Examples of lupos.engine.operators.singleinput.ReplaceVar


public class RuleReplaceVarUnderProjection extends Rule {

  @Override
  protected void init() {
    final Projection projection = new Projection();
    final ReplaceVar replaceVar = new ReplaceVar();

    projection.setSucceedingOperator(new OperatorIDTuple(replaceVar, 0));
    replaceVar.setPrecedingOperator(projection);

    subGraphMap = new HashMap<BasicOperator, String>();
    subGraphMap.put(projection, "projection");
    subGraphMap.put(replaceVar, "replaceVar");
View Full Code Here


      final Map<String, BasicOperator> mso,
      final BasicOperator rootOperator) {
    final Collection<BasicOperator> deleted = new LinkedList<BasicOperator>();
    final Collection<BasicOperator> added = new LinkedList<BasicOperator>();
    final Projection projection = (Projection) mso.get("projection");
    final ReplaceVar replaceVar = (ReplaceVar) mso.get("replaceVar");

    // Clone ReplaceVar
    final ReplaceVar replaceVar_new = new ReplaceVar();
    replaceVar_new.setSubstitutionsVariableLeft(replaceVar
        .getSubstitutionsVariableLeft());
    replaceVar_new.setSubstitutionsVariableRight(replaceVar
        .getSubstitutionsVariableRight());

    replaceVar.removePrecedingOperator(projection);

    // Enhance projection variables by left tuple variables of ReplaceVar
    final LinkedList<Variable> vars = replaceVar
        .getSubstitutionsVariableLeft();
    for (int i = 0; i < vars.size(); i++) {
      if (!projection.getProjectedVariables().contains(vars.get(i))) {
        projection.addProjectionElement(vars.get(i));
      }
    }

    final LinkedList<BasicOperator> pres = (LinkedList<BasicOperator>) projection
        .getPrecedingOperators();
    final LinkedList<OperatorIDTuple> succs = (LinkedList<OperatorIDTuple>) replaceVar
        .getSucceedingOperators();

    BasicOperator pre;
    for (int i = 0; i < pres.size(); i++) {
      pre = pres.get(i);
      pre.addSucceedingOperator(new OperatorIDTuple(replaceVar_new, 0));
      pre.removeSucceedingOperator(projection);
    }

    replaceVar_new.setPrecedingOperators(pres);
    replaceVar_new
        .setSucceedingOperator(new OperatorIDTuple(projection, 0));

    projection.setPrecedingOperator(replaceVar_new);
    projection.setSucceedingOperators(succs);
View Full Code Here

    final Item[] generateItems = generate.getValueOrVariable();

    // System.out.println(generate.toString() + "---" + pat.toString());

    Filter filter = null;
    final ReplaceVar replaceVar = new ReplaceVar();
    replaceVar.setIntersectionVariables(new HashSet<Variable>());
    replaceVar.setUnionVariables(replaceVar.getIntersectionVariables());

    final LinkedList<Variable> addBindingsVar = new LinkedList<Variable>();
    final LinkedList<Literal> addBindingsLit = new LinkedList<Literal>();

    String filterConstraint = "Filter( ";
    for (int i = 0; i < 3; i++) {
      final Item patItem = patItems[i];
      final Item generateItem = generateItems[i];
      if ((!patItem.isVariable()) && generateItem.isVariable()) {
        filterConstraint += generateItems[i].toString() + " = "
            + patItems[i].toString() + " && ";
      } else if (patItem.isVariable() && generateItem.isVariable()) {
        replaceVar.addSubstitution((Variable) patItem,
            (Variable) generateItem);
        replaceVar.getIntersectionVariables().add((Variable) patItem);
      } else if (patItem.isVariable() && (!generateItem.isVariable())) {
        addBindingsVar.add((Variable) patItem);
        addBindingsLit.add((Literal) generateItem);
      } else if (!patItem.isVariable() && !generateItem.isVariable()
          && !generateItem.equals(patItem)) {
        // cannot match, remove generate.
        for (final BasicOperator parent : generate
            .getPrecedingOperators())
          parent.removeSucceedingOperator(generate);
        generate.getPrecedingOperators().clear();
        generate.removeFromOperatorGraph();
        return null;
      }
    }

    // If (?x = ?a) and (?x = ?b) then (valueOf(?a) = value(?b)) must be
    // fulfilled
    for (int i = 0; i < 2; i++) {
      for (int x = i + 1; x < 3; x++) {
        if (patItems[i].equals(patItems[x])) {
          filterConstraint += generateItems[i].toString() + " = "
              + generateItems[x].toString() + " && ";
        }
      }
    }

    if (!filterConstraint.equals("Filter( ")) {
      filterConstraint = filterConstraint.substring(0,
          filterConstraint.length() - 3)
          + ") ";

      try {
        final ASTFilterConstraint ASTfilter = (ASTFilterConstraint) SPARQL1_1Parser
            .parseFilter(filterConstraint);
        filter = new Filter(ASTfilter);
      } catch (final Exception e) {
        System.err
            .println("This should never happen in RuleReplaceGenPat!");
        System.err.println(e);
        e.printStackTrace();
      }
    }

    // Only Operators with a not empty definition are put into the
    // operatorgraph
    final LinkedList<BasicOperator> order = new LinkedList<BasicOperator>();
    if (filter != null) {
      order.add(filter);
      added.add(filter);
    }

    final int substVar = replaceVar.getSubstitutionsVariableLeft().size();

    if (substVar > 0) {
      order.add(replaceVar);
      added.add(replaceVar);
    } else {
      final Projection p = new Projection();
      p.setIntersectionVariables(new HashSet<Variable>());
      p.setUnionVariables(p.getUnionVariables());
      order.add(p);
      added.add(p);
    }
    if (addBindingsVar.size() > 0) {
      final Iterator<Literal> lit_it = addBindingsLit.iterator();
      final HashSet<Variable> hsv = new HashSet<Variable>();
      hsv.addAll(replaceVar.getUnionVariables());
      for (final Variable v : addBindingsVar) {
        final AddBinding ab = new AddBinding(v, lit_it.next());
        hsv.add(v);
        ab.setIntersectionVariables((HashSet<Variable>) hsv.clone());
        ab.setUnionVariables(ab.getIntersectionVariables());
View Full Code Here

public class RuleReplaceVarUnderJoin extends Rule {

  @Override
  protected void init() {
    final Join join = new Join();
    final ReplaceVar replaceVar = new ReplaceVar();

    join.setSucceedingOperator(new OperatorIDTuple(replaceVar, 0));
    replaceVar.setPrecedingOperator(join);

    subGraphMap = new HashMap<BasicOperator, String>();
    subGraphMap.put(join, "join");
    subGraphMap.put(replaceVar, "replaceVar");
View Full Code Here

  }

  @Override
  protected boolean checkPrecondition(final Map<String, BasicOperator> mso) {
    final Join join = (Join) mso.get("join");
    final ReplaceVar replaceVar = (ReplaceVar) mso.get("replaceVar");

    final LinkedList<Variable> replaceRightVars = replaceVar
        .getSubstitutionsVariableRight();
    final Object[] joinVars = join.getIntersectionVariables().toArray();
    // Only interesting if minimum one right ReduceEnv-Variable is not join
    // partner
    for (int i = 0; i < replaceRightVars.size(); i++) {
View Full Code Here

  }

  private ReplaceVar getReplaceAfterPre(final ReplaceVar replaceVar,
      final ReplaceVar originalClone, final BasicOperator pre,
      final Join join) {
    final ReplaceVar replaceAfterPre = new ReplaceVar();
    final Object[] unionPre = pre.getUnionVariables().toArray();

    final LinkedList<Variable> replaceVarsLeft = originalClone
        .getSubstitutionsVariableLeft();
    final LinkedList<Variable> replaceVarsRight = originalClone
        .getSubstitutionsVariableRight();
    final Object[] intersectionJoin = join.getIntersectionVariables()
        .toArray();

    for (int i = 0; i < replaceVarsLeft.size(); i++) {
      final Variable replaceVarRight = replaceVarsRight.get(i);
      final Variable replaceVarLeft = replaceVarsLeft.get(i);
      // Join gets (p,lit1) (p,lit2) and ReplaceVar has (x,p) => no
      // trigger
      // After incorrect Transformation Join could get (x,lit1) (p,lit2)
      // => trigger
      if (!arrayContains(intersectionJoin, replaceVarRight)) {
        // Right variable be replaced over join
        if (arrayContains(unionPre, replaceVarRight)) {
          replaceAfterPre.addSubstitution(replaceVarLeft,
              replaceVarRight);
          replaceVar.removeSubstitutionVars(i);
        }
      }
    }
View Full Code Here

      final Map<String, BasicOperator> mso,
      final BasicOperator rootOperator) {
    final Collection<BasicOperator> deleted = new LinkedList<BasicOperator>();
    final Collection<BasicOperator> added = new LinkedList<BasicOperator>();
    final Join join = (Join) mso.get("join");
    final ReplaceVar replaceVar = (ReplaceVar) mso.get("replaceVar");

    // Generate a clone
    final ReplaceVar originalClone = new ReplaceVar();
    originalClone.setSubstitutionsVariableLeft(replaceVar
        .getSubstitutionsVariableLeft());
    originalClone.setSubstitutionsVariableRight(replaceVar
        .getSubstitutionsVariableRight());

    final LinkedList<BasicOperator> pres = (LinkedList<BasicOperator>) join
        .getPrecedingOperators();

    BasicOperator pre;
    final LinkedList<Integer> indices = new LinkedList<Integer>();
    // Remark the operator-IDs of the precessors
    for (int i = 0; i < pres.size(); i++) {
      pre = pres.get(i);
      indices.add(pre.getOperatorIDTuple(join).getId());
    }

    ReplaceVar rep;
    Projection projectionPre;
    for (int i = 0; i < pres.size(); i++) {
      pre = pres.get(i);

      // Calculate the new ReplaceVar which will be replaced between the
      // i-th precessor and the join
      rep = getReplaceAfterPre(replaceVar, originalClone, pre, join);

      // Calculate projection after precessor and new ReplaceVar
      projectionPre = getProjectionAfterReplace(rep, pre);

      added.add(rep);
      added.add(projectionPre);

      pre.setSucceedingOperator(new OperatorIDTuple(rep, 0));
      rep.setPrecedingOperator(pre);
      rep.setSucceedingOperator(new OperatorIDTuple(projectionPre, 0));

      projectionPre.setPrecedingOperator(rep);
      projectionPre.setSucceedingOperator(new OperatorIDTuple(join,
          indices.get(i)));
      join.setPrecedingOperator(projectionPre);
View Full Code Here

          objectIsALiteral = true;
        } else {
          object = (Variable) itm;
        }
        final Node objectNode = tripleSet.jjtGetChild(2);
        final ReplaceVar replaceVar = new ReplaceVar();
        replaceVar.addSubstitution(object, subject);
        final Variable variable = this.getVariable(subject.toString(), object.toString(), "interimVariable");
        replaceVar.addSubstitution(variable, object);
        if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
          replaceVar.addSubstitution((Variable)graphConstraint, (Variable)graphConstraint);
        }
        final ReplaceVar replaceVari = new ReplaceVar();
        replaceVari.addSubstitution(subject, subject);
        replaceVari.addSubstitution(object, variable);
        if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
          replaceVari.addSubstitution((Variable)graphConstraint, (Variable)graphConstraint);
        }

        final BasicOperator startingOperator =tripleSet.jjtGetChild(1).jjtGetChild(0).accept(this, connection, graphConstraint, subject, object, subjectNode, objectNode);

        final InMemoryDistinct memoryDistinct = new InMemoryDistinct();
        final Filter filter = new Filter("(" + subject + " != " + object + ")");

        startingOperator.addSucceedingOperator(new OperatorIDTuple(filter,0));
        startingOperator.addSucceedingOperator(connection.getOperatorIDTuple());
        final Join intermediateJoinOperator = new Join();
        replaceVar.addSucceedingOperator(new OperatorIDTuple(memoryDistinct,0));
        memoryDistinct.addSucceedingOperator(new OperatorIDTuple(intermediateJoinOperator,1));
        filter.addSucceedingOperator(new OperatorIDTuple(intermediateJoinOperator,0));
        filter.addSucceedingOperator(new OperatorIDTuple(replaceVar,0));
        intermediateJoinOperator.addSucceedingOperator(new OperatorIDTuple(replaceVari,0));
        replaceVari.addSucceedingOperator(new OperatorIDTuple(replaceVar,0));
        replaceVari.addSucceedingOperator(connection.getOperatorIDTuple());

        if(subjectIsALiteral && !objectIsALiteral){
          final Filter firstFilter = new Filter("(" + subject + " = " + realSubject +")");
          final Filter secondFilter = new Filter("(" + subject + " = " + realSubject +")");
          final Projection firstProjection = new Projection();
          firstProjection.addProjectionElement(object);
          if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
            firstProjection.addProjectionElement((Variable)graphConstraint);
          }
          final Projection secondProjection = new Projection();
          secondProjection.addProjectionElement(object);
          if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
            secondProjection.addProjectionElement((Variable)graphConstraint);
          }

          firstFilter.addSucceedingOperator(new OperatorIDTuple(firstProjection,0));
          secondFilter.addSucceedingOperator(new OperatorIDTuple(secondProjection,0));

          firstProjection.addSucceedingOperator(connection.getOperatorIDTuple());
          secondProjection.addSucceedingOperator(connection.getOperatorIDTuple());

          replaceVari.addSucceedingOperator(new OperatorIDTuple(secondFilter,0));
          replaceVari.removeSucceedingOperator(connection.getOperatorIDTuple().getOperator());

          startingOperator.addSucceedingOperator(new OperatorIDTuple(firstFilter,0));
          startingOperator.removeSucceedingOperator(connection.getOperatorIDTuple().getOperator());

        }

        if(!subjectIsALiteral && objectIsALiteral){
          final Filter firstFilter = new Filter("(" + object + " = " + realObject + ")");
          final Filter secondFilter = new Filter("(" + object + " = " + realObject + ")");
          final Projection firstProjection = new Projection();
          firstProjection.addProjectionElement(subject);
          if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
            firstProjection.addProjectionElement((Variable)graphConstraint);
          }
          final Projection secondProjection = new Projection();
          secondProjection.addProjectionElement(subject);
          if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
            secondProjection.addProjectionElement((Variable)graphConstraint);
          }

          firstFilter.addSucceedingOperator(new OperatorIDTuple(firstProjection,0));
          secondFilter.addSucceedingOperator(new OperatorIDTuple(secondProjection,0));

          firstProjection.addSucceedingOperator(connection.getOperatorIDTuple());
          secondProjection.addSucceedingOperator(connection.getOperatorIDTuple());

          replaceVari.addSucceedingOperator(new OperatorIDTuple(secondFilter,0));
          replaceVari.removeSucceedingOperator(connection.getOperatorIDTuple().getOperator());

          startingOperator.addSucceedingOperator(new OperatorIDTuple(firstFilter,0));
          startingOperator.removeSucceedingOperator(connection.getOperatorIDTuple().getOperator());

        }
        if(subjectIsALiteral && objectIsALiteral){
          final Filter firstFilter = new Filter("(" + object + " = " + realObject + ")");
          final Filter secondFilter = new Filter("(" + subject + " = " + realSubject + ")");
          final Filter thirdFilter = new Filter("(" + object + " = " + realObject + ")");
          final Filter fourthFilter = new Filter("(" + subject + " = " + realSubject + ")");
          final Projection firstProjection = new Projection();
          firstProjection.addProjectionElement(subject);
          if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
            firstProjection.addProjectionElement((Variable)graphConstraint);
          }
          final Projection secondProjection = new Projection();
          secondProjection.addProjectionElement(object);
          if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
            secondProjection.addProjectionElement((Variable)graphConstraint);
          }
          final Projection thirdProjection = new Projection();
          thirdProjection.addProjectionElement(subject);
          if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
            thirdProjection.addProjectionElement((Variable)graphConstraint);
          }
          final Projection fourthProjection = new Projection();
          fourthProjection.addProjectionElement(object);
          if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
            fourthProjection.addProjectionElement((Variable)graphConstraint);
          }

          firstFilter.addSucceedingOperator(new OperatorIDTuple(firstProjection,0));
          secondFilter.addSucceedingOperator(new OperatorIDTuple(secondProjection,0));
          thirdFilter.addSucceedingOperator(new OperatorIDTuple(thirdProjection,0));
          fourthFilter.addSucceedingOperator(new OperatorIDTuple(fourthProjection,0));

          firstProjection.addSucceedingOperator(new OperatorIDTuple(secondFilter, 0));
          secondProjection.addSucceedingOperator(connection.getOperatorIDTuple());
          thirdProjection.addSucceedingOperator(new OperatorIDTuple(fourthFilter, 0));
          fourthProjection.addSucceedingOperator(connection.getOperatorIDTuple());

          replaceVari.addSucceedingOperator(new OperatorIDTuple(thirdFilter,0));
          replaceVari.removeSucceedingOperator(connection.getOperatorIDTuple().getOperator());

          startingOperator.addSucceedingOperator(new OperatorIDTuple(firstFilter,0));
          startingOperator.removeSucceedingOperator(connection.getOperatorIDTuple().getOperator());
        }
      }
View Full Code Here

      final Union union = new Union();
      final InMemoryDistinct memoryDistinct = new InMemoryDistinct();
      try {
        final Filter filter = new Filter("(" + subject + " != " + object + ")");

        final ReplaceVar replaceVar = new ReplaceVar();
        replaceVar.addSubstitution(object, subject);
        final Variable variable = this.getVariable(subject.toString(), object.toString(), "interimVariable");
        replaceVar.addSubstitution(variable, object);
        if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
          replaceVar.addSubstitution((Variable)graphConstraint, (Variable)graphConstraint);
        }
        final ReplaceVar replaceVari = new ReplaceVar();
        replaceVari.addSubstitution(subject, subject);
        replaceVari.addSubstitution(object, variable);
        if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
          replaceVari.addSubstitution((Variable)graphConstraint, (Variable)graphConstraint);
        }

        startingOperator.addSucceedingOperator(new OperatorIDTuple(filter,0));
        startingOperator.addSucceedingOperator(new OperatorIDTuple(union,1));
        final Join intermediateJoinOperator = new Join();
        replaceVar.addSucceedingOperator(new OperatorIDTuple(memoryDistinct,0));
        memoryDistinct.addSucceedingOperator(new OperatorIDTuple(intermediateJoinOperator,1));
        filter.addSucceedingOperator(new OperatorIDTuple(intermediateJoinOperator,0));
        filter.addSucceedingOperator(new OperatorIDTuple(replaceVar,0));
        intermediateJoinOperator.addSucceedingOperator(new OperatorIDTuple(replaceVari,0));
        replaceVari.addSucceedingOperator(new OperatorIDTuple(replaceVar,0));
        replaceVari.addSucceedingOperator(new OperatorIDTuple(union,1));
        union.addSucceedingOperator(new OperatorIDTuple(projection,0));

        //Zero Operator
        final BasicOperator startingPoint = this.zeroPath(node, graphConstraint, subject, object, subjectNode, objectNode);
View Full Code Here

      startingOperator.addSucceedingOperator(new OperatorIDTuple(closure,0));

      return closure;
    } else {
      // alternative way to evaluate (...)+ without using the Closure operator!
      final ReplaceVar replaceVar = new ReplaceVar();
      final ReplaceVar replaceVari = new ReplaceVar();
      final BasicOperator startingOperator = node.jjtGetChild(0).accept(this, connection, graphConstraint, subject, object, subjectNode, objectNode);

      final Projection projection = new Projection();
      projection.addProjectionElement(subject);
      projection.addProjectionElement(object);
      if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
        projection.addProjectionElement((Variable)graphConstraint);
      }

      final InMemoryDistinct memoryDistinct = new InMemoryDistinct();
      try {
        final Filter filter = new Filter("(" + subject + " != " + object + ")");

        replaceVar.addSubstitution(object, subject);
        final Variable variable = this.getVariable(subject.toString(), object.toString(), "interimVariable");
        replaceVar.addSubstitution(variable, object);
        if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
          replaceVar.addSubstitution((Variable)graphConstraint, (Variable)graphConstraint);
        }
        replaceVari.addSubstitution(subject, subject);
        replaceVari.addSubstitution(object, variable);
        if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
          replaceVari.addSubstitution((Variable)graphConstraint, (Variable)graphConstraint);
        }

        startingOperator.addSucceedingOperator(new OperatorIDTuple(filter,0));
        startingOperator.addSucceedingOperator(new OperatorIDTuple(projection,0));
        final Join intermediateJoinOperator = new Join();
        replaceVar.addSucceedingOperator(new OperatorIDTuple(memoryDistinct,0));
        memoryDistinct.addSucceedingOperator(new OperatorIDTuple(intermediateJoinOperator,1));
        filter.addSucceedingOperator(new OperatorIDTuple(intermediateJoinOperator,0));
        filter.addSucceedingOperator(new OperatorIDTuple(replaceVar,0));
        intermediateJoinOperator.addSucceedingOperator(new OperatorIDTuple(replaceVari,0));
        replaceVari.addSucceedingOperator(new OperatorIDTuple(replaceVar,0));
        replaceVari.addSucceedingOperator(new OperatorIDTuple(projection,0));

      } catch (final ParseException e) {
        System.out.println(e);
        e.printStackTrace();
      }
View Full Code Here

TOP

Related Classes of lupos.engine.operators.singleinput.ReplaceVar

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.