7. Dealing with Vertices

There are several operations that can be performed directly on the vertices of a graph.

class pypgx.api.VertexCollection(graph, java_collection)

A collection of vertices.

Parameters

graph (PgxGraph) –

Return type

None

add(v)

Add one or multiple vertices to the collection.

Parameters

v (Union[pypgx.api._pgx_entity.PgxVertex, int, str, Iterable[Union[pypgx.api._pgx_entity.PgxVertex, int, str]]]) – Vertex or vertex id. Can also be an iterable of vertices/Vetrices ids

Return type

None

add_all(vertices)

Add multiple vertices to the collection.

Parameters

vertices (Iterable[Union[pypgx.api._pgx_entity.PgxVertex, int, str]]) – Iterable of vertices/Vertices ids

Return type

None

contains(v)

Check if the collection contains vertex v.

Parameters

v (Union[pypgx.api._pgx_entity.PgxVertex, int, str]) – PgxVertex object or id

Return type

bool

remove(v)

Remove one or multiple vertices from the collection.

Parameters

v (Union[pypgx.api._pgx_entity.PgxVertex, int, str, Iterable[Union[pypgx.api._pgx_entity.PgxVertex, int, str]]]) – Vertex or vertex id. Can also be an iterable of vertices/Vetrices ids.

Return type

None

remove_all(vertices)

Remove multiple vertices from the collection.

Parameters

vertices (Iterable[Union[pypgx.api._pgx_entity.PgxVertex, int, str]]) – Iterable of vertices/Vetrices ids

class pypgx.api.VertexLabels(graph, java_labels)

Class for storing labels for vertices.

A vertex can have multiple labels. In effect this is a VertexProperty where a set of strings is associated to each vertex.

Parameters

graph (PgxGraph) –

Return type

None

get_values()

Get the values of this label as a list.

Returns

a list of key-value tuples, where each key is a vertex and each key is the set of labels assigned to that vertex

Return type

list of tuple(PgxVertex, set of str)

class pypgx.api.VertexProperty(graph, java_prop)

A vertex property of a PgxGraph.

Parameters

graph (PgxGraph) –

Return type

None

get(key)

Get a property value.

Parameters

key (Union[pypgx.api._pgx_entity.PgxVertex, int, str]) – The vertex (or vertex ID) whose property to get

Return type

Any

set(key, value)

Set a property value.

Parameters
Return type

None

set_values(values)

Set the labels values.

Parameters

values (PgxMap) – pgxmap with ids and values

Return type

None

class pypgx.api.VertexSequence(graph, java_collection)

An ordered sequence of vertices which may contain duplicates.

Parameters

graph (PgxGraph) –

Return type

None

class pypgx.api.VertexSet(graph, java_collection)

An unordered set of vertices (no duplicates).

Parameters

graph (PgxGraph) –

Return type

None

extract_top_k_from_map(pgx_map, k)

Extract the top k keys from the given map and puts them into this collection.

Parameters
  • pgx_map (PgxMap) – the map to extract the keys from

  • k (int) – how many keys to extract

Return type

None