User Tools

Site Tools


tutorials:basic-to-advanced-xl-queries

From simple to advanced XL queries

Path queries

module A;
module B;
module C;
module D;
 
protected void init ()
[
	Axiom ==> A [A B [b1:B] c:C b2:B ] D C [B A A] B A,c />d:D,b1 /> b2, b2 /> d;
]

0. Get all nodes

answer

answer

In a Context:

(*Node*)

In a Query:

Node ==>

Why:

The query system in XL works based on the concept of object orientation from java, therefore a Query also selects all Objects, that extend the class used in the pattern. And since all Nodes in the graph extends the class Node…

1. Get all the A nodes

answer

answer

In a Context:

((*A*))

In a Query:

A ==>

2. Get all B's that are linked by a successor

answer

answer

In a Context:

((*Node > B*))

In a Query:

(*Node > *) B ==> ;

Selected Nodes:

Model.B[id=30]
Model.B[id=33]
Model.B[id=39]

Why:

The > arrow describes a successor connection and since Node addresses all Objects in the graph this query addresses all B's that are linked by an successor. For the Query, the use of the context syntax ((*...*) is necessary to clarify that this part of the pattern is not suppose to be replaced.

3. Get all B's that are linked by a branch

answer

answer

In a Context:

((*Node +> B*))

In a Query:

(*Node +> *) B ==> ;

Selected Nodes:

Model.B[id=31]
Model.B[id=36]

Why:

The same as above only with the +> edge, which represents a branch

4. Get all As followed directly by another A

answer

answer

In a Context:

((*A -->A*))

In a Query:

(*A --> *) A ==> ;

Selected Nodes:

Model.A[id=29]
Model.A[id=38]

Why:

First of all in this case we know what type of parent we are looking for so the first Node is an A but we do not care about the edge and therefore we can use the --> term in the pattern which means all edges are possible.

5. Get As followed directly by another A, both are connected by a branch

answer

answer

In a Context:

((*A +>A*))

In a Query:

(*A +> *) A ==> ;

Selected Nodes:

Model.A[id=29]

Why:

Same as above but only for branch edge.

6. Get all A's that are below a C

answer

answer

In a Context:

(*C (-->)* A*))

In a Query:

(*C (-->)* *) A ==> ;

Selected Nodes:

Model.A[id=37]
Model.A[id=38]
Model.A[id=40]

Why:

Now we start at a C because we know at some point above our A there is suppose to be a C, moreover we know that the type of edge does not matter so we can use -->. Finally we do not only look for the direct connection but for a range of connecitons this can be done by ()*.

7. Get all B's that are below another B

answer

answer

In a Context:

(*B (-->)+ B*))

In a Query:

(*B (-->)+ *) B ==> ;

Selected Nodes:

Model.B[id=31]
Model.B[id=33]
Model.B[id=33]
Model.B[id=33]

8. Get all D which are below a C, where the C is below a B

answer

answer

In a Context:

(*B --> C --> D*))

In a Query:

(*B --> C -->*) D ==> ;

Selected Nodes:

Model.D[id=41]

9. Get All Nodes, which are connected upwards as following: Branch, Successor Branch

answer

answer

In a Context:

((*Node +> > +> Node*))

In a Query:

(*Node +> > +>*) D ==> ;

Selected Nodes:

Model.A[id=29]
Model.B[id=31]

10. Get The B that is a decomposition child of another B, the successor of an C and has a D as a decomposition child.

answer

answer

In a Context:

((*B /> b:B, C > b,D</b*))

In a Query:

(*B />*)b:B (*< C*),(*D </b*) ==>;

Selected Nodes:

Model.B[id=33]

11. Get all A's that have no Children

answer

answer

In a Context:

((*a:A,(empty((*a --> Node*)))*))

In a Query:

a:A,(empty((*a --> Node*))) ==>;

Selected Nodes:

Model.A[id=38]
Model.A[id=40]
tutorials/basic-to-advanced-xl-queries.txt · Last modified: 2024/12/04 19:48 by tim2