wassimj / topologicpy

The python bindings for topologic
Other
95 stars 27 forks source link

Attribute error in the keys = Dictionary.Keyus(vDict) when storing topologicpy graph to neo4j graph #69

Closed Howie-Arup closed 2 months ago

Howie-Arup commented 2 months ago

Hi, I am trying to store the topologicpy graph to neo4j. The codes are as below.

from topologicpy.Topology import Topology
from topologicpy.Graph import Graph
from topologicpy import Neo4j

IFC_file_path = "Cubes.ifc"
graph_topo = Graph.ByIFCPath(IFC_file_path)
graph_neo4j = Neo4j.Neo4j.ByParameters(url=url, username=username, password=password)
topo_neo4j = Neo4j.Neo4j.AddGraph(neo4jGraph=graph_neo4j, graph=graph_topo)

The error is as below.

{
    "name": "AttributeError",
    "message": "type object 'Dictionary' has no attribute 'Keyus'",
    "stack": "---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[34], line 4
      1 # Create an instance of the Neo4j graph
      2 graph_neo4j = Neo4j.Neo4j.ByParameters(url=url, username=username, password=password)
----> 4 topo_neo4j = Neo4j.Neo4j.AddGraph(neo4jGraph=graph_neo4j, graph=graph_topo)

File c:\\Users\\Howie.Liu\\AppData\\Local\\miniforge3\\envs\\graphrag\\lib\\site-packages\\topologicpy\\Neo4j.py:317, in Neo4j.AddGraph(neo4jGraph, graph, labelKey, relationshipKey, mantissa, tolerance)
    315 for  i in range(len(vertices)):
    316     vDict = Topology.Dictionary(vertices[i])
--> 317     keys = Dictionary.Keyus(vDict)
    318     values = Dictionary.Values(vDict)
    319     keys.append(\"x\")

AttributeError: type object 'Dictionary' has no attribute 'Keyus'"
}

It seems that there is a typo in the keys = Dictionary.Keyus(vDict)?

wassimj commented 2 months ago

Yes. Apologies. Definitely a typo. If you are in a hurry for this to be fixed, find the folder where topologicpy is installed and go into the Neo4j py file, find that line and change it to .Keys. Then restart your process and test again. This will be fixed in the next release

Howie-Arup commented 2 months ago

Thank you for your reply @wassimj . I have modified it in the Neo4j py file. But I got another error when exporting the topologicpy graph to neo4j graph.

I used the codes below:

from topologicpy.Topology import Topology
from topologicpy.Graph import Graph
from topologicpy import Neo4j

IFC_file_path = "sample.ifc"
graph_topo = Graph.ByIFCPath(IFC_file_path)

username="..."
password="..."
url="..."

graph_neo4j = Neo4j.Neo4j.ByParameters(url=url, username=username, password=password)
topo_neo4j = Neo4j.Neo4j.AddGraph(neo4jGraph=graph_neo4j, graph=graph_topo, labelKey='None', relationshipKey='None')

But it seems that there is something wrong with the graph object to execute the Cypher:

  ---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[5], line 4
      1 # Create an instance of the Neo4j graph
      2 graph_neo4j = Neo4j.Neo4j.ByParameters(url=url, username=username, password=password)
----> 4 topo_neo4j = Neo4j.Neo4j.AddGraph(neo4jGraph=graph_neo4j, graph=graph_topo, labelKey='None', relationshipKey='None')

File c:\Users\Howie.Liu\AppData\Local\miniforge3\envs\graphrag\lib\site-packages\topologicpy\Neo4j.py:336, in Neo4j.AddGraph(neo4jGraph, graph, labelKey, relationshipKey, mantissa, tolerance)
    334     nodeName = str(values[keys.index(labelKey)])
    335 n = py2neo.Node(nodeName, **pydict)
--> 336 neo4jGraph.cypher.execute("CREATE INDEX FOR (n:%s) on (n.name)" %
    337         n.nodelabel)
    338 tx.create(n)
    339 nodes.append(n)

AttributeError: 'Graph' object has no attribute 'cypher'

I wonder where is the problem in the library or I misused it?

wassimj commented 2 months ago

@Howie-Arup I just published a new version of topologicpy (v0.7.56). n this version, the Neo4j class has been re-written using the native neo4j driver. The reason for that is that py2neo, which topologic used previously, has been declared EOL. The new API is much simpler, but allows you to convert between topologic and neo4j graphs easily. When you include a cypher string, sub-graphs can be retrieved from the graph database. A Project Jupyter notebook has also been included for you to test. neo4j_screenshot topologic_graphs

Howie-Arup commented 2 months ago

@Howie-Arup I just published a new version of topologicpy (v0.7.56). n this version, the Neo4j class has been re-written using the native neo4j driver. The reason for that is that py2neo, which topologic used previously, has been declared EOL. The new API is much simpler, but allows you to convert between topologic and neo4j graphs easily. When you include a cypher string, sub-graphs can be retrieved from the graph database. A Project Jupyter notebook has also been included for you to test. neo4j_screenshot topologic_graphs topologic_graphs

@wassimj Fantastic! Many thanks!