Rule Template Library – Basic Rule Structures

There are several rule templates available as library elements in the rule template library of Soley Studio. Currently library elements for rule structures, decisions within rules and loops in rules are available.

Examples of how you can use the different structures can be found in the blue boxes.

Library elements for structures of rules

  • RuleThis is the standard structure of a rule.
rule RULE_NAME { // Left-hand side graph pattern 
 modify{ // Right-hand side graph pattern
 } 
}
  • Rule with a node parameter: Use this library element if you want to predefine a node parameter in the pattern part.
rule RULE_NAME (n:NODE_CLASS) { 
 // Left-hand side graph pattern 
 modify{ // Right-hand side graph pattern 
 } 
}
  • Rule with a directed edge parameter: Use this library element if you want to predefine an edge parameter in the pattern part.
rule RULE_NAME (-e:DIRECTED_EDGE_CLASS->) {
 // Left-hand side graph pattern 
 modify{ // Right-hand side graph pattern 
 } 
}
  • Rule with a primitive type parameter: Use this library element if you want to predefine a primitive type parameter. Primitive types are int, double, string etc.
rule RULE_NAME (var p : PRIMITIVE_TYPE) { 
 // Left-hand side graph pattern 
 modify{ // Right-hand side graph pattern 
 }
}
  • Rule with a reference type parameter: This library element allows you to predefine referencing type parameters. Reference types are set, map<S, T>, array etc.
rule RULE_NAME (ref p : REFERENCE_TYPE) { 
 // Left-hand side graph pattern 
 modify{ // Right-hand side graph pattern } 
}
  • Rule with a return statement: Use this library element if you want to return a variable from the rule. Together with parameters it allows you to pass on variables, graph elements etc. between rules and sequences.

TYPE: primitive type (int, string etc.), reference type (set, map<S,T> etc.) or graph element class (Node, Edge etc.)

rule RULE_NAME : (TYPE) { 
 // Left-hand side graph pattern 
 modify{ // Right-hand side graph pattern. Variable holds
 a value of the specified TYPE. 
 return(variable); } 
}

Library elements for Decisions

  • Alternative: Use this library element to look for alternative patterns on the left-hand side and transform a graph according to the matched pattern. Make sure the alternatives exclude each other in order to prevent unspecified matching.
alternative { 
 ALTERNATIVE1 { PATTERN_STATEMENT modify{ } } 
 ALTERNATIVE2 { PATTERN_STATEMENT modify{ } }
 // Add more alternatives here.
}
  • If statement: Use this library element to estrictt the applicability of a rule. Use if statements if you want to further specify the pattern searching on the left-hand side.
rule doIF { n1:NODE_CLASS; n2:NODE_CLASS; 
 if{ n1 -:EDGE_CLASS-> n2;} 
 modify{ eval{ delete(n2); } } 
}
  • Negative: Use this library element to to specify graph patterns which forbid the application of a rule if any of them is present in the host graph.
rule doIF {n1:NODE_CLASS; n2:NODE_CLASS; 
 if{ n1 -:EDGE_CLASS-> n2;} 
 negative{n2.name == "Important Node"} 
 modify{ eval{ delete(n2); } } 
}

Library elements for loops

  • Iterated: Use this library element if you want the contained subpattern to be matched as often as possible. It can not fail, even if the contained pattern is not available. It is used on the rule’s left-hand side.
rule letNodesSayHello {
 iterated{ n1:Node; 
 modify{ eval{ emit("Hello! \n"); } } 
 } 
}
  • Multiple: The multiple block works like the iterated block, but the contained subpattern has to be available at least once. If not, matching of the multiple block and thus its enclosing pattern fails.
rule letNodesSayHello { 
 multiple{ n1:Node; 
 modify{ eval{ emit("Hello! \n"); } } 
 } 
}
  • Optional: The optional block works like the iterated block, but matches the contained subpattern at most once; further occurrences of the subpattern are left unmatched.
rule RULE_NAME { optional { PATTERN_STATEMENT 
 modify { eval{ emit("Hello! \n"); } 
 } 
}

Further Information

If these functions do not fit your needs, you can have a look at the Global Function section of the Soley Help Center.

Was this article helpful?

Related Articles