Manipulate Your Graphs with Rules

Basics

All analyses in Soley are based on rules, sequences and procedures/functions. Sequences apply different rules, rules manipulate the input graph and procedures/functions can be part of a sequence or rule to calculate variables with inputs and returning outputs if necessary. A rule is therefore the main code segment you need for setting up your analyses.

How it works

A rule consists of two parts called the left hand side (LHS), where the data from the graph is picked when fullfilling a certain pattern and the right hand side (RHS), where the data is manipulated when fullfilling a certain (or no) condition. The concept is depicted in the image below.

Graph Transformation

  • LHS: In this part of the rule you define the data you want to manipulate, e.g. you can define a variable part of type Part to pick a node of type “Part” from your graph or define an edge e of type “Contains” to pick a edge of type “Contains” as shown in the code beneath.
1 rule deleteAnalyticsEdge {    //Here starts the LHS
2                 
3     part:Part;                //find a node of type Part and assign name part
4     -e:AnalyticContains->;    //find a AnalyticContains edge and assign name e
5     
6     modify{                   //Here starts the RHS
7         delete(e);            //and then delete the edge
8     }
9 }

Often you will implement a condition to execute your RHS-part or it will contain a loop. You can realize this with a “If pattern” or a “For pattern“.

  • RHS: In this part of the rule you define the manipulation of the graph. This part always starts with the modify part, which contains the different manipulations. Within this segment you can build edges between nodes, delete nodes or edges, execute other code segments or calculate (evaluate) properties of nodes or edges. Additionaly you can use alternatives or negative statements to structure your rule. The code beneath shows examples for possible statements.
1 rule examplerule {                        //Here starts the LHS
2                 
3     node1:Node1;
4      node2:Node2;                         //find a node of type Node1 and assign name node1
5     -e1:Edge1->;                          //find a Edge1 edge and assign name e
6
7   if(node2.quantity == 0;)                //If condition to execute RHS 
8                    
9     modify{                               //Here starts the RHS
10         node2-:Edge2->node1;             //Build edge of type Edge2 from node2 to node1
11 
12        eval{                            //Start an evaluation part within the modify part of a rule
13         node2.quantity=node1.quantity*2 //Calculate the quantity property of node2
14          }
15
16       delete(e1);                       //delete the edge
17
18       exec(rule2);                      //executes rule2
19     }
20 }

Further information

Please refer to the Soley tutorial and the other articles in this Knowledge Base category for more detailed descriptions regarding this topic. If you have to run several calculations procedures/functions might be the right kind of tool. To execute several rules in a row or to adapt them for the total graph, you should use sequences.

Was this article helpful?

Related Articles