topologicpy.Neo4j module
- class topologicpy.Neo4j.Neo4j
Bases:
objectNeo4j helper class for TopologicPy.
This implementation keeps the existing static-method style while adding a canonical graph-corpus API compatible with Kuzu.py:
EnsureSchema
ByCSVPath
UpsertGraph
GraphByID
GraphsByQuery
DeleteGraph
EmptyDatabase
ListGraphs
FetchAllPairs
CandidateCountsForLabels
MaxNeighborsForLabel
FindBestExampleForLabel
Canonical storage model:
(:Graph {id, label, num_nodes, num_edges, props}) (:Vertex {id, graph_id, label, x, y, z, props}) (:Vertex)-[:Edge {label, props, graph_id}]->(:Vertex)
Methods
ByCSVPath(manager, path[, graphIDHeader, ...])Reads CSV graph data using TGraph.ByCSVPath where available, falling back to Graph.ByCSVPath, and upserts all returned graphs into Neo4j.
ByGraph(driver, graph[, graphID, ...])Writes the input Topologic graph to Neo4j.
Connect(url, username, password[, database, ...])Returns a Neo4j driver/manager created from the input connection parameters.
EmptyDatabase(manager[, dropSchema, ...])Empties the Neo4j database.
EnsureSchema(manager[, database, silent])Ensures the canonical TopologicPy graph-corpus schema exists in Neo4j.
Execute(driver, cypher[, parameters, write, ...])Executes the input Cypher statement and returns the resulting records.
FindBestExampleForLabel(manager, label[, ...])Returns a representative corpus vertex for the input label.
GraphByID(manager, graphID[, database, ...])Constructs a TopologicPy graph from Neo4j using the canonical graph id.
GraphsByOntologyClass(manager, ontologyClass)Returns graph metadata records whose graph-level ontology_class matches the input value.
GraphsByQuery(manager, query[, parameters, ...])Executes a Cypher query and returns a list of TopologicPy graphs constructed directly from the returned nodes, relationships, and paths.
Manager([url, username, password, database, ...])Returns a Neo4j manager created from the input connection parameters.
MergeGraph(driver, graph[, nodeLabelKey, ...])Compatibility wrapper.
Neighborhood(driver, nodeId[, depth, xMin, ...])Returns the neighborhood of the input Neo4j node as a Topologic graph.
OntologySummary(manager[, database, silent])Returns counts grouped by ontology_class for graphs, vertices, and edges.
ToGraph(driver[, graphID, cypher, ...])Returns a TopologicPy TGraph from Neo4j.
UpsertGraph(manager, graph[, database, ...])Upserts a TopologicPy graph into Neo4j using the canonical schema.
VerticesByOntologyClass(manager, ontologyClass)Returns vertex records whose ontology_class matches the input value.
BatchExecute
CandidateCountsForLabels
Close
CountNodes
CountRelationships
CreateConstraint
CreateIndex
DeleteGraph
DeleteNodes
DeleteRelationships
FetchAllPairs
Info
Labels
ListGraphs
MatchNodes
MaxNeighborsForLabel
Query
RelationshipTypes
Reset
Schema
ToDataFrame
Validate
- static BatchExecute(driver, cypher, data, batchSize=1000, database=None, silent=False)
- static ByCSVPath(manager, path, graphIDHeader='graph_id', graphLabelHeader='label', graphFeaturesHeader='feat', graphFeaturesKeys=None, edgeSRCHeader='src_id', edgeDSTHeader='dst_id', edgeLabelHeader='label', edgeTrainMaskHeader='train_mask', edgeValidateMaskHeader='val_mask', edgeTestMaskHeader='test_mask', edgeFeaturesHeader='feat', edgeFeaturesKeys=None, nodeIDHeader='node_id', nodeLabelHeader='label', nodeTrainMaskHeader='train_mask', nodeValidateMaskHeader='val_mask', nodeTestMaskHeader='test_mask', nodeFeaturesHeader='feat', nodeXHeader='X', nodeYHeader='Y', nodeZHeader='Z', nodeFeaturesKeys=None, tolerance=0.0001, database=None, ontology: bool = True, silent=False)
Reads CSV graph data using TGraph.ByCSVPath where available, falling back to Graph.ByCSVPath, and upserts all returned graphs into Neo4j.
The signature mirrors the TopologicPy CSV graph dataset import signature, with an extra optional database parameter.
- static ByGraph(driver, graph, graphID: str = None, graphIDKey: str = 'graph_id', nodeLabelKey: str = 'label', defaultNodeLabel: str = 'Node', nodeCategoryKey: str = 'category', defaultNodeCategory: str = None, relationshipTypeKey: str = 'label', defaultRelationshipType: str = 'CONNECTED_TO', relationshipCategoryKey: str = 'category', defaultRelationshipCategory: str = None, bidirectional: bool = True, deleteAll: bool = False, createIndex: bool = True, createConstraint: bool = False, mantissa: int = 6, tolerance: float = 0.0001, database: str = None, overwrite: bool = True, ontology: bool = True, asTGraph: bool = True, silent: bool = False)
Writes the input Topologic graph to Neo4j.
Compatibility wrapper: internally uses Neo4j.UpsertGraph with the canonical schema. The input driver is returned on success.
- static CandidateCountsForLabels(manager, labels, excludeLabels=None, limit: int = 50, database=None, silent: bool = False) list
- static Close(driver, silent=False)
- static Connect(url, username, password, database=None, silent=False)
Returns a Neo4j driver/manager created from the input connection parameters.
- Parameters
- urlstr
The URL of the neo4j database
- usernamestr
The neo4j user name
- passwordstr
The neo4j password
- databasestr, optional
The name of the neo4j database
- silentbool , optional
If set to True, error and warning messages are suppressed. Default is False.
- Returns
- Neo4jDriver
The neo4j driver/manager
- static CountNodes(driver, label=None, database=None, silent=False)
- static CountRelationships(driver, relationshipType=None, database=None, silent=False)
- static CreateConstraint(driver, label, property, unique=True, constraintName=None, ifNotExists=True, database=None, silent=False)
- static CreateIndex(driver, label, property, indexName=None, ifNotExists=True, database=None, silent=False)
- static DeleteGraph(manager, graphID: str, database=None, silent: bool = False) bool
- static DeleteNodes(driver, label=None, properties=None, database=None, silent=False)
- static DeleteRelationships(driver, relationshipType=None, database=None, silent=False)
- static EmptyDatabase(manager, dropSchema: bool = False, recreateSchema: bool = True, database=None, silent: bool = False) bool
Empties the Neo4j database. If dropSchema is True, known constraints and indexes are also dropped when possible.
- static EnsureSchema(manager, database=None, silent: bool = False) bool
Ensures the canonical TopologicPy graph-corpus schema exists in Neo4j.
- Parameters
- managerneo4j.Driver
The Neo4j driver.
- databasestr , optional
The database name. Default is None.
- silentbool , optional
If set to True, error and warning messages are suppressed. Default is False.
- Returns
- bool
True if successful, False otherwise.
- static Execute(driver, cypher, parameters=None, write=False, database=None, silent=False)
Executes the input Cypher statement and returns the resulting records.
- static FetchAllPairs(manager, undirected: bool = True, database=None, silent: bool = False) list
- static FindBestExampleForLabel(manager, label: str, attachTo=None, database=None, silent: bool = False) dict
Returns a representative corpus vertex for the input label.
If attachTo is supplied, the method prefers an example adjacent to a vertex whose label equals attachTo. The returned dictionary contains id, graph_id, label, x, y, z, props, attach_label, and frequency where available.
- static GraphByID(manager, graphID: str, database=None, ontology: bool = True, asTGraph: bool = True, silent: bool = False)
Constructs a TopologicPy graph from Neo4j using the canonical graph id.
- static GraphsByOntologyClass(manager, ontologyClass: str, limit: int = 100, database=None, silent: bool = False)
Returns graph metadata records whose graph-level ontology_class matches the input value.
- static GraphsByQuery(manager, query: str, parameters: dict = None, database=None, ontology: bool = True, asTGraph: bool = True, silent: bool = False)
Executes a Cypher query and returns a list of TopologicPy graphs constructed directly from the returned nodes, relationships, and paths.
The method supports query results that return: - Neo4j nodes - Neo4j relationships - Neo4j paths - lists containing nodes, relationships, or paths - dictionaries containing nodes, relationships, or paths
If the query returns only nodes, the result is a graph containing isolated vertices. If the query returns relationships or paths, the corresponding edges are included.
- Parameters
- managerneo4j.Driver
The Neo4j driver.
- querystr
The Cypher query.
- parametersdict , optional
Query parameters. Default is None.
- databasestr , optional
Neo4j database name. Default is None.
- silentbool , optional
If set to True, error and warning messages are suppressed. Default is False.
- Returns
- list
A list containing one TopologicPy graph constructed from the query result, or an empty list if no graph elements are returned.
- static Info(driver, database=None, silent=False)
- static Labels(driver, database=None, silent=False)
- static ListGraphs(manager, where: dict = None, limit: int = 100, offset: int = 0, database=None, silent: bool = False) list
- static Manager(url: str = None, username: str = None, password: str = None, database=None, silent: bool = False)
Returns a Neo4j manager created from the input connection parameters.
- Parameters
- urlstr
The URL of the neo4j database
- usernamestr
The neo4j user name
- passwordstr
The neo4j password
- databasestr, optional
The name of the neo4j database
- silentbool , optional
If set to True, error and warning messages are suppressed. Default is False.
- Returns
- Neo4jDriver
The neo4j driver/manager
- static MatchNodes(driver, label=None, properties=None, database=None, silent=False)
- static MaxNeighborsForLabel(manager, label: str, database=None, silent: bool = False) int
- static MergeGraph(driver, graph, nodeLabelKey='label', defaultNodeLabel='Node', nodeCategoryKey='category', defaultNodeCategory=None, relationshipTypeKey='label', defaultRelationshipType='CONNECTED_TO', relationshipCategoryKey='category', defaultRelationshipCategory=None, bidirectional=True, createIndex=True, createConstraint=False, mantissa=6, tolerance=0.0001, database=None, ontology: bool = True, silent=False)
Compatibility wrapper. Uses canonical UpsertGraph and returns the driver.
- static Neighborhood(driver, nodeId, depth: int = 1, xMin: float = -0.5, yMin: float = -0.5, zMin: float = -0.5, xMax: float = 0.5, yMax: float = 0.5, zMax: float = 0.5, tolerance: float = 0.0001, silent: bool = False)
Returns the neighborhood of the input Neo4j node as a Topologic graph.
- Parameters
- driverneo4j.Driver
The input Neo4j driver.
- nodeIdstr
The Neo4j internal element id of the source node.
- depthint , optional
The neighborhood depth. Default is 1.
- xMinfloat , optional
The minimum random X coordinate to use when a node does not contain an
xproperty. Default is -0.5.- yMinfloat , optional
The minimum random Y coordinate to use when a node does not contain a
yproperty. Default is -0.5.- zMinfloat , optional
The minimum random Z coordinate to use when a node does not contain a
zproperty. Default is -0.5.- xMaxfloat , optional
The maximum random X coordinate to use when a node does not contain an
xproperty. Default is 0.5.- yMaxfloat , optional
The maximum random Y coordinate to use when a node does not contain a
yproperty. Default is 0.5.- zMaxfloat , optional
The maximum random Z coordinate to use when a node does not contain a
zproperty. Default is 0.5.- tolerancefloat , optional
The desired tolerance. Default is 0.0001.
- silentbool , optional
If set to True, error and warning messages are suppressed. Default is False.
- Returns
- topologic_core.Graph
The returned Topologic graph.
- static OntologySummary(manager, database=None, silent: bool = False)
Returns counts grouped by ontology_class for graphs, vertices, and edges.
- static Query(driver, cypher, parameters=None, database=None, silent=False)
- static RelationshipTypes(driver, database=None, silent=False)
- static Reset(driver, database=None, silent=False)
- static Schema(driver, database=None, silent=False)
- static ToDataFrame(driver, cypher, parameters=None, database=None, silent=False)
- static ToGraph(driver, graphID: str = None, cypher: str = None, parameters: dict = None, xMin: float = -0.5, yMin: float = -0.5, zMin: float = -0.5, xMax: float = 0.5, yMax: float = 0.5, zMax: float = 0.5, database: str = None, tolerance: float = 0.0001, ontology: bool = True, asTGraph: bool = True, silent: bool = False)
Returns a TopologicPy TGraph from Neo4j.
If graphID is supplied, the canonical graph with that id is returned. Otherwise, the method imports graph entities returned by the supplied Cypher query, or by a generic whole-database query when cypher is None.
- static UpsertGraph(manager, graph, database: str = None, graphIDKey: str = 'graph_id', vertexIDKey: str = 'id', vertexLabelKey: str = 'label', defaultVertexLabel: str = 'Node', vertexCategoryKey: str = 'category', defaultVertexCategory: str = 'Node', edgeLabelKey: str = 'label', defaultEdgeLabel: str = 'CONNECTED_TO', edgeCategoryKey: str = 'category', defaultEdgeCategory: str = 'Edge', bidirectional: bool = True, overwrite: bool = False, mantissa: int = 6, ontology: bool = True, silent: bool = False) str
Upserts a TopologicPy graph into Neo4j using the canonical schema.
- Parameters
- manager
The graph database manager/driver.
- graphtopologic_core.Graph
The input TopologicPy graph.
- databasestr , optional
The Neo4j database name. Default is None.
- graphIDKeystr , optional
The graph dictionary key under which the graph id is stored. Default is “graph_id”.
- vertexIDKeystr , optional
The vertex dictionary key under which the vertex id is stored. Default is “id”.
- vertexLabelKeystr , optional
The vertex dictionary key under which the vertex label is stored. Default is “label”.
- defaultVertexLabelstr , optional
The default vertex label if no vertex label is found. Default is “Node”.
- vertexCategoryKeystr , optional
The vertex dictionary key used for category metadata. Default is “category”.
- defaultVertexCategoryany , optional
The default vertex category if none is found. Default is “Node”.
- edgeLabelKeystr , optional
The edge dictionary key under which the edge label/type is stored. Default is “label”.
- defaultEdgeLabelstr , optional
The default edge label if no edge label is found. Default is “CONNECTED_TO”.
- edgeCategoryKeystr , optional
The edge dictionary key used for category metadata. Default is “category”.
- defaultEdgeCategoryany , optional
The default edge category if none is found. Default is “Edge”.
- bidirectionalbool , optional
If set to True, reverse edges are also written. Default is True.
- overwritebool , optional
If set to True, an existing graph with the same id is deleted before import. Default is False.
- mantissaint , optional
The number of decimal places to use when extracting mesh data. Default is 6.
- ontologybool , optional
If True, the graph, vertices, and edges are annotated with canonical TopologicPy ontology keys before being written to Neo4j. Default is True.
- silentbool , optional
If set to True, error and warning messages are suppressed. Default is False.
- Returns
- str
The graph id used, or None on error.
- static Validate(driver, idKey='topologic_id', database=None, silent=False)
- static VerticesByOntologyClass(manager, ontologyClass: str, graphID: str = None, limit: int = 100, database=None, silent: bool = False)
Returns vertex records whose ontology_class matches the input value.