A-B query and K-Hop query filter the edges and intermediate nodes in paths with a single rule, that is to say, the edges and intermediate nodes must meet the same filtering rules. If different rules are required to filter edges and intermediate nodes, template query is needed.
The template is to describe the filtering rules that any of the smallest unit (node, edge) in the path has to meet. By assembling multiple templates as path or subgraph, user can make structural matching in the graph to accommodate the business needs with celerity and great customizability.
Ultipa currently supports the following 4 basic templates:
Basic Template |
Type | Description | Structure Type of Custom Alias |
---|---|---|---|
n() |
Single node | The filtering rules of one node in the path | NODE |
e() , e()[1] ,le() , le()[1] , re() , re()[1] |
Single edge | The filtering rules of one edge in the path; edge direction is none, left or right (the same below) | EDGE |
e()[<steps>] ,le()[<steps>] ,re()[<steps>] |
Multiple edges | The filtering rules of multiple consecutive edges in the path; format of [<steps>] (N ≥ 2): [N] : N edges [:N] : 1~N edges [0:N] : 1~N edges (disgard the multiple edges template and the single node template to its right if no return) 4.1 [M:N] : M~N edges [*:N] : the shortest paths within N edges |
Custom alias not supported |
e().nf()[<steps>] ,le().nf()[<steps>] ,re().nf()[<steps>] |
Multiple edges | The filtering rules of multiple consecutive edges and nodes between those edges in the path; format of [<steps>] is the same as above |
Custom alias not supported |
Assembling Rules
- Rule No. 1: a path starts and ends with node, and consists of alternating nodes and edges.
For instance, a path of 4-node-3-edge should be n().e().n().e().n().e().n(). One can easily set independent filters and custom alias for each node or edge in the path.
n({@product}).le({@view}).n({@customer} as n1)
.re({@has}).n({@card} as n2)
.re({@transfer} as e1).n({@card}) as p
return p{*}, n1{*}, n2{*}, e1{*}
The template above describes a path where a product is viewed by Customer n1, and n1 owns card n2, then n2 makes a transfer named e1 to other cards.
- Rule No. 2: multiple edges and nodes can be merged in a multiple-edge template.
For instance, a path of 4-node-3-edge can be put into this way: n().e().nf()[3].n(), resembling A-B path query template. Custom alias is not applicable in multiple-edge template.
n({@card.level == 1} as n1).re({@transfer}).nf({@card})[2].n({@card.level == 2} as n2) as p
return p{*}, n1{*}, n2{*}
The template above describes the 3-step transfer paths starting from a Card whose level is 1 to Card n1, and ending with Card n2 whose level is 2.
- Rule No. 3: paths in 1~N steps can be merged in one path template to expand the query scope.
For instance, describe all paths within 10 steps by n().e().n().e()[:10].n():
n({@customer} as n1).re({@has}).n({@card} as c1)
.re({@transfer})[:10].n(c1) as p
return p{*}, n1{*}, c1{*}
The template above describes all possible paths where Customer n1 owns Card c1, c1 makes outbound transfers and finally transfers back to c1 within 10 steps.