Sequence Flow – Basic Operations

This article lists the basic operations of graph rewrite sequences at a glance. The operations allow you to control the flow and order in which activities in your sequence are executed. Highlighted operations are most used operations and will help you to cover most problems.

OperatorDescription
s*Execute s repeatedly as long as its execution does not fail. See Details for more information.
[s]Find all matches for rule s in the input data graph and then execute them in one go. See Details for more information.
s ;> t Execute s then t. Success if t succeeded.
s <; t Execute s then t. Success if s succeeded.
s | t Execute s then t. Success if s or t succeeded.
s || t The same as s | t but with lazy evaluation, i.e. if s is successful, t will not be executed.
s & t Execute s then t. Success if s and t succeeded.
s && t The same as s & t but with lazy evaluation, i.e. if s fails, t will not be executed.
s ^ t Execute s then t. Success if s or t succeeded, but not both.
If{r;s;t} Execute r. If r succeeded, then execute s and return the result of s. Else execute t and return the result of t. This represents a if-then-else statement. r is the condition, s the then part, t the else part. The else part is optional (see next row).
If{r;s} Same as If{r;s;true}, if-then pattern without an else part.
!s Switch the result of s from successful to fail and vice versa.
$<op> Use random instead of left-associative execution order for <op>.
s+ Same as s && s*.
s[n] Execute s repeatedly as long as its execution does not fail but n-times at most.
s[m:n] Same as s[n] but fails if executed less than m times.
s[m:*] Same as s* but fails if executed less than m times.
?Rule Switches Rule to a test.
%Rule This is the multi-purpose flag when accessed from libGr. Also used for graph dumping and break points.
(v:array)=[r] Searches for all matches and rewrites them all, for r returning T.
count[a ]=>v Rewrite every pattern match produced by the action a, and write the count of the
matches found to the variable v.
true A constant acting as a successful match.
false A constant acting as a failed match.
v A boolean variable acting as a predicate.
Let r, s, t be rules or sequences, u, v, w variable identifi ers, <op> 2 f|; ^; &; ||; &&g

 

How to use in a Sequence

Here you can find a short example of how operations can be used:

 sequence sequenceFlowExample(ID:string){
     counter:int = 1 ;>
     for{ part:Part in nodes(Part);
         if{ {{part.id == ID}};  //condition needs to be in two curly brackets, the first 
                                   semicolon starts the "then" part
             {emit("Part with ID " + ID + " has been found \n")} ;>
             writeCounterOnProperty(part, counter) | deleteAdjacentProducts(part)* ;>
             {counter = counter + 1};  //the second semicolon starts the optional "else" part
             break
         }
     }
 }
 
 rule deleteAdjacentProducts(p:Part){
     prod:Product;
     if{isAdjacent(p, prod);}
     modify{
         delete(prod);
     }
 }
 
 rule writeCounterOnProperty(p:Part, var number:int){
     modify{
         eval{p.quantity = number;}
     }
 }

 

As you could see in the example above, you have to use curly brackets around functions, evaluations or other code which has to be executed and double curly brackets around the condition of an if-statement.

If you want to learn more about how to use input parameters for rules you can click here.
If you want to read more about assigning variables in sequences you can have a look at this article.

 

Details on Sequence Operations s* and [s]

The sequence operators * and [ ] are used to control the application process of rules in sequences. It is important to understand the difference in application.

* operator:  

Execute s repeatedly as long as its execution does not fail. If s is a rule then s* causes following operation: Find LHS pattern match in input data graph –> apply RHS modification to pattern match –>  Find LHS pattern match –> … . This keeps on until the execution fails, i.e. until no more LHS pattern match can be found. Applying rules with the * operator requires the least amount of memory.

CAUTION! Using the * operator can cause endless (looped) rule application if the rule does not have a stopping criterion.

[ ] operator:

Find all matches for rule s in the input data graph and then execute them in one go. Applying rules with the [ ] operator requires more memory as all pattern matches are first found and stored before the pattern rewrite is carried out for all matches.

CAUTION! Using the [ ] operator with a delete operation on the RHS of the rule can cause “Reference not set to an instance of an object” errors if elements are deleted that are in the set of pattern matches.

Was this article helpful?

Related Articles