User Tools

Site Tools


tutorials:xl-queries-and-operators

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorials:xl-queries-and-operators [2024/12/07 16:27] – [Query examples] ksmolentutorials:xl-queries-and-operators [2025/06/02 07:36] (current) – added transitive closure examples ksmolen
Line 60: Line 60:
 } }
 </code> </code>
 +
 +{{ :tutorials:graph_query_example_2rot.png?200|}}
 +
 +The underlying 2d graph of the generated structure given below:
 +
 +Beginning from //RGGRoot//, we have the sequence of three //Internodes// where to each a //Leaf// is linked by a branching edge. The last internode, additionally, has a Bud node successor.
 +
  
 ==== Query examples ==== ==== Query examples ====
Line 138: Line 145:
 Aggregate operations are used to collect multiple values when traversing the graph structure and return a single value. Aggregate operations are used to collect multiple values when traversing the graph structure and return a single value.
  
-Standard [[groimp-platform:xl-operators|aggregate operations]] are: ''count'', ''sum'', ''empty'', ''exist'', ''forall'', ''first'', ''last'', ''max'', ''min'', ''mean'', ''selectRandomly'', ''selectWhereMin'', ''selectWhereMax'', ...+Standard [[:groimp-platform:xl-builtin-methods|aggregate operations]] are: ''count'', ''sum'', ''empty'', ''exist'', ''forall'', ''first'', ''last'', ''max'', ''min'', ''mean'', ''selectRandomly'', ''selectWhereMin'', ''selectWhereMax'', ...
  
   * Count all leaves:    * Count all leaves: 
Line 145: Line 152:
 count((* Leaf *)) count((* Leaf *))
 </code> </code>
 +
 +<hidden answer>
 +3
 +</hidden>
 +
  
   * Sum up the area of all leaves:   * Sum up the area of all leaves:
Line 151: Line 163:
 sum((* Leaf *)[area]) sum((* Leaf *)[area])
 </code> </code>
 +
 +<hidden answer>
 +6.0
 +</hidden>
 +
  
   * Sum up the length of internodes:   * Sum up the length of internodes:
Line 157: Line 174:
 sum((* Internode *)[length]) sum((* Internode *)[length])
 </code> </code>
 +
 +<hidden answer>
 +6.0
 +</hidden>
  
 In this particular example with internodes forming (only) the main stem, the query will return stem length. In this particular example with internodes forming (only) the main stem, the query will return stem length.
Line 165: Line 186:
 selectWhereMax((* l:Leaf *), (l[area])) selectWhereMax((* l:Leaf *), (l[area]))
 </code> </code>
 +
 +<hidden answer>
 +Model.Leaf[id=1903]@668c1f97
 +</hidden>
 +
  
   * Count internodes that are older than 2 (time units):   * Count internodes that are older than 2 (time units):
Line 172: Line 198:
 </code> </code>
  
 +<hidden answer>
 +2
 +</hidden>
 +
 +==== Transitive closure ====
 +
 +Transitive closure is a concept used to derive relations between successive nodes connected by several edges of the same type. For example, we want to find all descendants of some given node that are of type Internode.
 +
 +The quantifier ''+'' stands for 1-to-//n// repetitions, the quantifier ''*'' stands for 0-to-//n// repetitions.
 +
 +  * Find all internodes connected to the bud:
 + 
 +<code java> 
 +(* Bud (<--)+ Internode *)
 +</code>
 +
 +Special syntax is used after the quantifier if we are interested only in finding minimal elements '':(node_type)'' 
 +
 +  * Find the first internode connected to the bud:
 + 
 +<code java> 
 +(* Bud (<--)+ :(Internode) *)
 +</code>
tutorials/xl-queries-and-operators.1733585279.txt.gz · Last modified: 2024/12/07 16:27 by ksmolen