neo4j package¶
Reference page for the bluegraph.backends.neo4j package. All the interfaces below are also available as bluegraph.backends.neo4j.<interface> (for example, from bluegraph.backends.neo4j import Neo4jPathFinder
).
Graph metrics¶
- class bluegraph.backends.neo4j.analyse.metrics.Neo4jMetricProcessor(pgframe=None, directed=True, uri=None, username=None, password=None, driver=None, node_label=None, edge_label=None)¶
Class for metric processing based on Neso4j graphs.
- betweenness_centrality(distance=None, write=False, write_property=None)¶
Compute (weighted) betweenness centrality.
- closeness_centrality(distance=None, write=False, write_property=None)¶
Compute (weighted) closeness centrality.
- degree_centrality(weight=None, write=False, write_property=None)¶
Compute (weighted) degree centrality.
- pagerank_centrality(weight=None, write=False, write_property=None)¶
Compute (weighted) PageRank centrality.
Path search¶
- class bluegraph.backends.neo4j.analyse.paths.Neo4jPathFinder(pgframe=None, directed=True, uri=None, username=None, password=None, driver=None, node_label=None, edge_label=None)¶
Neo4j-based shortest paths finder.
- all_shortest_paths(source, target, exclude_edge=False, max_length=4)¶
Compute all shortest paths from the source to the target.
This function computes all the shortest (unweighted) paths from the source to the target.
- Parameters:
source (str) – Source node ID
target (str) – Target node ID
exclude_edge (bool, optional) – Flag indicating whether the direct edge from the source to the target should be excluded from the result (if exists).
max_length (int, optional) – Maximum allowed path length (the larger the value, the slower is the performance)
- get_distance(source, target, distance)¶
Get distance value between source and target.
- get_subgraph_from_paths(paths)¶
Get a subgraph given the input paths.
- minimum_spanning_tree(distance, write=False, write_edge_label=None, start_node=None)¶
Compute the minimum spanning tree.
- Parameters:
distance (str) – Distance to minimize when computing the minimum spanning tree (MST)
write (bool, optional) – Flag indicating whether the MST should be returned as a new graph object or saved within a Boolean edge property being True whenever a given edge belongs to the MST.
write_edge_label (str, optional) – Edge label for creating edges beloning to the MST.
- Returns:
tree – The minimum spanning tree graph object (backend-dependent)
- Return type:
graph object
- n_shortest_paths(source, target, n, distance=None, strategy='naive', exclude_edge=False)¶
Compute n shortest paths from the source to the target.
Two search strategies are available: ‘naive’ and ‘yen’. The naive strategy first finds the set of all shortest paths from the source to the target node, it then ranks them by the cumulative distance score and returns n best paths. The second strategy uses Yen’s algorithm [1] for finding n shortest paths. The first naive strategy performs better for highly dense graphs (where every node is connected to almost every other node). Note that if there are less than n unweighted shortest paths in the graph, the naive strategy may return less than n paths.
1. Yen, Jin Y. “Finding the k shortest loopless paths in a network”. Management Science 17.11 (1971): 712-716.
- Parameters:
source (str) – Source node ID
target (str) – Target node ID
n (int) – Number of top paths to include in the result
distance (str, optional) – The name of the attribute to use as the edge distance
path_condition (func, optional) – Edge filtering function returning Boolean flag
strategy (str, optional) – Path finding strategy: naive or yen. By default, naive.
exclude_edge (bool, optional) – Flag indicating whether the direct edge from the source to the target should be excluded from the result (if exists).
- Returns:
paths – List containing top n best paths according to the distance score
- Return type:
list
- shortest_path(source, target, distance=None, exclude_edge=False)¶
Compute the single shortest path from the source to the target.
- Parameters:
source (str) – Source node ID
target (str) – Target node ID
exclude_edge (bool, optional) – Flag indicating whether the direct edge from the source to the target should be excluded from the result (if exists).
- top_neighbors(node, n, weight, smallest=False)¶
Get top n neighbours of the specified node by weight.
Community Detection¶
- class bluegraph.backends.neo4j.analyse.communities.Neo4jCommunityDetector(pgframe=None, directed=True, uri=None, username=None, password=None, driver=None, node_label=None, edge_label=None)¶
Neo4j-based community detection interface.
Currently supported community detection strategies for Neo4j:
Louvain algorithm (strategy=”louvain”)
Girvan–Newman algorithm (strategy=”girvan-newman”)
Label propagation (strategy=”lpa”)
Hierarchical clustering (strategy=”hierarchical”)
References
https://neo4j.com/docs/graph-data-science/current/algorithms/community/
- detect_communities(strategy='louvain', weight=None, n_communities=2, intermediate=False, write=False, write_property=None, **kwargs)¶
Detect community partition using the input strategy.
Node embedding¶
- class bluegraph.backends.neo4j.embed.embedders.Neo4jNodeEmbedder(model_name, directed=True, include_type=False, feature_props=None, feature_vector_prop=None, edge_weight=None, **model_params)¶
- fit_model(pgframe=None, uri=None, username=None, password=None, driver=None, node_label=None, edge_label=None, graph_view=None, write=False, write_property=False)¶
Train specified model on the provided graph.
- predict_embeddings(pgframe=None, uri=None, username=None, password=None, driver=None, node_label=None, edge_label=None, graph_view=None, write=False, write_property=False)¶
Predict embeddings of out-sample elements.