예제 #1
0
 // olga: use comatch after step ia done to get values of OUTPUT parameters of a rule
 String getValueOfOutputParameter(VarMember p, Rule r, OrdinaryMorphism comatch) {
   if (p != null && r != null && comatch != null) {
     Enumeration<GraphObject> rightObjs = comatch.getDomain();
     while (rightObjs.hasMoreElements()) {
       GraphObject obj = rightObjs.nextElement();
       if (obj.getAttribute() != null) {
         ValueTuple vt = (ValueTuple) obj.getAttribute();
         for (int i = 0; i < vt.getNumberOfEntries(); i++) {
           ValueMember vm = vt.getEntryAt(i);
           if (vm.isSet() && vm.getExpr().isVariable() && vm.getExprAsText().equals(p.getName())) {
             // we found an object obj inside of the RHS which uses the output parameter p,
             // now we will find an appropriate graph object
             // and to get the value of the output parameter
             GraphObject go = comatch.getImage(obj);
             ValueTuple vt_go = (ValueTuple) go.getAttribute();
             ValueMember vm_go = vt_go.getEntryAt(vm.getName());
             String parVal = vm_go.getExprAsText();
             System.out.println(
                 parVal
                     + "  is value of OUTPUT parameter: --"
                     + p.getName()
                     + "--  of rule: "
                     + r.getName());
             return parVal;
           }
         }
       }
     }
   }
   return null;
 }
예제 #2
0
  /**
   * If the kernel rule is using an input parameter and its value is already set do propagate this
   * value to the attribute context of multi rules.
   */
  public void applyValueOfInputParameter() {
    final VarTuple vars = (VarTuple) this.getAttrContext().getVariables();

    for (int i = 0; i < vars.getNumberOfEntries(); i++) {
      final VarMember v = vars.getVarMemberAt(i);
      if (v.isInputParameter() && v.isSet()) {
        VarMember vm =
            ((VarTuple) this.kernelRule.getAttrContext().getVariables())
                .getVarMemberAt(v.getName());
        if (vm != null && (vm.getExpr() == null || !v.getExprAsText().equals(vm.getExprAsText()))) {
          //					vm.setExprAsText(v.getExprAsText());
          vm.setExpr(v.getExpr());
        }

        for (int j = 0; j < this.multiRules.size(); j++) {
          vm =
              ((VarTuple) this.multiRules.get(j).getAttrContext().getVariables())
                  .getVarMemberAt(v.getName());
          if (vm != null
              && (vm.getExpr() == null || !v.getExprAsText().equals(vm.getExprAsText()))) {
            //						vm.setExprAsText(v.getExprAsText());
            vm.setExpr(v.getExpr());
          }
        }
      }
    }

    //		System.out.println("applyValueOfInputParameter...  "+this.kernelRule.getName());
    //		((VarTuple) this.kernelRule.getAttrContext().getVariables()).showVariables();
    //		for (int j=0; j<this.multiRules.size(); j++) {
    //			System.out.println("applyValueOfInputParameter...  "+this.multiRules.get(j).getName());
    //			((VarTuple) this.multiRules.get(j).getAttrContext().getVariables()).showVariables();
    //		}
  }
예제 #3
0
 void setInputParameter(Rule r) {
   VarTuple vars = (VarTuple) r.getAttrContext().getVariables();
   for (int i = 0; i < vars.getNumberOfEntries(); i++) {
     VarMember var = (VarMember) vars.getMemberAt(i);
     if (var.isInputParameter())
       System.out.println(var.getName() + "  is already input parameter of rule: " + r.getName());
     else {
       // this var should be an input parameter
       var.setInputParameter(true);
       System.out.println(var.getName() + "  is now input parameter of rule: " + r.getName());
     }
   }
 }
예제 #4
0
  void setPars(Rule r) throws IOException {
    System.out.println("\n TAKING INPUTS to APPLY Rule: " + r.getName() + "\n");
    List<String> list = r.getInputParameterNames();
    System.out.println("The parameters for " + r.getName() + " are: " + list);
    //		System.out.println("The parameters values for " + r.getName() + " are: " +
    // r.getInputParameters());
    System.out.println("The parameters values:");
    for (int i = 0; i < list.size(); i++) {
      String pname = list.get(i);
      VarMember var = (VarMember) ((VarTuple) r.getAttrContext().getVariables()).getMemberAt(pname);
      if (var.isSet()) System.out.println(pname + " is set to value: " + var.getExprAsText());
      else System.out.println(pname + " is not set");
    }

    VarTuple vars = (VarTuple) r.getAttrContext().getVariables();

    for (int i = 0; i < vars.getNumberOfEntries(); i++) {
      VarMember var = (VarMember) vars.getMemberAt(i);
      if (var.isInputParameter()) {
        // olga:
        if (!var.isSet()) {
          System.out.println(
              var.getName() + "  is already input parameter of rule: " + r.getName());

          System.out.println(
              "\n \n Please Enter the value for input parameter for rule -- "
                  + r.getName()
                  + " --, parameter name -- "
                  + var.getName()
                  + " --: ");
          Scanner scan = new Scanner(System.in);
          String value = scan.nextLine();
          System.out.println("The given input was: " + value);
          var.setInputParameter(true);
          var.setExprAsText(value);
          // in1.close();
          System.out.println(var.getName() + "  is now input parameter of rule: " + r.getName());
        } else {
          System.out.println(
              var.getExprAsText()
                  + " is value of the INPUT parameter: "
                  + var.getName()
                  + "  of rule: "
                  + r.getName());
        }
      }
    }
    // in.close();
  }
예제 #5
0
 // olga: propagate value of OUTPUT parameters of rule r1 to INPUT parameters of rule r2
 void propagateOutParamToInParamOfRule(Hashtable<String, String> outPars, Rule r) {
   if (outPars != null && !outPars.isEmpty()) {
     VarTuple vars = (VarTuple) r.getAttrContext().getVariables();
     for (int i = 0; i < vars.getNumberOfEntries(); i++) {
       VarMember var = vars.getVarMemberAt(i);
       String outVal = outPars.get(var.getName());
       if (outVal != null && var.isInputParameter()) {
         var.setExprAsText(outVal);
       }
     }
   }
 }
예제 #6
0
  public boolean doStep(Rule r) {
    Match match = gratra.createMatch(r);
    System.out.println("The match was: " + match.getRule().getName().toString());

    // olga
    while (match.nextCompletion()) {
      if (match.isValid()) {
        try {
          Morphism co = StaticStep.execute(match);
          System.out.println("Rule  " + match.getRule().getName() + " : step is done");
          didTransformation = true;
          Graph graph = co.getOriginal();
          Graph graph2 = co.getImage();
          System.out.println();
          //					System.out.println("The image parameters are: " + graph.toString());
          //					System.out.println("The OUTPUT parameters are: " + graph2.toString());

          // olga
          outPar = getOutputParameters(r, outPar);
          for (int i = 0; i < outPar.size(); i++) {
            VarMember p = outPar.get(i);
            String parVal = getValueOfOutputParameter(p, r, (OrdinaryMorphism) co);
            this.outParVal.put(p.getName(), parVal);
          }

          ((OrdinaryMorphism) co).dispose();
          return true;
        } catch (TypeException ex) {
          ex.printStackTrace();
          gragra.destroyMatch(match);
          System.out.println(
              "Rule  "
                  + match.getRule().getName()
                  + " : step of match failed : "
                  + ex.getMessage());
        }
      } else
        System.out.println(
            "Rule  "
                + match.getRule().getName()
                + " : a match completion is not valid; try to find the next ones");
    }
    System.out.println("Rule  " + match.getRule().getName() + " : match could not be found");
    return false;
    // gragra.destroyMatch(match);
    // match.clear();
  }
예제 #7
0
  // olga
  List<VarMember> getOutputParameters(Rule r, List<VarMember> list) {
    if (list == null) list = new Vector<VarMember>();
    else list.clear();

    VarTuple vars = (VarTuple) r.getAttrContext().getVariables();
    for (int i = 0; i < vars.getNumberOfEntries(); i++) {
      VarMember var = (VarMember) vars.getMemberAt(i);
      if (var.isOutputParameter()) {
        System.out.println(var.getName() + "  is OUTPUT parameter of rule: " + r.getName());
        list.add(var);
      }
      //			else {
      // if this var should be an output parameter
      //				var.setOutputParameter(true);
      //				System.out.println(var.getName()+"  is now OUTPUT parameter of rule: "+r.getName());
      //			}
    }
    return list;
  }
예제 #8
0
  private boolean nacIsUsingVariable(
      final VarMember var, final AttrConditionTuple act, final List<OrdinaryMorphism> nacs) {

    for (int l = 0; l < nacs.size(); l++) {
      final OrdinaryMorphism nac = nacs.get(l);
      if (nac.getTarget().isUsingVariable(var)) {
        return true;
      }
      Vector<String> nacVars = nac.getTarget().getVariableNamesOfAttributes();
      for (int j = 0; j < nacVars.size(); j++) {
        String varName = nacVars.get(j);
        for (int k = 0; k < act.getNumberOfEntries(); k++) {
          CondMember cond = (CondMember) act.getMemberAt(k);
          Vector<String> condVars = cond.getAllVariables();
          if (condVars.contains(varName) && condVars.contains(var.getName())) {
            return true;
          }
        }
      }
    }
    return false;
  }