def main(): inFileTube = 'DATA/tram_validated.csv' outFileTube = "DATA/tram_dirty" + ".ttl" csvTubeS = readCsv(inFileTube) next(csvTubeS, None) tubeS_store = plugin.get('IOMemory', Store)() tubeS_g = Graph(tubeS_store) prefixes = definePrefixes() print('Binding Prefixes') bindingPrefixes(tubeS_g, prefixes) #bindingPrefixes(tubeT_graph,prefixes) print('Creating graph-TubeS...') flag = 1 for row in csvTubeS: lstData = getTubeSData(row) createTubeSGraph(lstData, tubeS_g) createTubeSGraph(lstData, tubeS_g).serialize(outFileTube, format='turtle') print('DONE!')
def main(): #url="https://api.tfl.gov.uk/BikePoint?app_id=5ee709d5&app_key=1739d498d997e956a2b80c62a8948ff0" #url for bike api #apiJsonCsv(url) #json to csv conversion inputCsv = "DATA/tfl_bikes_validated.csv" outFile = "DATA/tfl_bikes_dirty.ttl" csvBike = readCsv(inputCsv) #create object from the resulting csv file next(csvBike) #skips the header bike_store = plugin.get('IOMemory', Store)() bike_g = Graph(bike_store) prefixes = definePrefixes() print('Binding Prefixes') bindingPrefixes(bike_g, prefixes) print('Creating graph-bike...') for row in csvBike: #loop through individual rows in the csv file **KEY** lstData = getBikeData( row) #activates the getBikeData() function **KEY** createBikeGraph(lstData, bike_g).serialize(outFile, format='turtle') print('Bikes rdfy - done')
def createHotelGraph(arg, g): acco = Namespace("http://purl.org/acco/ns#") dc = Namespace("http://purl.org/dc/elements/1.1/") dct = Namespace('http://purl.org/dc/terms/') dul = Namespace('http://ontologydesignpatterns.org/ont/dul/DUL.owl#') geo = Namespace("http://www.w3.org/2003/01/geo/wgs84_pos#") gr = Namespace('http://purl.org/goodrelations/v1#') gs = Namespace("http://www.opengis.net/ont/geosparql#") locationOnt = Namespace("http://data.linkedevents.org/def/location#") locn = Namespace("http://www.w3.org/ns/locn#") owl = Namespace('http://www.w3.org/2002/07/owl#') rdf = Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#") rdfs = Namespace("http://www.w3.org/2000/01/rdf-schema#") schema = Namespace("http://schema.org/") threecixtyKOS = Namespace('http://data.linkedevents.org/kos/3cixty/') xsd = Namespace("http://www.w3.org/2001/XMLSchema#") locationResPLACEHOLDER = URIRef("http://data.linkedevents.org/location/" + "%s") % getUid(arg[0]) print locationResPLACEHOLDER singleGeometry = URIRef("http://data.linkedevents.org/location/" + "%s" + "/geometry") % getUid(arg[0]) singleAddress = URIRef("http://data.linkedevents.org/location/" + "%s" + "/address") % getUid(arg[0]) g.add((locationResPLACEHOLDER, rdf.type, dul.place)) #g.add((locationResPLACEHOLDER, rdfs.label, Literal(getUid(arg[0])))) g.add((locationResPLACEHOLDER, locationOnt.businessType, threecixtyKOS.residence)) g.add((locationResPLACEHOLDER, dc.identifier, Literal(arg[0]))) #g.add((locationResPLACEHOLDER, dc.publisher, arg[17])) g.add((locationResPLACEHOLDER, dc.publisher, arg[7])) g.add((locationResPLACEHOLDER, owl.sameAs, URIRef("http://www.airbnb.co.uk/rooms/" + "%s") % arg[0])) #g.add((locationResPLACEHOLDER, schema.location, singleAddress)) g.add((locationResPLACEHOLDER, geo.location, singleGeometry)) g.add((singleGeometry, rdf.type, geo.Point)) #g.add((singleGeometry, geo.lat, Literal(arg[6], datatype=xsd.placeholder))) g.add((singleGeometry, geo.lat, Literal(arg[3], datatype=xsd.placeholder))) #g.add((singleGeometry, geo.long, Literal(arg[7], datatype=xsd.placeholder))) g.add((singleGeometry, geo.long, Literal(arg[4], datatype=xsd.placeholder))) #g.add((singleGeometry, locn.geometry, Literal(arg[8], datatype=gs.wktLiteral))) g.add( (singleGeometry, locn.geometry, Literal(arg[5], datatype=gs.wktLiteral))) #g.add((singleAddress, rdf.type, schema.postalAddress)) #g.add((singleAddress, dct.title, Literal(arg[1]))) #g.add((singleAddress, schema.addressCountry, Literal('uk'))) #g.add((singleAddress, schema.addressLocality, Literal(arg[5]))) prefixes = definePrefixes() bindingPrefixes(g, prefixes) return g
def main(): busPathf = './' inFileB = busPathf + 'DATA/bus_validatedSMALL.csv' outFileB = busPathf + 'DATA/bus_dirtySMALL.ttl' csvB = readCsv(inFileB) busline_store = plugin.get('IOMemory', Store)() bus_g = Graph(busline_store) prefixes = definePrefixes() print('Binding Prefixes') bindingPrefixes(bus_g, prefixes) print('Creating graph-Bus...') for row in csvB: lstData = getBusData(row) createBusGraph(lstData, bus_g).serialize(outFileB, format='turtle') print('DONE - Bus rdfy')
def main(): pathf = "./" inFile = pathf + "DATA/airbnbNiceTest.csv" outFile = pathf + "DATA/airbnbNice_dirty.ttl" csv = readCsv(inFile) next(csv, None) # FILE WITH HEADERS store = plugin.get('IOMemory', Store)() g = Graph(store) prefixes = definePrefixes() print('Binding Prefixes') bindingPrefixes(g, prefixes) print('Creating graph-Hotel...') # AMENDED #This one generates the 'turtle' graph. Please deactivate the script for the 'nt' graph below for row in csv: lstData = getHotelData(row) createHotelGraph(lstData, g).serialize(outFile, format='turtle') print('DONE! Time elapsed ' + str((time.time() - start_time)))