图形any()
函数计算沿可变长度路径的每个边缘或内部节点的条件。
语法
any(
边缘,
条件)
any(inner_nodes(
边缘),
条件)
参数
名称 | 类型 | 必选 | DESCRIPTION |
---|---|---|---|
边缘 | string |
✔️ | 图形匹配运算符 或 图形最短路径运算符 模式中的可变长度边缘。 有关详细信息,请参阅 图形模式表示法。 |
条件 | string |
✔️ | 在可变长度边缘中使用inner_nodes时,由边缘或内部节点的属性组成的布尔表达式。 直接使用属性名称引用属性。 为 可变长度边缘中的每个 边缘 或 内部节点 计算表达式。 |
退货
如果在true
true
中使用inner_nodes,条件的计算结果为至少一个边缘或内部节点。 否则,它将返回 false
。
对于零长度路径,条件的计算结果为 false
。
例子
以下示例使用 Locations
和 Routes
数据表构造一个图形,该图通过 route
查找从源位置到目标位置的路径。 它使用 any()
函数查找至少使用 "Train"
运输方法的路径一次。 它返回路线沿线的源位置名称、目标位置名称和运输方法。
// Locations table (nodes)
let Locations = datatable(LocationName: string, LocationType: string) [
"New York", "City",
"San Francisco", "City",
"Chicago", "City",
"Los Angeles", "City",
"Seattle", "Warehouse"
];
// Routes table (edges)
let Routes = datatable(OriginLocationID: string, DestinationLocationID: string, TransportMode: string) [
"New York", "San Francisco", "Truck",
"New York", "Chicago", "Train",
"San Francisco", "Los Angeles", "Truck",
"Chicago", "Seattle", "Train",
"Los Angeles", "New York", "Truck",
"Seattle", "San Francisco", "Train"
];
Routes
| make-graph OriginLocationID --> DestinationLocationID with Locations on LocationName
| graph-match (src)-[route*1..2]->(dest)
where any(route, TransportMode == "Train")
project src.LocationName,
dest.LocationName,
route_TransportModes = map(route, TransportMode)
输出
src_LocationName | dest_LocationName | route_TransportModes |
---|---|---|
西雅图 | 旧金山 | [“Train”] |
芝加哥 | 西雅图 | [“Train”] |
纽约 | 芝加哥 | [“Train”] |
西雅图 | 洛杉矶 | [ “训练”, “卡车” ] |
芝加哥 | 旧金山 | [ “训练”, “训练” ] |
纽约 | 西雅图 | [ “训练”, “训练” ] |
洛杉矶 | 芝加哥 | [ “卡车”, “训练” ] |
以下示例演示如何将作员与函数graph-shortest-paths
一any()
起使用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-match cycles=none (start)-[connections*2..5]->(destination)
where start.station == "South-West" and
destination.station == "North" and
any(inner_nodes(connections), wifi)
project from = start.station,
stations = strcat_array(map(inner_nodes(connections), station), "->"),
to = destination.station
输出
从 | 站 | 到 |
---|---|---|
South-West | 中南部-> | 北部 |
South-West | 中西部-> | 北部 |