Skip to content

Instantly share code, notes, and snippets.

@baskaufs
Created October 29, 2016 05:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baskaufs/22defe85512e6da525784789ba472ce9 to your computer and use it in GitHub Desktop.
Save baskaufs/22defe85512e6da525784789ba472ce9 to your computer and use it in GitHub Desktop.
import rdflib
# from io import StringIO
# import xml.etree.ElementTree as etree
#builtGraph is where I'm going to accumulate triples that I've scraped
builtGraph=rdflib.Graph()
#addedGraph contains triples that I got from a particular GeoNames RDF file
addedGraph=rdflib.Graph()
with open("all-geonames-rdf.txt", encoding="utf8") as f:
fileIndex=0
while fileIndex<1000:
if fileIndex/10 == int(fileIndex/10):
print(fileIndex)
junk=f.readline()
rdfXmlText=f.readline()
out = open('output.txt', 'w', encoding='utf-8')
out.write(rdfXmlText)
out.close()
result=addedGraph.parse('output.txt')
builtGraph = builtGraph + addedGraph
fileIndex=fileIndex+1
s = builtGraph.serialize(destination='geonames1000.n3', format='n3')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment