Other API

Record

class graphdbapi.BoltStatementResult(session, hydrant, metadata)

基类:StatementResult

A handler for the result of Cypher statement execution.

get(key, default=None)
返回类型:

Any

index(key)

返回键对应的索引

返回类型:

int

value(key=0, default=None)

若key为int类型则通过key获取其index,然后取对应的值

参数:

key (str or int) --

返回类型:

int

keys()

获取所有的key

返回类型:

List [str]

values(*keys)

当keys不为空时获取指定数据,否则获取全部数据

返回类型:

List [Any]

items(*keys)

当keys不为空时获取指定数据,否则获取全部数据

返回类型:

List [Tuple [str, Any]]

data(*keys)

当keys不为空时获取指定数据,否则获取全部数据

返回类型:

Dict [str, Any]

BoltStatementResult

class graphdbapi.BoltStatementResult(session, hydrant, metadata)

基类:StatementResult

A handler for the result of Cypher statement execution.

consume()

消耗结果中的剩余部分

data(*items)

以list嵌套dict的形式返回结果的剩余部分

参数:

itmes -- 为剩余的 Record 返回的字段

返回类型:

List [Dict [str, Any]]

values(*items)

以list嵌套list的形式返回结果的剩余部分

参数:

itmes -- 为剩余的 Record 返回的字段

返回类型:

List [List [Any]]

value(item=0, default=None)

以值列表的形式返回结果的剩余部分

参数:
  • itme -- Record 需要返回的字段

  • default -- 字段不存在时返回default

返回类型:

List [Any]

__iter__()
records()

返回用于从结果中获取数据的生成器

Yields:

Record

Node

class graphdbapi.Node(graph, n_id)

基类:Entity

Self-contained graph node.

node == other

比较节点是否相等

hash(self)

计算hash值

len(self)

节点属性数量

iter(self)

遍历节点上的所有属性。

self[key]

按key返回属性。 Raises KeyError 如果key不存在

id

节点id

label

节点类型

get(name, default=None)

按名称获取属性值,可选择使用默认值

参数:
  • name (str) -- 属性名称

  • default (object) --

返回:

属性值,当属性不存在时返回 default

返回类型:

object

keys()

返回所有属性名称的可迭代对象

返回类型:

Iter[str]

values()

返回所有属性值的可迭代对象。

返回类型:

Iter[object]

items()

返回所有属性名称-值对的可迭代对象。

返回类型:

Iter[(str, object)...]

Relationship

class graphdbapi.Relationship(graph, r_id, r_type)

基类:Entity

Self-contained graph relationship.

relationship == other

比较relationship是否相等

hash(self)

计算hash值

len(self)

属性数量

iter(self)

遍历关系上的所有属性。

self[key]

按key返回属性。 Raises KeyError 如果key不存在

id

关系id

type

关系类型

start_node

起点

返回类型:

Node

end_node

终点

返回类型:

Node

Path

class graphdbapi.Path(start_node, *relationships)

基类:object

Self-contained graph path.

relationship == other

比较路径是否相等

hash(self)

计算hash值

len(self)

路径长度(关系数量)

iter(self)

遍历所有关系。

nodes

节点列表

返回类型:

list [Node]

relationships

关系列表

返回类型:

list [Relationship]

start_node

起点

返回类型:

Node

end_node

终点

返回类型:

Node

Vertex

class graphdbapi.Vertex(node, graph)

基类:GsVertex

参数:

node (Node) --

get_id()

获取点的id

返回:

返回类型:

int

get_type()

获取点的类型

返回:

返回类型:

str

has_property(key)

判断是否有某个属性名

参数:

key (str) -- 属性名

返回:

true 有值,false 没值

返回类型:

bool

get_property(key)

获取某个属性名对应的值

参数:

key (str) -- 属性名

返回:

get_property_keys()

返回所有的属性名

返回:

返回类型:

list

get_all_properties()

返回所有属性集合

返回:

返回类型:

dict

Edge

class graphdbapi.Edge(relationship, graph)

基类:GsEdge

参数:

relationship (Relationship) --

get_id()

获取边的id

返回:

返回类型:

str

get_type()

获取边的类型

返回:

返回类型:

str

get_from_vertex_id()

获取起始点id

返回:

返回类型:

int

get_from_vertex()

获取起始点信息。 不是同边信息一同返回,额外调用了{@link Graph#retrieveVertex(long)}方法获取。

返回:

返回类型:

Vertex

get_to_vertex_id()

获取终止点id。

返回:

返回类型:

int

get_to_vertex()

获取终止点信息。 不是同边信息一同返回,额外调用了{@link Graph#retrieveVertex(long)}方法获取。

返回:

返回类型:

Vertex

has_property(key)

判断是否有某个属性名

参数:

key (str) -- 属性名

返回:

true 有值,false 没值

返回类型:

bool

get_property(key)

获取某个属性名对应的值

参数:

key (str) -- 属性名

返回:

get_property_keys()

返回所有的属性名

返回:

返回类型:

list

get_all_properties()

返回所有属性集合

返回:

返回类型:

dict

MetricInfo

class graphdbapi.MetricInfo(**kwargs)

基类:object

get_id()

节点id

get_node_start_time()

启动时间

get_addresses()

节点地址

get_host_name()

节点主机名

get_heap_init()

节点id

get_heap_used()

节点id

get_heap_committed()

heap Committed

get_heap_max()

heap Max

get_heap_total()

heap Total

get_last_update_time()
get_thread_cnt()
get_daemon_thread_cnt()
get_peak_thread_cnt()
get_started_thread_cnt()
get_graph_metrics()

CypherQuery

class graphdbapi.v1.CypherQuery(task_id, cypher, graph_name, user_name, start_time)

基类:object

参数:
  • task_id (int) --

  • cypher (str) --

  • graph_name (str) --

  • user_name (str) --

  • start_time (int) --

get_task_id()
返回类型:

int

get_cypher()
返回类型:

str

get_graph_name()
返回类型:

str

get_user_name()
返回类型:

str

get_start_time()
返回类型:

int

SearchOrder

class graphdbapi.v1.SearchOrder(prop, order_by)

基类:object

参数:
  • prop (str) --

  • order_by (OrderBy) --

prop

属性

Rtype:

str

order_by

排序方式

Rtype:

OrderBy

SearchPredicate

class graphdbapi.v1.SearchPredicate

基类:object

查询判断,包含属性名、比较类型、比较类型所需值

classmethod init_contains_predicate(prop, val)

谓词 包含

参数:
  • prop (str) -- 属性名

  • val (str) -- 包含的值

返回:

self

classmethod init_prefix_predicate(prop, val)

谓词 前缀

参数:
  • prop (str) -- 属性名

  • val (str) -- 前缀的值

返回:

self

classmethod init_suffix_predicate(prop, val)

谓词 后缀

参数:
  • prop (str) -- 属性名

  • val (str) -- 后缀的值

返回:

self

classmethod init_less_than_predicate(prop, val, eq1)

谓词 小于或小于等于

参数:
  • prop (str) -- 属性名

  • val (Union[int, float]) -- 比较的值

  • eq1 (bool) -- 是否包含等于

返回:

self

classmethod init_greater_than_predicate(prop, val, eq1)

谓词 大于或大于等于

参数:
  • prop (str) -- 属性名

  • val (Union[int, float]) -- 比较的值

  • eq1 (bool) -- 是否包含等于

返回:

self

classmethod init_range_number_predicate(prop, val1, val2, eq1, eq2)

谓词 范围

参数:
  • prop (str) -- 属性名

  • val1 (Union[int, float]) -- 与目的比较的值(范围最小值)

  • val2 (Union[int, float]) -- 与目的比较的值(范围最大值)

  • eq1 (bool) -- 是否包含等于范围最小值

  • eq2 (bool) -- 是否包含范围最大值

返回:

self

classmethod init_equal_predicate(prop, val)

谓词 等于

参数:
  • prop (str) -- 属性名

  • val (Any) -- 与目的比较的值

返回:

self

CombinedEdgeType

class graphdbapi.v1.graph.CombinedEdgeType

基类:object

边信息

classmethod init_combined_edge_type(from_type: str, to_type: str)
参数:
  • from_type (str) -- 起始点类型

  • to_type (str) -- 终止点类型

返回类型:

CombinedEdgeType

EdgeInfo

class graphdbapi.v1.graph.EdgeInfo

基类:object

static init_edge_info(edge_id, property=None, is_merge=True)
参数:
  • edge_id (str) -- 边id

  • property (Optional [Dict [str, Any]]) -- 边属性

  • is_merge (bool) -- 为 True 时集合属性追加,为 False 属性覆盖

EdgeInfoByVertexId

class graphdbapi.v1.graph.EdgeInfoByVertexId

基类:object

static init_edge_info_by_vertex_id(from_id, to_id, type, property, is_merge=True)
参数:
  • from_id (int) -- 起始点id

  • to_id (int) -- 终止点id

  • type (str) -- 边类型

  • property (Optional [Dict [str, Any]]) -- 边属性

  • is_merge (bool) -- 为 True 时集合属性追加,为 False 属性覆盖

EdgeInfoByVertexPk

class graphdbapi.v1.graph.EdgeInfoByVertexPk

基类:object

批量添加边的基础信息封装

static init_edge_info_by_vertex_pk(from_pk, from_type, to_pk, to_type, type, property, is_merge=True)

根据点主键创建边。如果起始点或终止点不存在,则会抛异常

参数:
  • is_merge --

  • from_pk (str) -- 起始点主键值。由于通过边类型能确定起始类型和终止类型,因此这里需要填点类型

  • from_type (str) -- 起始点类型

  • to_pk (str) -- 终止点主键值。由于通过边类型能确定起始类型和终止类型,因此这里需要填点类型

  • to_type (str) -- 终止点类型

  • type (str) -- 边类型

  • property (Optional[Dict[str, Any]]) -- 边属性

返回:

返回类型:

EdgeInfoByVertexPk

static init_edge_info_by_vertex_pk_with_create(from_pk, from_type, create_from, to_pk, to_type, create_to, type, property, is_merge=True)

根据点主键创建边。

参数:
  • from_pk (str) -- 起始点主键值。由于通过边类型能确定起始类型和终止类型,因此这里需要填点类型

  • from_type (str) -- 起始点类型

  • create_from (bool) -- 如果起始点不存在,true是需要创建一个无属性点。false是返回异常

  • to_pk (str) -- 终止点主键值。由于通过边类型能确定起始类型和终止类型,因此这里需要填点类型

  • to_type (str) -- 终止点类型

  • createTo -- 如果终止点不存在,true是需要创建一个无属性点。false是返回异常

  • type (str) -- 边类型

  • property (Optional[Dict[str, Any]]) -- 边属性

  • create_to (bool) --

返回:

返回类型:

EdgeInfoByVertexPk

ResponseItem

class graphdbapi.v1.graph.ResponseItem

基类:object

返回消息内容

is_error()

执行是否出错

返回类型:

bool

message()
返回:

错误信息

返回类型:

str

data()
返回类型:

Union[Vertex, Edge]

VertexInfoById

class graphdbapi.v1.graph.VertexInfoById

基类:object

static init_vertex_info_by_id(id, property, is_merge)
参数:
  • id (int) -- 点id

  • property (Optional [Dict [str, Any]]) -- 点属性

  • is_merge (bool) -- 为 True 时集合属性追加,为 False 属性覆盖

返回类型:

VertexInfoById

VertexInfoByPk

class graphdbapi.v1.graph.VertexInfoByPk

基类:object

批量添加点的参数信息封装

static init_vertex_info_by_pk(pk, type, is_merge=True)
参数:
  • pk (str) -- 点pk

  • type (str) -- 点类型

  • is_merge (bool) -- 为 True 时集合属性追加,为 False 属性覆盖

返回类型:

VertexInfoByPk

static init_vertex_info_by_pk_and_property(pk, type, property, is_merge=True)
参数:
  • pk (str) -- 点pk

  • type (str) -- 点类型

  • property (Optional [Dict [str, Any]]) -- 点属性

  • is_merge (bool) -- 为 True 时集合属性追加,为 False 属性覆盖

返回类型:

VertexInfoByPk

EdgeDegreeInfo

class graphdbapi.v1.graph.query.EdgeDegreeInfo

基类:object

边的度数信息汇总

get_degree_info()

key是边类型,value是对应类型的总degree数量

返回类型:

Dict[str, int]

get_degree()

边的总度数值

返回类型:

int

ResponseElementInfo

class graphdbapi.v1.graph.query.ResponseElementInfo

基类:object

bfs(广度优先搜索)结果集中,点和边的基础信息

get_element_id()

元素id

返回类型:

str

get_pk()

元素为点时,对应的主键值

返回类型:

str

get_type()

元素对应的类型(点类型 or 边类型)

返回类型:

str

get_from_id()

元素为边时,对应的起始点ID

返回类型:

int

get_to_id()

元素为边时,对应的终止点ID

返回类型:

int

get_direct()

元素为边时,对应边方向

返回类型:

bool

get_edge_property_map()

元素为边时,对应的边属性

返回类型:

Dict[str, Any]

QueryResult

class graphdbapi.v1.graph.query.bfs.QueryResult

基类:object

bfs(广度优先搜索)结果集

get_vertex_set()
返回:

点集合

返回类型:

Dict [int, ResponseElementInfo]

get_edge_set()
返回:

边集合

返回类型:

Dict [str, ResponseElementInfo]

get_vertex_count()

点总数

get_edge_count()

边总数

PropertyFilter

class graphdbapi.v1.graph.query.condition.PropertyFilter

基类:object

属性过滤集合,是{ VisitConditionByProperty}的依赖类

static init_Property_filter()
返回类型:

PropertyFilter

add_filter_by_property_filter_info(property_filter_info)
参数:

property_filter_info (PropertyFilterInfo) --

add_filter_by_params(property_name, method, value, value2=None)
参数:

PropertyFilterInfo

class graphdbapi.v1.graph.query.condition.PropertyFilterInfo

基类:object

具体的属性过滤,是{PropertyFilter}的依赖类

static init_property_filter_info(property_name, method, value, value2=None)

给是范围比较的符号{ QueryMethod}使用

参数:
  • property_name (str) -- 属性名

  • method (QueryMethod) --

  • value -- 比较范围的最小值

  • value2 -- 比较范围的最大值

返回:

VisitCondition

class graphdbapi.v1.graph.query.condition.VisitCondition

条件过滤基类

VisitConditionByProperty

class graphdbapi.v1.graph.query.condition.VisitConditionByProperty

基类:VisitCondition

对属性添加条件过滤

static init_visit_condition_by_property(condition_filter_map, is_vertex)
参数:
  • condition_filter_map (Dict[str, PropertyFilter]) --

  • is_vertex (bool) --

VisitConditionByType

class graphdbapi.v1.graph.query.condition.VisitConditionByType

基类:VisitCondition

对类型添加过滤

static init_visit_condition_by_type(type_set, type_condition_method, is_vertex)
参数:
  • type_set (Set[str]) -- 类型集合

  • type_condition_method (TypeConditionMethod) -- {TypeConditionMethod} 对typeSet中的类型添加条件

  • is_vertex (bool) -- 该条件中的类型是点类型还是边类型,true是点类型,false是边类型

返回:

VisitConditionComposite

class graphdbapi.v1.graph.query.condition.VisitConditionComposite

基类:VisitCondition

多条件组合类,可以组合{ VisitConditionByProperty} 和 {VisitConditionByType}

多个条件之间通过AND组合

static init_visit_condition_composite(*values)

VisitCondition :param values: :return:

参数:

values (VisitCondition) --

VisitConditionCompositeOr

class graphdbapi.v1.graph.query.condition.VisitConditionCompositeOr

基类:VisitCondition

多条件组合类,可以组合{ VisitConditionByProperty} 和 { VisitConditionByType}

多个条件之间通过OR组合

static init_visit_condition_composite_or(*values)
参数:

values (VisitCondition) --

BfsParam

class graphdbapi.v1.graph.query.bfs.BfsParam

start_id: 起始点id,不能小于0

depth: 深度,范围必须为(0-10)。

邻居点上限,填小于0 不参与计算。

limit_edge: 邻居边上限,填小于0 不参与计算。

dir_list: 方向集合,需要 size = 1 或者 size = depth,不可为 None

vertex_condition_list: 点查询条件集合,需要 size = 1 或者 size = depth;填 None 不参与计算;

edge_condition_list: 边查询条件集合,需要size = 1 或者 size = depth;填 None 不参与计算;

edge_type_filter_list: 边类型过滤集合,需要size = 1 或者 size = depth;填null不参与计算 以上三个 List 都是和 depth 对应的,如果 size = 1,那么这个过滤条件会被复制,每一度都是这个过滤条件, 如果你只想给某一度添加过滤条件,那么应该在 list 的其他位置 add(null)。

hop: 是否 启用hop模式。只返回最外层的点。

only_count: 是否只返回 count。True表示返回count。

return_vertex: 是否返回结果点集。只有only_count为False时生效。

return_edge: 是否返回结果边集。只有only_count为False时生效。

BfsParamBuilder 构建

Show-inheritance:

BfsParamBuilder

class graphdbapi.v1.graph.query.bfs.BfsParamBuilder
DEMO:

BfsParamBuilder.init_by_pk("10086", "user", 2).set_hop(True).set_only_count(True).builder()

BfsParam构建类

Show-inheritance:
builder()

构建BfsParam

返回:

返回类型:

BfsParam

classmethod init_by_id(start_id, depth)

通过id初始化构造器

参数:
  • start_id (int) -- 点id

  • depth (int) -- 深度

返回:

self

返回类型:

BfsParamBuilder

classmethod init_by_pk(pk, Type, depth)

通过pk初始化构造器

参数:
  • pk (str) -- 点pk

  • Type (str) -- 点类型

  • depth (int) -- 深度

返回:

self

返回类型:

BfsParamBuilder

set_limit_neighbor(limit_neighbor)
参数:

limit_neighbor (int) -- 邻居点上限,-1为不限制。默认值:-1

返回:

self

返回类型:

BfsParamBuilder

set_limit_edge(limit_edge)
参数:

limit_edge (int) -- 邻居边上限,-1为不限制。默认值:-1

返回:

self

返回类型:

BfsParamBuilder

set_hop(hop)
参数:

hop (bool) -- 是否启用hop模式。默认值:false

返回:

self

返回类型:

BfsParamBuilder

set_only_count(only_count)
参数:

only_count (bool) -- true表示只返回count。默认值:false

返回:

self

返回类型:

BfsParamBuilder

set_return_vertex(return_vertex)
参数:

return_vertex (bool) -- 是否返回结果点集。只有onlyCount为false时生效。默认值:false

返回:

self

返回类型:

BfsParamBuilder

set_return_edge(return_edge)
参数:

return_edge (bool) -- 是否返回结果边集。只有onlyCount为false时生效。默认值:false

返回:

返回类型:

BfsParamBuilder

set_direction(direction, specified_depth=-1)
参数:
  • direction (Direction) -- 边方向

  • specified_depth -- 为-1时为所有扩展都设置此条件。否则只应用于指定度数

返回:

返回类型:

BfsParamBuilder

set_vertex_condition(pv, specified_depth=-1)
参数:
  • pv (VisitCondition) -- 点过滤条件。默认无条件。

  • specified_depth -- 为-1时为所有扩展都设置此条件。否则只应用于指定度数

返回:

self

返回类型:

BfsParamBuilder

set_edge_condition(pe, specified_depth=-1)
参数:
  • pv -- 边过滤条件。默认无条件。

  • specified_depth -- 为-1时为所有扩展都设置此条件。否则只应用于指定度数

  • pe (VisitCondition) --

返回:

self

返回类型:

BfsParamBuilder

set_edge_type_filter(edge_type, specified_depth=-1)
参数:
  • edge_type (Set[str]) -- 边类型过滤条件。默认无条件。

  • specified_depth -- 为-1时为所有扩展都设置此条件。否则只应用于指定度数

返回:

返回类型:

BfsParamBuilder