Created
May 30, 2021 14:53
-
-
Save asanchez75/ed152515451b6cb34f6ba3e816eca471 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from SPARQLWrapper import SPARQLWrapper, POST, BASIC, DIGEST, TURTLE, N3, XML, RDFXML | |
from rdflib import Graph | |
sparql = SPARQLWrapper("http://localhost:7200/repositories/myrepo") | |
sparql.setHTTPAuth(BASIC) | |
sparql.setCredentials("admin", "admin") | |
sparql.setMethod(POST) | |
sparql.setQuery(""" | |
construct {?s ?p ?o} | |
where { | |
?s ?p ?o. | |
} | |
limit 1000 | |
""") | |
sparql.setReturnFormat(TURTLE) | |
results = sparql.query().convert() | |
g = Graph() | |
g.parse(data=results, format="turtle") | |
file = open("output.n3", "wb") | |
print(g.serialize(destination=file, format='turtle')) | |
file.flush() | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment