![]() |
STAG Python
2.0.2
Spectral Toolkit of Algorithms for Graphs
|
Represent a neo4j database as a stag.graph.LocalGraph object.
This provides 'local' access to the graph only. Given a node, we can query its neighbors and its degree. The graph does not support weighted edges, and it does not distinguish between edge types or directions.
The neo4j <id> attributes are used as the STAG vertex ids.
All methods which make calls to the database backend have a small cache of recent queries, meaning that consecutive queries for the same node will be fast.
Public Member Functions | |
| def | __init__ (self, str uri, str username, str password) |
| Connect to a neo4j database backend. | |
| def | degree (self, v) |
| Equivalent to stag.neo4j.Neo4jGraph.degree_unweighted. | |
| int | degree_unweighted (self, int v) |
| Query the degree of the node with the given neo4j ID. | |
| List[graph.Edge] | neighbors (self, int v) |
| Fetch the neighbors of the node with the given Neo4j node ID. | |
| List[int] | neighbors_unweighted (self, int v) |
| Fetch the neighbors of the node with the given Neo4j node ID. | |
| List[str] | query_node_labels (self, int node_id) |
| Query the labels of the given node. | |
| int | query_id (self, str property_name, str property_value) |
| Find the Neo4j ID of a node with the given property. | |
| str | query_property (self, int id, str property_name) |
| Find the requested property of a Neo4j node. | |
| bool | vertex_exists (self, int v) |
| Given a vertex ID, returns true or false to indicate whether the vertex exists in the graph. | |
Public Member Functions inherited from stag.graph.LocalGraph | |
| def | __init__ (self) |
| Default LocalGraph constructor. | |
| float | degree (self, int v) |
| Given a vertex v, return its weighted degree. | |
| int | degree_unweighted (self, int v) |
| Given a vertex v, return its unweighted degree. | |
| List[Edge] | neighbors (self, int v) |
| Given a vertex v, return a list of edges representing the neighbors of v. | |
| np.ndarray | neighbors_unweighted (self, int v) |
| Given a vertex v, return a list of neighbors of v. | |
| np.ndarray | degrees (self, np.ndarray vertices) |
| Given a list of vertices, return a list of their weighted degrees. | |
| np.ndarray | degrees_unweighted (self, np.ndarray vertices) |
| Given a list of vertices, return a list of their unweighted degrees. | |
| bool | vertex_exists (self, int v) |
| Given a vertex ID, returns true or false to indicate whether the vertex exists in the graph. | |
Public Attributes | |
| driver | |
| The neo4j database driver object used to query the underlying database. | |
| def stag.neo4j.Neo4jGraph.__init__ | ( | self, | |
| str | uri, | ||
| str | username, | ||
| str | password | ||
| ) |
Connect to a neo4j database backend.
For example, assuming that there is a Neo4j database running locally, the graph object can be created as follows.
It is also possible to connect to a remote Neo4j database by passing the relevant uri to the constructor.
| uri | the location of the neo4j database |
| username | the neo4j username |
| password | the neo4j password |
Reimplemented from stag.graph.LocalGraph.
| def stag.neo4j.Neo4jGraph.degree | ( | self, | |
| v | |||
| ) |
Equivalent to stag.neo4j.Neo4jGraph.degree_unweighted.
Reimplemented from stag.graph.LocalGraph.
| int stag.neo4j.Neo4jGraph.degree_unweighted | ( | self, | |
| int | v | ||
| ) |
Query the degree of the node with the given neo4j ID.
Reimplemented from stag.graph.LocalGraph.
| List[graph.Edge] stag.neo4j.Neo4jGraph.neighbors | ( | self, | |
| int | v | ||
| ) |
Fetch the neighbors of the node with the given Neo4j node ID.
The returned stag.graph.Edge objects all have weight 1.
Reimplemented from stag.graph.LocalGraph.
| List[int] stag.neo4j.Neo4jGraph.neighbors_unweighted | ( | self, | |
| int | v | ||
| ) |
Fetch the neighbors of the node with the given Neo4j node ID.
Returns the Neo4j node IDs of the neighboring nodes.
Reimplemented from stag.graph.LocalGraph.
| List[str] stag.neo4j.Neo4jGraph.query_node_labels | ( | self, | |
| int | node_id | ||
| ) |
Query the labels of the given node.
For example, using the Neo4j movie database example, you can query whether a given node represents a person or a movie as follows.
| int stag.neo4j.Neo4jGraph.query_id | ( | self, | |
| str | property_name, | ||
| str | property_value | ||
| ) |
Find the Neo4j ID of a node with the given property.
For example, using the Neo4j movie database example you can find the Neo4j node corresponding to a given movie as follows.
This will make a query to the database to find a node with the given property. This query will be slow unless the database has an index for property_name. For more information, see the Neo4j documentation on creating an index.
| property_name | the node property to query |
| property_value | the value of the node property to search for |
| str stag.neo4j.Neo4jGraph.query_property | ( | self, | |
| int | id, | ||
| str | property_name | ||
| ) |
Find the requested property of a Neo4j node.
For example, using the Neo4j movie database example, you can find the title of a movie node as follows.
| id | the Neo4j node ID to query |
| property_name | the name of the property to query |
| bool stag.neo4j.Neo4jGraph.vertex_exists | ( | self, | |
| int | v | ||
| ) |
Given a vertex ID, returns true or false to indicate whether the vertex exists in the graph.
| v | the vertex index to check |
Reimplemented from stag.graph.LocalGraph.
| stag.neo4j.Neo4jGraph.driver |
The neo4j database driver object used to query the underlying database.