圖形all()函式會沿著可變長度路徑評估每個邊緣或內部節點的條件。
語法
all(
邊緣,條件)
all(inner_nodes(
邊緣),條件)
參數
| 名稱 | 類型 | 為必填項目 | 說明 |
|---|---|---|---|
| 邊緣 | string |
✔️ | 圖形比對運算符或圖形最短路徑運算符模式中的可變長度邊緣。 如需詳細資訊,請參閱 圖形模式表示法。 |
| 條件 | string |
✔️ | 布爾表達式,由 邊緣 或 內部節點的屬性所組成 ,當inner_nodes 用於 可變長度邊緣時。 直接使用屬性名稱參考屬性。 表達式會針對可變長度邊緣中的每個邊緣或內部節點進行評估。 |
退貨
true如果條件在true可變長度邊緣中使用inner_nodes時,評估為 每個邊緣或內部節點,則傳回 。 否則會傳回 false。
針對零長度路徑,條件會評估為 true。
範例
下列範例示範如何使用 graph-match 運算元搭配 函 all() 式,在交通網路中尋找兩個月臺之間的所有往返路徑。 它會針對每個方向使用不同的線條。 此查詢會從 connections 數據建構圖形,並尋找長度最多五個且使用 "red" 外向路由之線條的所有路徑,以及 "blue" 傳迴路由的線條。 函 all() 式可確保可變長度邊緣中的所有邊緣都是相同行的一部分,可以是 "red" 或 "blue"。
let connections = datatable(from_station:string, to_station:string, line:string)
[
"Central", "North", "red",
"North", "Central", "red",
"Central", "South", "red",
"South", "Central", "red",
"South", "South-West", "red",
"South-West", "South", "red",
"South-West", "West", "red",
"West", "South-West", "red",
"Central", "East", "blue",
"East", "Central", "blue",
"Central", "West", "blue",
"West", "Central", "blue",
];
connections
| make-graph from_station --> to_station with_node_id=station
| graph-match (start)-[outward*1..5]->(destination)-[return*1..5]->(start)
where start.station != destination.station and
all(outward, line == "red") and
all(return, line == "blue")
project from = start.station,
outward_stations = strcat_array(map(inner_nodes(outward), station), "->"),
to = destination.station,
return_stations = strcat_array(map(inner_nodes(return), station), "->"),
back=start.station
輸出
| 從 | outward_stations | 至 | return_stations | 返回 |
|---|---|---|---|---|
| 中央 | 中南部>->South-West> | 西 | 中央 | |
| 西 | 西南->中>南部->北 | 中央 | 西 | |
| 中央 | 南South-West> | 西 | 中央 | |
| 西 | 西南->南 | 中央 | 西 | |
| 中央 | 中南部>->South-West> | 西 | >中東部 | 中央 |
| 西 | 西南->中>南部->北 | 中央 | >中東部 | 西 |
| 中央 | 南South-West> | 西 | >中東部 | 中央 |
| 西 | 西南->南 | 中央 | >中東部 | 西 |
下列範例示範如何使用 graph-shortest-paths 運算符搭配 all() 和 inner_nodes 函式,在運輸網路中尋找兩個月臺之間的路徑。 查詢會從 connections 數據建構圖表,並尋找從 "South-West" 月臺到 "North" 月臺的最短路徑,並傳遞 Wi-Fi 可用的月臺。
let connections = datatable(from_station:string, to_station:string, line:string)
[
"Central", "North", "red",
"North", "Central", "red",
"Central", "South", "red",
"South", "Central", "red",
"South", "South-West", "red",
"South-West", "South", "red",
"South-West", "West", "red",
"West", "South-West", "red",
"Central", "East", "blue",
"East", "Central", "blue",
"Central", "West", "blue",
"West", "Central", "blue",
];
let stations = datatable(station:string, wifi: bool)
[
"Central", true,
"North", false,
"South", false,
"South-West", true,
"West", true,
"East", false
];
connections
| make-graph from_station --> to_station with stations on station
| graph-shortest-paths (start)-[connections*2..5]->(destination)
where start.station == "South-West" and
destination.station == "North" and
all(inner_nodes(connections), wifi)
project from = start.station,
stations = strcat_array(map(inner_nodes(connections), station), "->"),
to = destination.station
輸出
| 從 | 站 | 至 |
|---|---|---|
| South-West | >中西部 | 北 |