I have a large RDF dataset (Geonames dataset: 18GB) in NT format. I would like to load it into a PostgreSQL relational table by using rdflib_sqlalchemy.SQLAlchemy
. I know that it is doable (performing sparql query on the rdf data stored in relational database). However, I am not sure how. Could you please provide me an example?
My next goal is to write an SPARQL query from python by using RDFLib. I know how to do it. Thanks in advance for your help.
Install these Python libraries:
Run the following Python code:
'demo.nt' is the N-Triples file to import. I used this for testing:
After being imported successfully, your database contains five tables (e.g., kb_[some_id]_asserted_statements) populated with the triples. The console has printed ten triples at most.
Tested on Windows 10, PostgreSQL 10.5, Python 3.5.4 (all 64bit) with rdflib-4.2.2, rdflib-sqlalchemy-0.3.8, and psycopg2-2.7.5.