コード例 #1
0
ファイル: Rule.java プロジェクト: dani8art/rSYBL
 public boolean equals(Object o) {
   if (!(o instanceof Rule)) {
     return false;
   }
   Rule r = (Rule) o;
   if (r.getName().toLowerCase().equalsIgnoreCase(name.toLowerCase())) return true;
   else return false;
 }
コード例 #2
0
 private String getRuleNames(Vector<Rule> rules) {
   String names = "[ ";
   for (int j = 0; j < rules.size(); j++) {
     Rule r = rules.elementAt(j);
     names = names + r.getName() + " ";
   }
   names = names + "]";
   return names;
 }
コード例 #3
0
ファイル: RuleEngine.java プロジェクト: okleine/luposdate
 /**
  * applyRulesDebugByteArray.
  *
  * @param op a {@link lupos.engine.operators.BasicOperator} object.
  * @param mapStartNodes a {@link java.util.Map} object.
  * @param rules an array of {@link lupos.optimizations.logical.rules.Rule} objects.
  * @param untilRule a {@link lupos.optimizations.logical.rules.Rule} object.
  * @param prefixInstance a {@link lupos.rdf.Prefix} object.
  * @return a {@link java.util.List} object.
  */
 public List<DebugContainer<BasicOperatorByteArray>> applyRulesDebugByteArray(
     final BasicOperator op,
     final Map<Class<? extends BasicOperator>, Set<BasicOperator>> mapStartNodes,
     final Rule[] rules,
     final Rule untilRule,
     final Prefix prefixInstance) {
   final List<DebugContainer<BasicOperatorByteArray>> debug =
       new LinkedList<DebugContainer<BasicOperatorByteArray>>();
   for (final Rule r : rules) {
     if (untilRule != null && r.equals(untilRule)) break;
     while (r.applyDebug(op, mapStartNodes)) {
       debug.add(
           new DebugContainer<BasicOperatorByteArray>(
               r.getName(),
               r.getDescription(),
               BasicOperatorByteArray.getBasicOperatorByteArray(op.deepClone(), prefixInstance)));
       // mapStartNodes = RuleEngine.createStartNodeMap(op);
       if (checkNodeMap) {
         // check if all nodes of the operatorgraph are in the
         // map:
         op.visit(
             new SimpleOperatorGraphVisitor() {
               public Object visit(final BasicOperator basicOperator) {
                 if (!checkIfInNodeMap(basicOperator, mapStartNodes))
                   System.err.println(
                       "The following node is not in mapStartNodes:" + basicOperator);
                 return null;
               }
             });
         // check if all nodes of the map are in the
         // operatorgraph:
         for (final Map.Entry<Class<? extends BasicOperator>, Set<BasicOperator>> entry :
             mapStartNodes.entrySet()) {
           for (final BasicOperator bo : entry.getValue()) {
             final FindInOperatorGraph findInOperatorGraph = new FindInOperatorGraph(bo);
             op.visit(findInOperatorGraph);
             if (!findInOperatorGraph.getFlag())
               System.err.println(
                   "The following node for class "
                       + entry.getKey()
                       + " is not in the operatorgraph:"
                       + bo);
           }
         }
       }
       Rule[] rulesToApply = r.getRulesToApply(this);
       if (rulesToApply == null) rulesToApply = this.rules;
       debug.addAll(applyRulesDebugByteArray(op, mapStartNodes, rulesToApply, r, prefixInstance));
     }
   }
   return debug;
 }
コード例 #4
0
 private boolean applyRule(Rule r) {
   boolean applied = false;
   while (apply(r)) {
     applied = true;
     break;
   }
   String s0 = r.getName() + " \t applied:  " + applied;
   System.out.println(s0);
   writeTransformProtocol(s0);
   String s1 = "";
   if (!applied) {
     s1 = s1 + getErrorMsg();
     writeTransformProtocol(s1);
   }
   return applied;
 }
コード例 #5
0
ファイル: Rule.java プロジェクト: dshen36/GATECH
  /** @return a string representation of the rule. */
  public String toString() {
    SB = new StringBuffer();
    if (this.start) {
      SB.append("[START] ");
    }
    SB.append(name + ":");

    if (terminal) {
      SB.append(" terminal\n");
    } else {
      SB.append("\n");
      for (Rule[] rs : this.rules) {
        for (Rule r : rs) {
          SB.append(r.getName());
        }
        SB.append("\n");
      }
    }
    return SB.toString();
  }
コード例 #6
0
  public boolean apply(Rule r) {
    //		System.out.println("ApplRuleSequencesGraTraImpl.apply(Rule) : "+r.getName()+"
    // "+updateTypeObjectsMapAfterStep);

    //		long time0 = System.currentTimeMillis();

    this.stoppingRule = false;
    boolean result = false;
    boolean valid = false;

    this.currentMatch = r.getMatch();
    if (this.currentMatch == null) {
      this.currentMatch = this.grammar.createMatch(r);
      this.currentMatch.setCompletionStrategy(
          (MorphCompletionStrategy) this.strategy.clone(), true);
      //		strategy.showProperties();
    } else if (this.updateTypeObjectsMapAfterStep) {
      this.currentMatch.setTypeObjectsMapChanged(true);
    }

    boolean parallelApply = true;
    boolean is_applied = false;
    //		int matchCompletions = 0;

    //		time0 = System.currentTimeMillis();

    while (parallelApply) {

      if (!isInputParameterSet(r.getLeft(), true, this.currentMatch)) {
        fireGraTra(new GraTraEvent(this, GraTraEvent.INPUT_PARAMETER_NOT_SET, this.currentMatch));
      }

      if (this.stopping || this.stoppingRule) {
        this.currentMatch.clear();
        return false;
      }

      if (this.pauseRule) return false;

      valid = false;
      while (!valid) {
        if (this.currentMatch.isTotal() || this.currentMatch.nextCompletion()) {
          if (this.currentMatch.isValid()) {
            valid = true;
            //						matchCompletions++;

            if (r.isParallelApplyEnabled() && this.currentMatch.typeObjectsMapChanged) {
              this.currentMatch.typeObjectsMapChanged = false;
              // das hat Auswirkung auf den naechsten Aufruf
              // von nextCompletion():
              // die Graphaenderungen nach dem Step werden
              // NICHT BEACHTET!!!
            }
          } else {
            this.errorMsg = this.currentMatch.getErrorMsg();
            this.currentMatch.clear();
          }
        } else {
          this.errorMsg = this.currentMatch.getErrorMsg();
          break;
        }
      }

      if (valid) {

        fireGraTra(new GraTraEvent(this, GraTraEvent.MATCH_VALID, this.currentMatch));

        if (!isInputParameterSet(r.getRight(), false, this.currentMatch)) {
          fireGraTra(new GraTraEvent(this, GraTraEvent.INPUT_PARAMETER_NOT_SET, this.currentMatch));
        }

        if (this.stopping || this.stoppingRule) {
          if (this.currentMatch != null) {
            this.currentMatch.clear();
          }
          return false;
        }

        if (this.pauseRule) return false;

        try { // check attr context: variables only
          boolean checkVarsOnly = true;
          this.currentMatch
              .getAttrContext()
              .getVariables()
              .getAttrManager()
              .checkIfReadyToTransform(this.currentMatch.getAttrContext(), checkVarsOnly);
        } catch (AttrException ex) {
          fireGraTra(new GraTraEvent(this, GraTraEvent.NOT_READY_TO_TRANSFORM, r.getName()));
          // destroyMatch(currentMatch);
          return false;
        }

        Morphism coMatch = apply(this.currentMatch);
        if (coMatch != null) {
          this.errorMsg = "";
          is_applied = true;

          this.currentMatch.clear();
          // destroyMatch(currentMatch);
          coMatch.dispose();
          coMatch = null;
          result = true;
        } else {
          valid = false;
          fireGraTra(
              new GraTraEvent(this, GraTraEvent.NO_COMPLETION, this.currentMatch, this.errorMsg));
          this.currentMatch.clear();
          // destroyMatch(currentMatch);

          result = false;
        }
      } else {
        fireGraTra(
            new GraTraEvent(
                this,
                GraTraEvent.NO_COMPLETION,
                this.currentMatch,
                this.currentMatch.getErrorMsg()));
        this.currentMatch.clear();
        // destroyMatch(currentMatch);

        result = false;
      }

      //
      if (r.isParallelApplyEnabled()) {
        if (!valid) {
          parallelApply = false;
          this.currentMatch.typeObjectsMapChanged = true;
        }
        if (is_applied) {
          result = true;
        }
      } else {
        parallelApply = false;
        break;
      }
      //
    }

    return result;
  }
コード例 #7
0
  protected void apply(Rule r, String iters) {
    boolean ruleapplied = true;
    if (iters.equals("*")) {
      //			System.out.println("\nrule: " + r.getName()+ "\t*  times");

      while (ruleapplied && !this.stopping) {
        ruleapplied = apply(r);

        if (ruleapplied) {
          this.appliedOnce = true;
        }

        //				System.out
        //						.println(r.getName() + " \t applied:  " + ruleapplied);

        if (this.os != null) writeTransformProtocol(r.getName() + " \t applied:  " + ruleapplied);

        if (!isGraphConsistent()) this.stopping = true;
      }
    } else {
      long N = (new Long(iters)).longValue();

      //			String str = "";
      //			if (N > 1)
      //				str = "\t{"+ N+"} times";
      //			System.out.println("apply rule: " + r.getName());

      if (this.options.hasOption(GraTraOptions.WAIT_AFTER_STEP)) {
        fireGraTra(new GraTraEvent(this, GraTraEvent.RULE, r));
      }

      if (this.ruleSequence != null) {
        this.indx++;
        int preIndx = this.indx - 1;
        Hashtable<GraphObject, GraphObject> matchMap =
            this.ruleSequence
                .getMatchSequence()
                .getMatch(this.indx, r, preIndx, this.preRule, this.grammar.getGraph());

        if (r.getMatch() == null) {
          this.currentMatch = this.grammar.createMatch(r);
          this.currentMatch.setCompletionStrategy(
              (MorphCompletionStrategy) this.strategy.clone(), true);
        }
        if (matchMap != null) {
          try {
            this.currentMatch.addMapping(matchMap);
          } catch (BadMappingException ex) {
            System.out.println("match mapping  FAILED!  " + ex.getMessage());
            this.currentMatch.clear();
          }
        }
      }

      for (long i = 0; i < N && !this.stopping; i++) {

        ruleapplied = apply(r);

        if (r.getMatch() != null)
          ((VarTuple) r.getMatch().getAttrContext().getVariables()).unsetInputParameters();

        if (ruleapplied) {
          this.preRule = r;
          this.appliedOnce = true;
        }

        System.out.println(r.getName() + " \t applied:  " + ruleapplied);

        if (this.os != null) writeTransformProtocol(r.getName() + " \t applied:  " + ruleapplied);

        if (!isGraphConsistent()) this.stopping = true;
      }
    }
  }