trovares_connector.Neo4jConnector#

class trovares_connector.Neo4jConnector(xgt_server, neo4j_driver, verbose=False, enable_apoc=True)[source]#
__init__(xgt_server, neo4j_driver, verbose=False, enable_apoc=True)[source]#

Initializes the connector class.

Parameters:
  • xgt_server (xgt.Connection) – Connection object to xGT.

  • neo4j_driver (neo4j.Neo4jDriver, neo4j.BoltDriver, tuple(neo4j.Neo4jDriver, database), tuple(neo4j.BoltDriver, database), or trovares_connector.Neo4jDriver) – Connection object to Neo4j.

  • verbose (bool) – Print detailed information during calls.

  • enable_apoc (bool) – If the connector finds APOC, it will use that to improve schema queries. If set to True this enables that feature. By default this is True.

Methods

__init__(xgt_server, neo4j_driver[, ...])

Initializes the connector class.

copy_data_to_xgt(xgt_schemas)

Copies data from Neo4j to the requested vertex and/or edge frames in Trovares xGT.

create_xgt_schemas(xgt_schemas[, append, force])

Creates vertex and/or edge frames in Trovares xGT.

get_xgt_schemas([vertices, edges, ...])

Retrieve a dictionary containing the schema information for all of the nodes/vertices and all of the edges requested.

transfer_to_neo4j([vertices, edges, ...])

Copies data from Trovares xGT to Neo4j.

transfer_to_xgt([vertices, edges, ...])

Copies data from Neo4j to Trovares xGT.

translate_query(query)

Translate a Cypher query to be ready to run in Trovares xGT.

Attributes

neo4j_driver

Retrieve the Neo4j driver used to connect to the neo4j database.

neo4j_edges

Retrieve a dictionary of the edges (relationships) mapped to a description of the edge's metadata, including its property schema and its endpoint node labels (for both source and target).

neo4j_node_labels

Retrieve a list of the Neo4j node labels.

neo4j_node_type_properties

Retrieve a list of the property types attached to the nodes in Neo4j.

neo4j_nodes

Retrieve a dictionary of the node labels (types) mapped to a description of the node's schema.

neo4j_property_keys

Retrieve a list of the Neo4j property keys.

neo4j_rel_type_properties

Retrieve a list of the property types attached to the relationships in Neo4j.

neo4j_relationship_types

Retrieve a list of the Neo4j relationship types.

xgt_server

Retrieve the Trovares driver used to connect to the xGT server.

__init__(xgt_server, neo4j_driver, verbose=False, enable_apoc=True)[source]#

Initializes the connector class.

Parameters:
  • xgt_server (xgt.Connection) – Connection object to xGT.

  • neo4j_driver (neo4j.Neo4jDriver, neo4j.BoltDriver, tuple(neo4j.Neo4jDriver, database), tuple(neo4j.BoltDriver, database), or trovares_connector.Neo4jDriver) – Connection object to Neo4j.

  • verbose (bool) – Print detailed information during calls.

  • enable_apoc (bool) – If the connector finds APOC, it will use that to improve schema queries. If set to True this enables that feature. By default this is True.

copy_data_to_xgt(xgt_schemas) None[source]#

Copies data from Neo4j to the requested vertex and/or edge frames in Trovares xGT.

This function copies data from Neo4j to xGT for all of the nodes and all of the relationships, one frame at a time.

Parameters:

xgt_schemas (dict) – Dictionary containing schema information for vertex and edge frames to create in xGT. This dictionary can be the value returned from the get_xgt_schemas() method.

Return type:

None

create_xgt_schemas(xgt_schemas, append=False, force=False) None[source]#

Creates vertex and/or edge frames in Trovares xGT.

This function first infers the schemas for all of the needed frames in xGT to store the requested data. Then those frames are created in xGT.

Parameters:
  • xgt_schemas (dict) – Dictionary containing schema information for vertex and edge frames to create in xGT. This dictionary can be the value returned from the get_xgt_schemas() method.

  • append (boolean) – Set to true when the xGT frames are already created and holding data that should be appended to. Set to false when the xGT frames are to be newly created (removing any existing frames with the same names prior to creation).

  • force (boolean) – Set to true to force xGT to drop edges when a vertex frame has dependencies.

Return type:

None

get_xgt_schemas(vertices=None, edges=None, neo4j_id_name='neo4j_id', neo4j_source_node_name='neo4j_source', neo4j_target_node_name='neo4j_target', import_edge_nodes=True) {}[source]#

Retrieve a dictionary containing the schema information for all of the nodes/vertices and all of the edges requested. If both vertices and edges is None, it will retrieve them all.

Parameters:
  • vertices (iterable) – List of requested node labels (vertex frame names) as a string or tuple. To map to a specific from a Neo4j label to a xGT frame use a tuple like so: (‘neo4j_name’, ‘xgt_name’).

  • edges (iterable) – List of requested relationship type (edge frame) names or tuple. To map to a specific from a Neo4j type to a xGT frame use a tuple like so: (‘neo4j_name’, ‘xgt_name’). Any vertices not given for an edge will be automatically requested unless disabled.

  • neo4j_id_name (str) – The name of the xGT column holding the Neo4j node’s ID value.

  • neo4j_source_node_name (str) – The name of the xGT column holding the source node’s ID value.

  • neo4j_source_node_name – The name of the xGT column holding the target node’s ID value.

  • import_edge_nodes (boolean) – Add vertices from edge if not explicitly listed. By default True.

Returns:

Dictionary containing the schema information of all the nodes/ vertices and all of the edges requested.

Return type:

dict

property neo4j_driver#

Retrieve the Neo4j driver used to connect to the neo4j database.

property neo4j_edges: {}#

Retrieve a dictionary of the edges (relationships) mapped to a description of the edge’s metadata, including its property schema and its endpoint node labels (for both source and target).

Returns:

Dictionary mapping the edge names to a description of the edge’s schema and edge endpoints.

Return type:

dict

property neo4j_node_labels: []#

Retrieve a list of the Neo4j node labels.

Returns:

List of the string names of node labels in the connected Neo4j.

Return type:

list

property neo4j_node_type_properties: []#

Retrieve a list of the property types attached to the nodes in Neo4j.

Each element of this list is a dictionary describing the property, including its name, its possible data types, and which node labels it may be attached to.

Returns:

List of the string names of node property types in the connected Neo4j.

Return type:

list

property neo4j_nodes: {}#

Retrieve a dictionary of the node labels (types) mapped to a description of the node’s schema.

Each dictionary entry has a key, which is the node label, and a value that is a dictionary of property-names mapped to property-types.

Returns:

Dictionary mapping the node labels to a description of the node’s schema.

Return type:

dict

property neo4j_property_keys: []#

Retrieve a list of the Neo4j property keys.

Returns:

List of the string names of property keys in the connected Neo4j.

Return type:

list

property neo4j_rel_type_properties: []#

Retrieve a list of the property types attached to the relationships in Neo4j.

Each element of this list is a dictionary describing the property, including its name, its possible data types, and which relationship(s) it may be attached to.

Returns:

List of the string names of relationship property types in the connected Neo4j.

Return type:

list

property neo4j_relationship_types: []#

Retrieve a list of the Neo4j relationship types.

Returns:

List of the string names of relationship types in the connected Neo4j.

Return type:

list

transfer_to_neo4j(vertices=None, edges=None, namespace=None, edge_keys=False, vertex_keys=False)[source]#

Copies data from Trovares xGT to Neo4j.

All of the nodes and all of the relationships are copied, one frame at a time, from xGT to Neo4j. If both vertices and edges is None, it will retrieve them all.

Parameters:
  • vertices (iterable) – List of requested node labels (vertex frame names).

  • edges (iterable) – List of requested relationship type (edge frame) names. Any vertices not given for an edge will be automatically requested.

  • namespace (str) – Namespace for the selected frames. If none will use the default namespace.

  • edge_keys (boolean) – If true will transfer edge key columns.

  • vertex_keys (boolean) – If true will transfer vertex key columns.

Return type:

None

transfer_to_xgt(vertices=None, edges=None, neo4j_id_name='neo4j_id', neo4j_source_node_name='neo4j_source', neo4j_target_node_name='neo4j_target', append=False, force=False, import_edge_nodes=True) None[source]#

Copies data from Neo4j to Trovares xGT.

This function first infers the schemas for all of the needed frames in xGT to store the requested data. Then those frames are created in xGT. Finally, all of the nodes and all of the relationships are copied, one frame at a time, from Neo4j to xGT. If both vertices and edges is None, it will retrieve them all.

Parameters:
  • vertices (iterable) – List of requested node labels (vertex frame names) as a string or tuple. To map to a specific from a Neo4j label to a xGT frame use a tuple like so: (‘neo4j_name’, ‘xgt_name’).

  • edges (iterable) – List of requested relationship type (edge frame) names or tuple. To map to a specific from a Neo4j type to a xGT frame use a tuple like so: (‘neo4j_name’, ‘xgt_name’). Any vertices not given for an edge will be automatically requested unless disabled.

  • neo4j_id_name (str) – The name of the xGT column holding the Neo4j node’s ID value.

  • neo4j_source_node_name (str) – The name of the xGT column holding the source node’s ID value.

  • neo4j_source_node_name – The name of the xGT column holding the target node’s ID value.

  • append (boolean) – Set to true when the xGT frames are already created and holding data that should be appended to. Set to false when the xGT frames are to be newly created (removing any existing frames with the same names prior to creation).

  • force (boolean) – Set to true to force xGT to drop edges when a vertex frame has dependencies.

  • import_edge_nodes (boolean) – Add vertices from edge if not explicitly listed. By default True.

Return type:

None

translate_query(query: str) str[source]#

Translate a Cypher query to be ready to run in Trovares xGT.

It is sometimes necessary to make alterations to naming of graph components as part of the automatic graph schema creation from a Neo4j database to hold data in a Trovares xGT server. One example of this is when a relationship type consists of some edges from one source node label and other edges from a different source node label.

Given a Cypher query that formulated to run against a Neo4j database, there may be some changes required in order to run that same query against a Trovares xGT server holding a graph schema that has been auto-generated.

Parameters:

query (str) – A Cypher query that can be run against the Neo4j database that is part of this connector instance.

Returns:

Translated Cypher query.

Return type:

str

property xgt_server#

Retrieve the Trovares driver used to connect to the xGT server.