Neo4j-based graphs

Neo4j-based persisent graph objects.

This module implements data structures that allow working with persistent graphs stored in an instance of the Neo4j database.

class regraph.backends.neo4j.graphs.Neo4jGraph(driver=None, uri=None, user=None, password=None, node_label='node', edge_label='edge', unique_node_ids=True)[source]

Class implementing Neo4j graph instance.

This class encapsulates neo4j.v1.GraphDatabase object. It provides an interface for accessing graph sitting in the DB. This interface is similar (in fact is intended to be as similar as possible) to the networkx.DiGraph object.

Attributes
_driverneo4j.v1.GraphDatabase

Driver providing connection to a Neo4j database

_node_labelstr

Label of nodes inducing the manipulated subgraph.

_edge_labelstr

Type of relations used in the manipulated subgraph.

Methods

add_edge(self, s, t[, attrs])

Add an edge to a graph.

add_node(self, node[, attrs, ignore_naming])

Abstract method for adding a node.

edges(self[, data])

Return the list of edges of the graph.

find_matching(self, pattern[, nodes, …])

Find matching of a pattern in a graph.

from_json([driver, uri, user, password, …])

Create a Neo4jGraph from a json-like dictionary.

get_edge(self, s, t)

Get edge attributes.

get_node(self, node_id)

Get node attributes.

load([driver, uri, user, password, …])

Load a Neo4jGraph from a JSON file.

nodes(self[, data])

Return a list of nodes of the graph.

predecessors(self, node_id)

Return the set of predecessors.

relabel_node(self, node_id, new_id)

Relabel a node in the graph.

remove_edge(self, s, t)

Remove edge from the graph.

remove_node(self, node)

Remove node.

successors(self, node_id)

Return the set of successors.

update_edge_attrs(self, s, t, attrs[, normalize])

Update attributes of a node.

update_node_attrs(self, node_id, attrs[, …])

Update attributes of a node.

add_edge(self, s, t, attrs=None, **attr)[source]

Add an edge to a graph.

Parameters
graphnetworkx.(Di)Graph
shashable, source node id.
thashable, target node id.
attrsdict

Edge attributes.

add_node(self, node, attrs=None, ignore_naming=False)[source]

Abstract method for adding a node.

Parameters
nodehashable

Prefix that is prepended to the new unique name.

attrsdict, optional

Node attributes.

edges(self, data=False)[source]

Return the list of edges of the graph.

find_matching(self, pattern, nodes=None, graph_typing=None, pattern_typing=None)[source]

Find matching of a pattern in a graph.

classmethod from_json(driver=None, uri=None, user=None, password=None, json_data=None, node_label='node', edge_label='edge')[source]

Create a Neo4jGraph from a json-like dictionary.

Parameters
json_datadict

JSON-like dictionary with graph representation

get_edge(self, s, t)[source]

Get edge attributes.

Parameters
graphnetworkx.(Di)Graph
shashable, source node id.
thashable, target node id.
get_node(self, node_id)[source]

Get node attributes.

Parameters
graphnetworkx.(Di)Graph or regraph.neo4j.Neo4jGraph
node_idhashable, node id.
classmethod load(driver=None, uri=None, user=None, password=None, filename=None, node_label='node', edge_label='edge')[source]

Load a Neo4jGraph from a JSON file.

Create a graph object from a JSON representation stored in a file.

Parameters
driverneo4j.v1.direct.DirectDriver, optional

Driver providing connection to a Neo4j database

uristr, optional

Uri for a new Neo4j database connection (bolt)

userstr, optional

Username for the Neo4j database connection

passwordstr, optional

Password for the Neo4j database connection

filenamestr, optional

Name of the file to load the json serialization of the graph

node_labeloptional

Label of nodes inducing the subgraph to scope. By default “node”.

edge_labeloptional

Type of relations inducing the subgraph to scope. By default “edge”.

Returns
Graph object
Raises
ReGraphError

If was not able to load the file

nodes(self, data=False)[source]

Return a list of nodes of the graph.

predecessors(self, node_id)[source]

Return the set of predecessors.

relabel_node(self, node_id, new_id)[source]

Relabel a node in the graph.

Parameters
node_idhashable

Id of the node to relabel.

new_idhashable

New label of a node.

remove_edge(self, s, t)[source]

Remove edge from the graph.

Parameters
graphnetworkx.(Di)Graph
shashable, source node id.
thashable, target node id.
remove_node(self, node)[source]

Remove node.

Parameters
graphnetworkx.(Di)Graph
node_idhashable, node to remove.
successors(self, node_id)[source]

Return the set of successors.

update_edge_attrs(self, s, t, attrs, normalize=True)[source]

Update attributes of a node.

Parameters
shashable, source node of the edge to update.
thashable, target node of the edge to update.
attrsdict

New attributes to assign to the node

update_node_attrs(self, node_id, attrs, normalize=True)[source]

Update attributes of a node.

Parameters
node_idhashable, node to update.
attrsdict

New attributes to assign to the node