Algorithm Documentation¶
shortest_path¶
最短路径,返回一条最短路径的所有边。
函数声明
def shortest_path(self, start_id: int, end_id: int, path_edge_type: Union[Set[str], None], limit: int = 1) -> Iterator[Edge]
参数说明
Parameter |
Optional |
Type |
DESC |
---|---|---|---|
start_id |
Y |
int |
起始点id,不能小于0。 |
end_id |
Y |
int |
终止点id,不能小于0。 |
path_edge_type |
N |
Union[Set[str], None] |
路径包含的边类型,填None不进行过滤。 |
limit |
Y |
int |
长度限制,最远限制10跳。 |
响应参数
Parameter |
Type |
DESC |
---|---|---|
Iterator[Edge] |
边列表的迭代器 |
异常
Type |
DESC |
---|---|
ParamException |
参数格式不正确,当起始点id、终止点id小于0时将抛出异常。 |
VertexNotFoundException |
起始点或终止点在图中不存在时将抛出异常。 |
TypeNotFoundException |
边类型在图中不存在时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
from graphdbapi.types.graph import Edge
# 查询起始点(点id: 13703631) 到 终止点(点id: 19943527)的所有边类型
for edge in graph.shortest_path(13703631, 19943527, None, 1):
print(edge)
bfs_master¶
多度查询邻居。通过起始点id查询。
函数声明
def bfs_master(
self, start_id: int, depth: int, limit_neighbor: int, limit_edge: int, dir_list: List[Direction],
vertex_condition_list: Union[List[VisitCondition], None], edge_condition_list: Union[List[VisitCondition], None],
edge_type_filter_list: Union[List[Set[str]], None], hop: bool, only_count: bool,
return_vertex: bool, return_edge: bool) -> QueryResult
参数说明
Parameter |
Optional |
Type |
DESC |
---|---|---|---|
start_id |
Y |
int |
起始点id,不能小于0。 |
depth |
Y |
int |
深度,范围必须为(0-10)。 |
limit_neighbor |
Y |
int |
邻居点上限,填<0 不参与计算 |
limit_edge |
Y |
int |
邻居边上限,填<0 不参与计算 |
dir_list |
Y |
List[Direction] |
方向列表,需要size = 1 或者 size = depth,不可为None, size为列表长度 |
vertex_condition_list |
N |
List[VisitCondition] |
点查询条件列表,需要size = 1 或者 size = depth;填None不参与计算, size为列表长度 |
edge_condition_list |
N |
List[VisitCondition] |
边查询条件列表,需要size = 1 或者 size = depth;填None不参与计算, size为列表长度 |
edge_type_filter_list |
N |
List[Set[str]] |
边类型过滤列表,需要size = 1 或者 size = depth;填None不参与计算, size为列表长度 |
hop |
Y |
bool |
是否启用hop模式(只返回最外层的点)。 |
only_count |
Y |
bool |
是否只返回 count。True表示返回count。 |
return_vertex |
Y |
bool |
是否返回结果点集。只有only_count为False时生效 |
return_edge |
Y |
bool |
是否返回结果边集。只有only_count为False时生效 |
响应参数
Parameter |
Type |
DESC |
---|---|---|
bfs查询结果 |
异常
Type |
DESC |
---|---|
ParamException |
参数格式不正确,当点id小于0、深度不符合要求,方向集合、点/边条件集合或边类型过滤集合长度不符合要求时将抛出异常。 |
VertexNotFoundException |
起始点在图中不存在时将抛出异常。 |
TypeNotFoundException |
边类型在图中不存在时将抛出异常。 |
PropertyNotFoundException |
点/边条件过滤对应的属性类型在指定点/边类型中不存在时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
from graphdbapi.v1.graph.query.bfs import QueryResult
from graphdbapi.v1.enum import Direction, QueryMethod
from graphdbapi.v1.graph.query.condition import *
# Direction,VertexCondition,EdgeCondition,VisitConditionByType 参考2.2节
# 边方向
dir_list = list()
dir_list.append(Direction.OUT)
# 查询点id为18的3度出度相邻节点
result = graph.bfs_master(18, 3, -1, -1, dir_list, None, None, None, False, False, True, True)
# 点边数量
print(result)
bfs_master_by_pk¶
多度查询邻居。通过起始点pk查询
函数声明
def bfs_master_by_pk(
self, pk: str, type: str, depth: int, limit_neighbor: int, limit_edge: int, dir_list: List[Direction],
vertex_condition_list: Union[List[VisitCondition], None], edge_condition_list: Union[List[VisitCondition], None],
edge_type_filter_list: Union[List[Set[str]], None], hop: bool, only_count: bool,
return_vertex: bool, return_edge: bool
) -> QueryResult
参数说明
Parameter |
Optional |
Type |
DESC |
---|---|---|---|
pk |
Y |
str |
点pk,不能为空。 |
type |
Y |
str |
点类型,不能为空。 |
depth |
Y |
int |
深度,范围必须为(0-10)。 |
limit_neighbor |
Y |
int |
邻居点上限,填<0 不参与计算 |
limit_edge |
Y |
int |
邻居边上限,填<0 不参与计算 |
dir_list |
Y |
List[Direction] |
方向列表,需要size = 1 或者 size = depth,不可为None, size为列表长度 |
vertex_condition_list |
N |
List[VisitCondition] |
点查询条件列表,需要size = 1 或者 size = depth;填None不参与计算, size为列表长度 |
edge_condition_list |
N |
List[VisitCondition] |
边查询条件列表,需要size = 1 或者 size = depth;填None不参与计算, size为列表长度 |
edge_type_filter_list |
N |
List[Set[str]] |
边类型过滤列表,需要size = 1 或者 size = depth;填None不参与计算, size为列表长度 |
hop |
Y |
bool |
是否启用hop模式(只返回最外层的点)。 |
only_count |
Y |
bool |
是否只返回 count。True表示返回count。 |
return_vertex |
Y |
bool |
是否返回结果点集。只有only_count为False时生效 |
return_edge |
Y |
bool |
是否返回结果边集。只有only_count为False时生效 |
响应参数
Parameter |
Type |
DESC |
---|---|---|
bfs查询结果 |
异常
Type |
DESC |
---|---|
ParamException |
参数格式不正确,当点pk为空、点类型为空、深度不符合要求,方向集合、点/边条件集合或边类型过滤集合长度不符合要求时将抛出异常。 |
VertexNotFoundException |
起始点在图中不存在时将抛出异常。 |
TypeNotFoundException |
边类型在图中不存在时将抛出异常。 |
PropertyNotFoundException |
点/边条件过滤对应的属性类型在指定点/边类型中不存在时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
from graphdbapi.v1.graph.query.bfs import QueryResult
from graphdbapi.v1.enum import Direction, QueryMethod
from graphdbapi.v1.graph.query.condition import *
# Direction,VertexCondition,EdgeCondition,VisitConditionByType 参考2.2节
# 边方向
dir_list = list()
dir_list.append(Direction.OUT)
# 查询点{pk:1,Type:个人}的3度出度相邻节点
result = graph.bfs_master_by_pk("1", "个人", 3, -1, -1, dir_list, None, None, None, False, False, True, True)
# 输出结果
print(result)
bfs_by_param¶
多度查询邻居,针对bfs参数进行的封装
函数声明
def bfs_by_param(self, bfs_param: BfsParam) -> QueryResult
参数说明
Parameter |
Optional |
Type |
DESC |
bfs_param |
Y |
bfsMaster参数对象 |
响应参数
Parameter |
Type |
DESC |
bfs查询结果 |
异常
Type |
DESC |
ParamException |
参数格式不正确,当点pk为空、点类型为空、深度不符合要求,方向集合、点/边条件集合或边类型过滤集合长度不符合要求时将抛出异常。 |
VertexNotFoundException |
起始点在图中不存在时将抛出异常。 |
TypeNotFoundException |
边类型在图中不存在时将抛出异常。 |
PropertyNotFoundException |
点/边条件过滤对应的属性类型在指定点/边类型中不存在时将抛出异常。 |
DatabaseException |
数据库内部异常。 |
示例
from graphdbapi.v1.graph.query.bfs import BfsParamBuilder
bfs_param = BfsParamBuilder.init_by_id(0, 10).set_hop(False).set_only_count(True).builder()
result = graph.bfs_by_param(bfs_param)
# 输出结果
print(result)
execute_procedure¶
通过bolt执行procedure方法。
函数声明
def execute_procedure(self, procedure_name: str, *input_params: Any) -> BoltStatementResult:
参数说明
Parameter |
Optional |
Type |
DESC |
---|---|---|---|
procedure_name |
Y |
str |
procedure方法名,不能为空。 |
input_params |
N |
Any |
入参(需按照procedure方法的参数顺序) |
响应参数
Parameter |
Type |
DESC |
---|---|---|
执行结果迭代器 |
异常
Type |
DESC |
---|---|
ParamException |
参数格式不正确 |
DatabaseException |
数据库内部异常。 |
示例
for _ in graph.execute_procedure("dbms.procedures"):
print(_)