Create a gist now

Instantly share code, notes, and snippets.

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