src.dackar.knowledge_graph.py2neo¶
Created on March, 2025
@author: wangc, mandd
Classes¶
Module Contents¶
- class src.dackar.knowledge_graph.py2neo.Py2Neo(uri, user, pwd)[source]¶
-
- create_node(label, properties)[source]¶
Create a new graph node
- Parameters:
label (str) – node label will be used by neo4j
properties (dict) – node attributes
- static _create_node(tx, label, properties)[source]¶
Create a new graph node
- Parameters:
tx (obj) – python neo4j active session that can be used to execute queries
label (str) – node label will be used by neo4j
properties (dict) – node attributes
- create_relation(l1, p1, l2, p2, lr, pr=None)[source]¶
create graph relation
- Parameters:
l1 (str) – first node label
p1 (dict) – first node attributes
l2 (str) – second node label
p2 (dict) – second node attributes
lr (str) – relationship label
pr (dict, optional) – attributes for relationship. Defaults to None.
- static _create_relation(tx, l1, p1, l2, p2, lr, pr)[source]¶
create graph relation
- Parameters:
tx (obj) – python neo4j active session that can be used to execute queries
l1 (str) – first node label
p1 (dict) – first node attributes
l2 (str) – second node label
p2 (dict) – second node attributes
lr (str) – relationship label
pr (dict, optional) – attributes for relationship. Defaults to None.
- find_nodes(label, properties=None)[source]¶
Find the node in neo4j graph database
- Parameters:
label (str) – node label
properties (dict, optional) – node attributes. Defaults to None.
- Returns:
list of nodes
- Return type:
list
- static _find_nodes(tx, label, properties)[source]¶
Find the node in neo4j graph database
- Parameters:
tx (obj) – python neo4j active session that can be used to execute queries
label (str) – node label
properties (dict, optional) – node attributes. Defaults to None.
- Returns:
list of nodes
- Return type:
list
- load_csv_for_nodes(file_path, label, attribute)[source]¶
Load CSV file to create nodes
- Parameters:
file_path (str) – file path for CSV file, location is relative to ‘dbms.directories.import’ or ‘server.directories.import’ in neo4j.conf file
label (str) – node label
attribute (dict) – node attribute from the CSV column names
- load_csv_for_relations(file_path, l1, p1, l2, p2, lr, pr=None)[source]¶
Load CSV file to create node relations
- Parameters:
file_path (str) – file path for CSV file, location is relative to ‘dbms.directories.import’ or ‘server.directories.import’ in neo4j.conf file
l1 (str) – first node label
p1 (dict) – first node attribute from the CSV column names
l2 (str) – second node label
p2 (dict) – second node attribute from the CSV column names
lr (str) – relationship label
pr (dict, optional) – of attributes for relation. Defaults to None.
- query(query, parameters=None, db=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 list of queried results.
- Return type:
list