Beispiel #1
0
  /** Create mapping pairs of objects of the embedding morphisms. */
  private void mapKernel2MultiObject(final MultiRule multiRule) {
    final OrdinaryMorphism embLeft = multiRule.getEmbeddingLeft();
    final Enumeration<GraphObject> domLeft = embLeft.getDomain();
    while (domLeft.hasMoreElements()) {
      final GraphObject kern = domLeft.nextElement();
      multiRule.mapKernel2MultiObject(kern, embLeft.getImage(kern));
    }
    //		final Enumeration<GraphObject> enLeft = multiRule.getLeft().getElements();
    //	  	while (enLeft.hasMoreElements()) {
    //	  		final GraphObject obj = enLeft.nextElement();
    //	       	if (embLeft.getInverseImage(obj).hasMoreElements()){
    //	       		multiRule.mapKernel2MultiObject(embLeft.getInverseImage(obj).nextElement(), obj);
    //	       	}
    //	  	}

    final OrdinaryMorphism embRight = multiRule.getEmbeddingRight();
    final Enumeration<GraphObject> domRight = embRight.getDomain();
    while (domRight.hasMoreElements()) {
      final GraphObject kern = domRight.nextElement();
      multiRule.mapKernel2MultiObject(kern, embRight.getImage(kern));
    }
    //	  	final Enumeration<GraphObject> enRight = multiRule.getRight().getElements();
    //	  	while (enRight.hasMoreElements()) {
    //	  		final GraphObject obj = enRight.nextElement();
    //	  		if (embRight.getInverseImage(obj).hasMoreElements()) {
    //	  			multiRule.mapKernel2MultiObject(embRight.getInverseImage(obj).nextElement(), obj);
    //	  		}
    //	  	}
  }
Beispiel #2
0
  /**
   * Save the rule scheme.
   *
   * @param h AGG XML helper
   */
  public void XwriteObject(XMLHelper h) {
    h.openNewElem("RuleScheme", this);
    h.addAttr("name", this.schemeName);
    if (!this.enabled) h.addAttr("enabled", "false");

    h.addAttr("disjointMultis", String.valueOf(this.disjointMultis));
    h.addAttr("parallelKernel", String.valueOf(this.parallelKernel));
    h.addAttr("checkConflict", String.valueOf(this.checkDeleteUseConflict));
    h.addAttr("atLeastOneMultiMatch", String.valueOf(this.atLeastOneMultiMatch));
    h.addAttr("index", this.itsIndex);

    h.openSubTag("Kernel");
    h.addObject("", this.kernelRule, true);
    h.close();

    for (int i = 0; i < this.multiRules.size(); i++) {
      h.openSubTag("Multi");
      final MultiRule r = (MultiRule) this.multiRules.get(i);
      h.addObject("", r, true);

      h.openSubTag("EmbeddingLeft");
      r.getEmbeddingLeft().writeMorphism(h);
      h.close();

      h.openSubTag("EmbeddingRight");
      r.getEmbeddingRight().writeMorphism(h);
      h.close();

      h.close();
    }

    if (this.amalgamRule != null) {
      h.openSubTag("Amalgamated");
      h.addObject("", this.amalgamRule, true);
      h.close();

      //			if (this.amalgamRule.getMatch() != null) {
      //				this.amalgamRule.getMatch().setName("MatchOf_" + this.amalgamRule.getName());
      //				h.openSubTag("MatchOf");
      //				h.addObject("Rule", this.amalgamRule, false);
      //				h.addObject("", this.amalgamRule.getMatch(), true);
      //				h.close();
      //			}
    }

    // TaggedValue layer
    h.openSubTag("TaggedValue");
    h.addAttr("Tag", "layer");
    h.addAttr("TagValue", this.layer);
    h.close();

    // TaggedValue priority
    h.openSubTag("TaggedValue");
    h.addAttr("Tag", "priority");
    h.addAttr("TagValue", this.priority);
    h.close();

    h.close();
  }
Beispiel #3
0
 public void clearMatchesOfMultiRules() {
   for (int i = 0; i < this.multiRules.size(); i++) {
     final MultiRule multiRule = (MultiRule) this.multiRules.get(i);
     if (multiRule.getMatch() != null) {
       multiRule.getMatch().dispose();
       multiRule.setMatch(null);
     }
     //			 ((VarTuple)
     // multiRule.getAttrContext().getVariables()).unsetVariables();//InputParameters();
   }
 }
Beispiel #4
0
 public Rule getRuleByQualifiedName(final String rname) {
   if (this.getName().equals(rname)) return this;
   else if (this.kernelRule.getName().equals(rname)
       || rname.equals(this.itsName + "." + this.kernelRule.getName())) return this.kernelRule;
   else {
     for (int i = 0; i < this.multiRules.size(); i++) {
       final MultiRule multiRule = (MultiRule) this.multiRules.get(i);
       if (multiRule.getName().equals(rname)
           || rname.equals(this.itsName + "." + multiRule.getName())) return multiRule;
     }
   }
   return null;
 }
Beispiel #5
0
 /**
  * Checks the left, right and rule morphism embedding of the kernel rule.
  *
  * @return true if embedding holds, otherwise false
  */
 public boolean isAmalgamable() {
   this.errorMsg = null;
   for (int i = 0; i < this.multiRules.size(); i++) {
     final MultiRule multiRule = (MultiRule) this.multiRules.get(i);
     if (!multiRule.isLeftEmbeddingValid()
         || !multiRule.isRightEmbeddingValid()
         || !multiRule.isMorphismEmbeddingValid()) {
       this.errorMsg = multiRule.getName();
       return false;
     }
   }
   return true;
 }
Beispiel #6
0
 /**
  * Replicate remove rule mapping of the kernel rule.
  *
  * @param go graph object of the kernel rule
  * @param left true if graph object belongs to the LHS of the kernel rule, otherwise false
  */
 public void propagateRemoveRuleMappingToMultiRule(final GraphObject go, boolean left) {
   for (int i = 0; i < this.multiRules.size(); i++) {
     final MultiRule multiRule = (MultiRule) this.multiRules.get(i);
     if (left) {
       GraphObject objL = multiRule.getEmbeddingLeft().getImage(go);
       if (objL != null) multiRule.removeMapping(go);
     } else {
       GraphObject objR = multiRule.getEmbeddingRight().getImage(go);
       if (objR != null && this.getInverseImage(objR).hasMoreElements())
         multiRule.removeMapping(this.getInverseImage(go).nextElement());
     }
   }
 }
Beispiel #7
0
 /**
  * Replicate new rule mapping of the kernel rule.
  *
  * @param leftgo graph object of the LHS of the kernel rule
  * @param rightgo graph object of the RHS of the kernel rule
  * @throws BadMappingException
  */
 public void propagateAddRuleMappingToMultiRule(
     final GraphObject leftgo, final GraphObject rightgo) throws BadMappingException {
   for (int i = 0; i < this.multiRules.size(); i++) {
     final MultiRule multiRule = (MultiRule) this.multiRules.get(i);
     try {
       GraphObject objL = multiRule.getEmbeddingLeft().getImage(leftgo);
       GraphObject objR = multiRule.getEmbeddingRight().getImage(rightgo);
       if (objL != null && objR != null) multiRule.addMapping(objL, objR);
     } catch (BadMappingException ex) {
       System.out.println(
           "RuleScheme.propagateCreatedMappingToMultiRule: " + ex.getLocalizedMessage());
       throw ex;
     }
   }
 }
Beispiel #8
0
  public void removeShiftedApplConditionsFromMultiRules() {
    for (int i = 0; i < this.multiRules.size(); i++) {
      Rule mRule = this.multiRules.get(i);

      ((MultiRule) mRule).removeShiftedKernelApplConds();

      this.removeAttrCondsOfKernelFromMultiRule(mRule);
    }
    this.shiftDone = false;
  }
Beispiel #9
0
  /**
   * Shift application conditions (NAC / PAC) of the kernel rule along embedding morphism of the
   * given multi rule (left embedding: kernel.LHS -> multi.LHS, right embedding: kernel.RHS ->
   * multi.RHS). Shifted application condition is added to the list of the own application
   * conditions of the multi rule.
   */
  private boolean shiftApplCondsOfKernelToMultiRule(final MultiRule multiRule) {
    // shift PACS
    List<OrdinaryMorphism> kernConds = this.kernelRule.getPACsList();
    for (int i = 0; i < kernConds.size(); i++) {
      OrdinaryMorphism kernCond = kernConds.get(i);
      if (kernCond.isEnabled()) {
        OrdinaryMorphism shiftCond =
            this.shiftApplCondAlongMorph(kernCond, multiRule.getEmbeddingLeft());
        if (shiftCond != null) {
          shiftCond.setName(kernCond.getName().concat("(shifted)"));
          shiftCond.setEnabled(kernCond.isEnabled());

          multiRule.addShiftedKernelApplCond(shiftCond, true);
          this.shiftDone = true;
        }
      }
    }
    // shift NACs
    kernConds = this.kernelRule.getNACsList();
    for (int i = 0; i < kernConds.size(); i++) {
      OrdinaryMorphism kernCond = kernConds.get(i);
      if (kernCond.isEnabled()) {
        OrdinaryMorphism shiftCond =
            this.shiftApplCondAlongMorph(kernCond, multiRule.getEmbeddingLeft());
        if (shiftCond != null) {
          shiftCond.setName(kernCond.getName().concat("(shifted)"));
          shiftCond.setEnabled(kernCond.isEnabled());

          multiRule.addShiftedKernelApplCond(shiftCond, false);
          this.shiftDone = true;
        }
      }
    }

    // shift NestedACs
    kernConds = this.kernelRule.getNestedACsList();
    for (int i = 0; i < kernConds.size(); i++) {
      if (kernConds.get(i) instanceof NestedApplCond) {
        NestedApplCond kernCond = (NestedApplCond) kernConds.get(i);
        if (kernCond.isEnabled()) {
          NestedApplCond shiftCond =
              this.shiftNestedApplCondAlongEmbMorphism(
                  kernCond,
                  multiRule.getEmbeddingLeft(),
                  this.kernelRule.getRight().getAttrContext());
          if (shiftCond != null) {
            shiftCond.setName(kernCond.getName().concat("(shifted)"));
            shiftCond.setEnabled(kernCond.isEnabled());

            multiRule.addShiftedKernelNestedApplCond(shiftCond);
            this.shiftDone = true;
          }
        }
      } else break;
    }

    addAttrCondsOfKernelToMultiRule(multiRule);

    return true;
  }
Beispiel #10
0
  /** Create new multi rule with embedding of the kernel rule. */
  public MultiRule createMultiRule(final String ruleName) {
    OrdinaryMorphism embL = this.kernelRule.getLeft().plainCopy();
    if (embL == null) {
      embL =
          new OrdinaryMorphism(
              this.kernelRule.getLeft(),
              BaseFactory.theFactory().createGraph(this.kernelRule.getLeft().getTypeSet(), false),
              agg.attribute.impl.AttrTupleManager.getDefaultManager()
                  .newContext(AttrMapping.PLAIN_MAP));
    }
    OrdinaryMorphism embR = this.kernelRule.getRight().plainCopy();
    if (embR == null) {
      embR =
          new OrdinaryMorphism(
              this.kernelRule.getRight(),
              BaseFactory.theFactory().createGraph(this.kernelRule.getRight().getTypeSet(), false),
              agg.attribute.impl.AttrTupleManager.getDefaultManager()
                  .newContext(AttrMapping.PLAIN_MAP));
    }
    MultiRule multiRule = new MultiRule(this.kernelRule, embL, embR);
    // add only variables of LHS and RHS
    if (this.kernelRule.hasNACs() || this.kernelRule.hasPACs()) {
      final Vector<String> list = this.kernelRule.getLeft().getVariableNamesOfAttributes();
      list.addAll(this.kernelRule.getRight().getVariableNamesOfAttributes());
      multiRule.addToAttrContextAccordingList(
          (VarTuple) this.kernelRule.getAttrContext().getVariables(), list);
    } else {
      multiRule.addToAttrContext((VarTuple) this.kernelRule.getAttrContext().getVariables());
    }

    multiRule.setRuleScheme(this);
    multiRule.setName(ruleName);
    multiRule.getLeft().setKind(GraphKind.LHS);
    multiRule.getRight().setKind(GraphKind.RHS);

    this.multiRules.add(multiRule);

    this.kernelRule.getLeft().addObserver(multiRule);
    this.kernelRule.getRight().addObserver(multiRule);
    this.kernelRule.addObserver(multiRule);

    this.kernelRule.setChanged(false);

    return multiRule;
  }
Beispiel #11
0
  /* Create an empty multi rule.
   */
  protected MultiRule createEmptyMultiRule() {
    MultiRule multiRule = new MultiRule(this.kernelRule.getTypeSet());

    multiRule.setEmbeddingLeft(
        new OrdinaryMorphism(
            this.kernelRule.getLeft(),
            multiRule.getLeft(),
            agg.attribute.impl.AttrTupleManager.getDefaultManager()
                .newContext(AttrMapping.PLAIN_MAP)));

    multiRule.setEmbeddingRight(
        new OrdinaryMorphism(
            this.kernelRule.getRight(),
            multiRule.getRight(),
            agg.attribute.impl.AttrTupleManager.getDefaultManager()
                .newContext(AttrMapping.PLAIN_MAP)));

    multiRule.setRuleScheme(this);

    this.multiRules.add(multiRule);

    return multiRule;
  }
Beispiel #12
0
  /**
   * Load the rule scheme.
   *
   * @param h AGG XML helper
   */
  public void XreadObject(XMLHelper h) {
    if (h.isTag("RuleScheme", this)) {
      Object attr_str = "";

      //			setSchemeName(h.readAttr("name"));

      attr_str = h.readAttr("atLeastOneMultiMatch");
      if (!"".equals(attr_str)) {
        this.atLeastOneMultiMatch = Boolean.valueOf((String) attr_str).booleanValue();
      }

      attr_str = h.readAttr("checkConflict");
      if (!"".equals(attr_str)) {
        this.checkDeleteUseConflict = Boolean.valueOf((String) attr_str).booleanValue();
      }

      attr_str = h.readAttr("disjointMultis");
      if (!"".equals(attr_str)) {
        this.disjointMultis = Boolean.valueOf((String) attr_str).booleanValue();
      }

      attr_str = h.readAttr("enabled");
      if (!"".equals(attr_str)) {
        this.enabled = Boolean.valueOf((String) attr_str).booleanValue();
      }

      attr_str = h.readAttr("index");
      if (!"".equals(attr_str)) {
        this.itsIndex = Integer.valueOf((String) attr_str).intValue();
      }

      attr_str = h.readAttr("name");
      if (!"".equals(attr_str)) {
        setSchemeName((String) attr_str);
      }

      attr_str = h.readAttr("parallelKernel");
      if (!"".equals(attr_str)) {
        this.parallelKernel = Boolean.valueOf((String) attr_str).booleanValue();
      }

      if (h.readSubTag("Kernel")) {
        h.getObject("", this.kernelRule, true);
        h.close();
        this.kernelRule.getLeft().setKind(GraphKind.LHS);
        this.kernelRule.getRight().setKind(GraphKind.RHS);
        this.kernelRule.setRuleScheme(this);
      }

      while (h.readSubTag("Multi")) {
        MultiRule mr = createEmptyMultiRule();
        h.getObject("", mr, true);

        if (h.readSubTag("EmbeddingLeft")) {
          mr.getEmbeddingLeft().readMorphism(h);
          h.close();
        }

        if (h.readSubTag("EmbeddingRight")) {
          mr.getEmbeddingRight().readMorphism(h);
          h.close();
        }
        h.close();

        mr.getLeft().setKind(GraphKind.LHS);
        mr.getRight().setKind(GraphKind.RHS);

        mr.setRuleScheme(this);
        mr.applyEmbeddedRuleMapping(this.kernelRule);
        mapKernel2MultiObject(mr);

        this.kernelRule.getLeft().addObserver(mr);
        this.kernelRule.getRight().addObserver(mr);
      }

      this.kernelRule.setChanged(false);

      //			if (h.readSubTag("Amalgamated")) {
      //				this.amalgamRule = new AmalgamatedRule(this.getTypeSet());
      //				h.getObject("", amalgamRule, true);
      //				h.close();
      //				this.amalgamRule.setRuleScheme(this);
      //
      //				if (h.readSubTag("MatchOf")) {
      //					Object obj = h.getObject("Rule", null, false);
      //					if (obj instanceof Rule) {
      //						Rule r = (Rule) obj;
      //						Match m = createMatch(r);
      //						h.getObject("Match", m, true);
      //						if (m.getSize() > 0)
      //							m.setPartialMorphismCompletion(true);
      //					}
      //					h.close();
      //				}
      //			}

      // read layer
      if (h.readSubTag("TaggedValue")) {
        int v = 0;
        String t = h.readAttr("Tag");
        // read new attribute
        int v2 = h.readIAttr("TagValue");
        if (v2 > 0) v = v2;
        if (t.equals("layer")) this.layer = v;
        h.close();
      }

      // read priority
      if (h.readSubTag("TaggedValue")) {
        int v = 0;
        String t = h.readAttr("Tag");
        // read new attribute
        int v2 = h.readIAttr("TagValue");
        if (v2 > 0) v = v2;
        if (t.equals("priority")) this.priority = v;
        h.close();
      }
      h.close();
    }
  }