Created
October 29, 2016 05:02
-
-
Save baskaufs/22defe85512e6da525784789ba472ce9 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
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