Skip to main content

gqlalchemy.transformations.translators.pyg_translator

PyGTranslator Objects

class PyGTranslator(Translator)

get_node_properties

@classmethod
def get_node_properties(cls, graph, node_label: str, node_id: int)

Extracts node properties from heterogeneous graph based on the node_label.

Arguments:

  • graph - A reference to the PyG graph.
  • node_label - Node label
  • node_id - Node_id

extract_node_edge_properties_from_homogeneous_graph

@classmethod
def extract_node_edge_properties_from_homogeneous_graph(cls, graph)

Homogenous graph don't have node and etype properties so it is hard to extract node and edge attributes.

Arguments:

  • graph - Data = reference to the PyG graph.

Returns:

node and edge attributes as dictionaries

to_cypher_queries

def to_cypher_queries(graph)

Produce cypher queries for data saved as part of thePyG graph. The method handles both homogeneous and heterogeneous graph. The method converts 1D as well as multidimensional features. If there are some isolated nodes inside the graph, they won't get transferred. Nodes and edges created in Memgraph DB will, for the consistency reasons, have property pyg_id set to the id they have as part of the PyG graph. Note that this method doesn't insert anything inside the database, it just creates cypher queries. To insert queries the following code can be used: >>> memgraph = Memgraph() pyg_graph = HeteroData(...) for query in PyGTranslator().to_cypher_queries(pyg_graph): memgraph.execute(query)

Arguments:

  • graph - A reference to the PyG graph.

Returns:

cypher queries.

get_instance

def get_instance()

Create instance of PyG graph from all edges that are inside Memgraph. Currently, isolated nodes are ignored because they don't contribute in message passing neural networks. Only numerical features that are set on all nodes or all edges are transferred to the PyG instance since this is PyG's requirement. That means thay any string values properties won't be transferred, as well as numerical properties that aren't set on all nodes. However, features thata re of type list are transferred to the PyG instance and can be used as any other feature in the PyG graph. Regardless of data residing inside Memgraph database, the created PyG graph is a heterograph instance.

Returns:

PyG heterograph instance.