Graph databases and RDF triplestores: storage of graph data in python

后端 未结 7 1491
青春惊慌失措
青春惊慌失措 2021-01-30 18:38

I need to develop a graph database in python (I would enjoy if anybody can join me in the development. I already have a bit of code, but I would gladly discuss about it).

<
7条回答
  •  醉梦人生
    2021-01-30 19:14

    RDFLib is a python library that you can use. Using harschware's example:

    Create a test.nt file like below:

       .
       .
    

    To query for all nodes two hops from node 1 in RDFLib:

        from rdflib import Graph
    
        g = Graph()
        g.parse("test.nt", format="nt")
    
        qres = g.query(
            """SELECT ?node
            WHERE {
                 ?p1 ?o1 .
                ?o1 ?p2 ?node .
            }"""
        )
    
        for row in qres:
            print(node)
    

    Should return the answer .

提交回复
热议问题