Parse large RDF in Python

前端 未结 6 1534
故里飘歌
故里飘歌 2021-02-02 16:07

I\'d like to parse a very large (about 200MB) RDF file in python. Should I be using sax or some other library? I\'d appreciate some very basic code that I can build on, say to r

6条回答
  •  一生所求
    2021-02-02 16:11

    I second the suggestion that you try out rdflib. It's nice and quick prototyping, and the BerkeleyDB backend store scales pretty well into the millions of triples if you don't want to load the whole graph into memory.

    import rdflib
    
    graph = rdflib.Graph("Sleepycat")
    graph.open("store", create=True)
    graph.parse("big.rdf")
    
    # print out all the triples in the graph
    for subject, predicate, object in graph:
        print subject, predicate, object
    

提交回复
热议问题