src.dackar.knowledge_graph.pygds¶
Created on March 20, 2025
@author: wangc, mandd
Attributes¶
Classes¶
Module Contents¶
- class src.dackar.knowledge_graph.pygds.PyGDS(uri, user, pwd, database='neo4j')[source]¶
-
- query(query, params=None, database=None)[source]¶
User provided Cypher query statements for python neo4j driver to use to query database
- Parameters:
query (str) – user provided Cypher query statements
parameters (dict, optional) – dictionary that provide key/value pairs for query statement to use. Defaults to None.
db (str, optional) – name for database. Defaults to None.
- Returns:
returned queried results.
- Return type:
DataFrame
- project(graph_name, node_spec, relationship_spec)[source]¶
Creates a named graph in the catalog for use by algorithms
- Parameters:
graph_name (str) – graph name
node_spec (str or dict) – Node project, dict option ({nodeLabel: {‘properties’:[properties]}})
relationship_spec (str or dict) – Relationship projection, dict option ({relationLabel: {‘properties’:[properties]}})
- Returns:
GDS graph object result (pandas.Series): containing metadata from underlying procedure call.
- Return type:
graph (Graph object)
- load_dataframe(graph_name, nodes, relationships, write=False)[source]¶
Constructing a graph from pandas.DataFrames
- Parameters:
graph_name (str) – Name of the graph to be constructed
nodes (pandas.DataFrame) – one or more dataframes containing node data
relationships (pandas.DataFrame) – one or more dataframes containing relationship data
- Returns:
GDS graph object
- Return type:
graph (Graph object)
Examples
- nodes = pandas.DataFrame(
- {
“nodeId”: [0, 1, 2, 3], “labels”: [“A”, “B”, “C”, “A”], “prop1”: [42, 1337, 8, 0], “otherProperty”: [0.1, 0.2, 0.3, 0.4]
}
)
- relationships = pandas.DataFrame(
- {
“sourceNodeId”: [0, 1, 2, 3], “targetNodeId”: [1, 2, 3, 0], “relationshipType”: [“REL”, “REL”, “REL”, “REL”], “weight”: [0.0, 0.0, 0.1, 42.0]
}
)
- centrality(method='eigenvector', check=False)[source]¶
Centrality algorithms are used to understand the role or influence of particular nodes in a graph
- Parameters:
method (str, optional) – centrality algorithm. Defaults to ‘eigenvector’.
connections ('Degree centrality' measures the number of)
network. (to other nodes in the)
intermediary ('Betweenness centrality' quantifies the importance of a node as a bridge or)
nodes (in the network. It measures how often a node lies on the shortest path between other pairs of)
connections
check (bool, optional) – print graph information if True