User Tools

Site Tools


01_user_documentation:07_rgg_xl:02_xl:03_query:01_predicate:02_path:05_function

Table of Contents

Node function

Method that return either a Node or a Node generator can be used as path pattern. The method needs to have at least one argument, and its first argument must be of type Node (or extend Node). Then, the path pattern use the Node pattern on the left and test if it can be matched with the Node pattern on the right.

Additionally the node function will:

  • use the Node on its left implicitly as argument
  • possibly use the last argument (if of type Type) implicitly if it exists. This argument bound the type of the Node on the right. (at least that what was the plan - currently not working - don't know why)
  • use all other arguments, but they need to be given explicitly

Example

// get the Nodes who have the same parent as the one on the left from the path pattern
Node* siblings(Node n) {
    Node p = n.getAxisParent();
    if (p != null){ 
    for (Edge e = p.getFirstEdge(); e != null; e = e.getNext(p)){
	if (e.isSource(p) && ! e.isTarget(n)){
	    yield e.getTarget();
	}
    }
    }
}
 
// get the nb-th sibling
Node sibling(Node n, int nb) {
    Node p = n.getAxisParent();
    if (p == null){ return null;}
    int i = 0;
    for (Edge e = p.getFirstEdge(); e != null; e = e.getNext(p)){
	if (e.isSource(p) && ! e.isTarget(n)){
	    if (i == nb) {
                return e.getTarget();
            }
            i++;
	}
    }
    return null;
}
 
public void run ()
[
	Node -sibling(5)-> Node -siblings-> Node ::>;
]
01_user_documentation/07_rgg_xl/02_xl/03_query/01_predicate/02_path/05_function.txt · Last modified: 2025/08/26 12:23 by gaetan