Skip to content

Instantly share code, notes, and snippets.

View rnnrght's full-sized avatar

Aaron Enright rnnrght

View GitHub Profile
@baskaufs
baskaufs / convert2ntriples.py
Created October 29, 2016 05:22
Convert stupid GeoNames RDF dump format into Ntriples
# script from https://github.com/rhasan/sw/blob/master/genames/convert2ntriples.py
# with some hacks to make it work for Python 3
# This script will take genames rdf dump available here http://download.geonames.org/all-geonames-rdf.zip
# and convert each triples to N-Triple seralization.
# The dump has one rdf document per toponym on every line of the file.
# The produced N-Triples will be written in geonames.nt file. The final geonames.nt file is approximately 13.21GB
#!/usr/bin/python
import rdflib
fo = open("geonames.nt", "wb")
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()