Package lupos.engine.operators.singleinput

Examples of lupos.engine.operators.singleinput.ReplaceVar


  }

  @Override
  protected void init() {
    final TriplePattern tp = new TriplePattern();
    final ReplaceVar repVar = new ReplaceVar();

    tp.setSucceedingOperator(new OperatorIDTuple(repVar, 0));
    repVar.setPrecedingOperator(tp);

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


    startNode = repVar;
  }

  @Override
  protected boolean checkPrecondition(final Map<String, BasicOperator> mso) {
    final ReplaceVar repVar = (ReplaceVar) mso.get("repVar");
    // 1. Are there only triple patterns as preceding operators?
    // 1. Do the triple patterns have only repVar as succeeding operator?
    // 2. Are all variables of the triple patterns used in the ReplaceVar
    // operator?
    for (final BasicOperator bo : repVar.getPrecedingOperators()) {
      if (!(bo instanceof TriplePattern))
        return false;
      else {
        final TriplePattern tp = (TriplePattern) bo;
        if (tp.getSucceedingOperators().size() > 1)
          return false;
        for (final Variable v : tp.getVariables()) {
          int found = 0;
          for (final Variable v2 : repVar
              .getSubstitutionsVariableRight()) {
            if (v2.equals(v)) {
              found++;
            }
          }
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 ReplaceVar repVar = (ReplaceVar) mso.get("repVar");

    for (final OperatorIDTuple oidt : repVar.getSucceedingOperators())
      oidt.getOperator().removePrecedingOperator(repVar);

    for (final BasicOperator bo : repVar.getPrecedingOperators()) {
      final TriplePattern tp = (TriplePattern) bo; // this has been
      // checked in
      // checkPrecondition
      // Already checked in checkPrecondition: All variables in tp can be
      // replaced!
      for (final Variable v : tp.getVariables()) {
        final Variable rv = repVar.getReplacement(v);
        tp.replace(v, rv);
      }
      final List<OperatorIDTuple> list = new LinkedList<OperatorIDTuple>();
      list.addAll(repVar.getSucceedingOperators());
      tp.setSucceedingOperators(list);
      for (final OperatorIDTuple oidt : repVar.getSucceedingOperators())
        oidt.getOperator().addPrecedingOperator(tp);
    }

    // rootOperator.deleteParents();
    // rootOperator.setParents();
View Full Code Here

    super();
  }

  @Override
  protected void init() {
    final ReplaceVar rep1 = new ReplaceVar();
    final ReplaceVar rep2 = new ReplaceVar();

    rep1.setSucceedingOperator(new OperatorIDTuple(rep2, 0));
    rep2.setPrecedingOperator(rep1);

    subGraphMap = new HashMap<BasicOperator, String>();
    subGraphMap.put(rep1, "rep1");
    subGraphMap.put(rep2, "rep2");
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 ReplaceVar rep1 = (ReplaceVar) mso.get("rep1");
    final ReplaceVar rep2 = (ReplaceVar) mso.get("rep2");

    final ReplaceVar rep_new = new ReplaceVar();
    rep_new.setSubstitutionsVariableLeft(rep1
        .getSubstitutionsVariableLeft());
    rep_new.setSubstitutionsVariableRight(rep1
        .getSubstitutionsVariableRight());

    final LinkedList<Variable> rep1VarsLeft = rep1
        .getSubstitutionsVariableLeft();
    final LinkedList<Variable> rep1VarsRight = rep1
        .getSubstitutionsVariableRight();
    final LinkedList<Variable> rep2VarsRight = rep2
        .getSubstitutionsVariableRight();
    final LinkedList<Variable> rep2VarsLeft = rep2
        .getSubstitutionsVariableLeft();
    Variable var;
    int index = -1;
    for (int i = 0; i < rep2VarsRight.size(); i++) {
      var = rep2VarsRight.get(i);
      index = rep1VarsLeft.indexOf(var);
      // No transitivity
      if (index == -1) {
        rep_new.addSubstitution(rep2VarsLeft.get(i), rep2VarsRight
            .get(i)); // Duplicate prevention by addSubstitution
      }
      // (y,a),(x,y) => (y,a),(x,a)
      else {
        rep_new.addSubstitution(rep2VarsLeft.get(i), rep1VarsRight
            .get(index));
      }
    }

    final LinkedList<BasicOperator> pres = (LinkedList<BasicOperator>) rep1
        .getPrecedingOperators();
    final LinkedList<OperatorIDTuple> succs = (LinkedList<OperatorIDTuple>) rep2
        .getSucceedingOperators();

    // Set precessors
    BasicOperator pre;
    for (int i = 0; i < pres.size(); i++) {
      pre = pres.get(i);
      pre.addSucceedingOperator(new OperatorIDTuple(rep_new, pre
          .getOperatorIDTuple(rep1).getId()));
      pre.removeSucceedingOperator(rep1);
    }

    rep_new.setPrecedingOperators(pres);
    rep_new.setSucceedingOperators(succs);

    // Set successors
    BasicOperator succ;
    for (int i = 0; i < succs.size(); i++) {
      succ = succs.get(i).getOperator();
View Full Code Here

  }

  @Override
  protected void init() {
    final ReplaceLit repLit = new ReplaceLit();
    final ReplaceVar repVar = new ReplaceVar();

    repLit.setSucceedingOperator(new OperatorIDTuple(repVar, 0));
    repVar.setPrecedingOperator(repLit);

    subGraphMap = new HashMap<BasicOperator, String>();
    subGraphMap.put(repLit, "repLit");
    subGraphMap.put(repVar, "repVar");
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 ReplaceLit repLit = (ReplaceLit) mso.get("repLit");
    final ReplaceVar repVar = (ReplaceVar) mso.get("repVar");

    final ReplaceVar repVar_new = new ReplaceVar();
    repVar_new.setSubstitutionsVariableLeft(repVar
        .getSubstitutionsVariableLeft());
    repVar_new.setSubstitutionsVariableRight(repVar
        .getSubstitutionsVariableRight());
    repVar_new.setIntersectionVariables(repVar.getIntersectionVariables());
    repVar_new.setUnionVariables(repVar.getUnionVariables());

    final ReplaceLit repLit_new = new ReplaceLit();
    repLit_new.setSubstitutionsLiteralLeft(repLit
        .getSubstitutionsLiteralLeft());
    repLit_new.setSubstitutionsLiteralRight(repLit
        .getSubstitutionsLiteralRight());
    repLit_new.setIntersectionVariables(repLit.getIntersectionVariables());
    repLit_new.setUnionVariables(repLit.getUnionVariables());

    final LinkedList<Variable> repVarLeft = repVar
        .getSubstitutionsVariableLeft();
    final LinkedList<Variable> repVarRight = repVar
        .getSubstitutionsVariableRight();
    final LinkedList<Variable> repLitLeft = repLit
        .getSubstitutionsLiteralLeft();
    final LinkedList<Literal> repLitRight = repLit
        .getSubstitutionsLiteralRight();
    Variable var;
    int index = -1;
    for (int i = 0; i < repVarRight.size(); i++) {
      var = repVarRight.get(i);
      index = repLitLeft.indexOf(var);
      // (x,<a>),(y,x) => (x,<a>),(y,<a>)
      if (index > -1) {
        final Variable var2 = repVarLeft.get(i);
        repVar_new.removeSubstitution(var2, var);
        repLit_new.addSubstitution(var2, repLitRight.get(index));
      }
    }

    final LinkedList<BasicOperator> pres = (LinkedList<BasicOperator>) repLit
        .getPrecedingOperators();
    final LinkedList<OperatorIDTuple> succs = (LinkedList<OperatorIDTuple>) repVar
        .getSucceedingOperators();

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

    repVar_new.setPrecedingOperators(pres);
    repVar_new.setSucceedingOperator(new OperatorIDTuple(repLit_new, 0));

    repLit_new.setPrecedingOperator(repVar_new);
    repLit_new.setSucceedingOperators(succs);

    BasicOperator succ;
View Full Code Here

public class RuleOptimizeReplaceByPat extends Rule {

  @Override
  protected void init() {
    final TriplePattern pat = new TriplePattern();
    final ReplaceVar replaceVar = new ReplaceVar();

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

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

    // successor
    if (pat.getSucceedingOperators().size() != 1) {
      return false;
    }

    final ReplaceVar replaceVar = (ReplaceVar) mso.get("replaceVar");
    BasicOperator op = replaceVar.getSucceedingOperators().get(0)
        .getOperator();
    // Ignore ReplaceLit and get the Projection
    if (op instanceof ReplaceLit) {
      op = op.getSucceedingOperators().get(0).getOperator();
    }
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 TriplePattern pat = (TriplePattern) mso.get("pat");
    final ReplaceVar replaceVar = (ReplaceVar) mso.get("replaceVar");

    BasicOperator op = replaceVar.getSucceedingOperators().get(0)
        .getOperator();
    if (op instanceof ReplaceLit) {
      op = op.getSucceedingOperators().get(0).getOperator();
    }
    final Projection proj = (Projection) op;

    final LinkedList<Variable> replaceVarLeft = replaceVar
        .getSubstitutionsVariableLeft();
    final LinkedList<Variable> replaceVarRight = replaceVar
        .getSubstitutionsVariableRight();
    final Object[] projVars = proj.getProjectedVariables().toArray();
    final Item[] patItems = pat.getItems();

    Variable var;
    Variable newTripleVar;

    // Before transformation: TriplePattern generates (p,lit) ,
    // ReplaceVar makes (y,lit) [because it has the tupel (y,p)] and
    // the Projection deletes (p,lit)
    // => Transformation replaces p by y in TriplePattern directly
    for (int i = 0; i < patItems.length; i++) {
      if (patItems[i].isVariable()) {
        var = (Variable) patItems[i];
        if (!arrayContains(projVars, var)) {
          final LinkedList<Integer> indices = getPositions(
              replaceVarRight, var);
          // Variable can be substituted by a ReplaceVar-variable
          if (indices.size() > 0) {
            newTripleVar = replaceVarLeft.get(indices.getFirst());
            // Replacement in TriplePattern
            pat.replace(var, newTripleVar);
            // Replacement same Replacement in ReplaceVar
            for (int a = 1; a < indices.size(); a++) {
              replaceVarRight.set(indices.get(a), newTripleVar);
            }
            // Delete the Tupel for Replacement
            replaceVar.removeSubstitutionVars(indices.getFirst());
          }
        }
      }
    }

    // Delete empty ReplaceVar
    if (replaceVar.getSubstitutionsVariableLeft().size() == 0) {
      final OperatorIDTuple succ = replaceVar.getSucceedingOperators()
          .get(0);
      pat.addSucceedingOperator(succ);
      pat.removeSucceedingOperator(replaceVar);
      succ.getOperator().removePrecedingOperator(replaceVar);
      succ.getOperator().addPrecedingOperator(pat);
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.