Filter and Order Functions

Soley Studio offers several functions to order and filter the matches found in a rule or array elements. This article offers a list of available filters and ordering possibilities and shows how to use them both with code examples.

Available Order functions

FunctionsDescription
orderAscendingBy orders the matches list ascendingly by value "v". "V" can be int, double or string.
orderDescendingByorders the matches list descendingly by value "v". "V" can be int, double or string.

Available Filter functions

FunctionDescription
keepSameAsFirstFilters all elements away, which don't have the same "v" value as the first element. "V" can be int, double or string.
removeLastFraction(fraction)Removes the fraction of the matches from the end of the matches list. "Fraction" has to be a double number.
removeLast(count)Removes the last "count" matches from the begin of the matches list. "Count" has to be a integer.
removeFirstFraction(fraction) Removes the fraction of the matches from the begin of the matches list. "Fraction" has to be a double number.
removeFirst(count)Removes the first "count" matches from the begin of the matches list. "Count" has to be a integer.
keepSameAsLastFilters all elements away, which don't have the same "v" value as the last element. "V" can be int, double or string.
keepOneForEach Filters away all matches with duplicate "v" values, i.e. only one (prototypical) match is kept per v value. The list must have been grouped or ordered before, otherwise the result is undefined. "V" can be int, double or string.
keepLastFraction(fraction) Keeps the "fraction" of the matches from the end of the matches list. "Fraction" has to be a double number.
keepLast(count)Keeps the last "count" elements. "Count" has to be a integer.
keepFirstFraction(fraction) Keeps the "fraction" of the matches from the begin of the matches list, "Fraction" has to be a double number.
keepFirst(count)Keeps the first "count" elements. "Count" has to be a integer.

Example

These functions can be used for the matches found in a rule as shown below. This rule deletes 50% of all found nodes with the smallest number of outgoing edges.

sequence deleteNodes{
  [deleteNode \ orderAscendingBy<i> \ keepFirstFraction(0.5)]
   }


rule deleteNode
   { 
     def var i:int;

     n:Node;
     
     yield { 
       yield i = outgoing(n).size();
           }

     modify{ 
       delete(n); 
           }  
  }  \ orderAscendingBy<i>

Alternatively these functions can be used for arrays or sets as shown below. This function orders the input array “xy” with “MyNode”-Node Elements ascending by their “id”-attribute and returns this array in another array “arr”.

function orderArray(ref xy:array<MyNode>):array<Mynode>{
     def ref arr:array<MyNode> = xy.orderAscendingBy<id>();
     return(arr);
 }

 

Was this article helpful?

Related Articles