'Neo4j - Project graph from Neo4j with GraphDataScience

So I have a graph of nodes -- "Papers" and relationships -- "Citations". Nodes have properties: "x", a list with 0/1 entries corresponding to whether a word is present in the paper or not, and "y" an integer label (one of the classes from 0-6).

I want to project the graph from Neo4j using GraphDataScience. I've been using this documentation and I indeed managed to project the nodes and vertices of the graph:

Code

from graphdatascience import GraphDataScience

AURA_CONNECTION_URI = "neo4j+s://xxxx.databases.neo4j.io"
AURA_USERNAME = "neo4j"
AURA_PASSWORD = "my_code:)"

# Client instantiation
gds = GraphDataScience(
    AURA_CONNECTION_URI,
    auth=(AURA_USERNAME, AURA_PASSWORD),
    aura_ds=True
)

#Shorthand projection --works
shorthand_graph, result = gds.graph.project(
    "short-example-graph",
    ["Paper"],
    ["Citation"]
)

When I do print(result) it shows

nodeProjection {'Paper': {'label': 'Paper', 'properties': {}}} relationshipProjection {'Citation': {'orientation': 'NATURAL', 'aggre... graphName short-example-graph nodeCount 2708 relationshipCount 10556 projectMillis 34 Name: 0, dtype: object

However, no properties of the nodes are projected. I then use the extended syntax as described in the documentation:

# Project a graph using the extended syntax
extended_form_graph, result = gds.graph.project(
    "Long-form-example-graph",
    {'Paper': {properties: "x"}},
    "Citation"
)

print(result)

#Errors I get the error: NameError: name 'properties' is not defined

I tried various variations of this, with or without " ", but none have worked so far (also documentation is very confusing because one of the docs always uses " " and in another place I did not see " ").

Also, note that all my properties are integers in the Neo4j db (in AuraDS), as I used to have the error that String properties are not supported.

Some clarification on the correct way of projecting node features (aka properties) would be very useful.

thank you, Dina



Solution 1:[1]

The keys in the Python dictionaries that you use with the GraphDataScience library should be enclosed in quotation marks. This is different from Cypher syntax, where map keys are not enclosed with quotation marks.

This should work for you.

extended_form_graph, result = gds.graph.project(
    "Long-form-example-graph",
    {'Paper': {"properties": "x"}},
    "Citation"
)

Best wishes,

Nathan

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nathan Smith