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 createTubeSGraph(arg, g): 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#") geosparql = Namespace("http://www.opengis.net/ont/geosparql#") locationOnt = Namespace("http://data.linkedevents.org/def/location#") locn = Namespace("http://www.w3.org/ns/locn#") 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/') transit = Namespace("http://vocab.org/transit/terms/") xsd = Namespace("http://www.w3.org/2001/XMLSchema#") #singleStation = createStation(str(arg[1]).strip())## singleStation = createStation(str(getUid(arg[1]))) ## #singleGeometry = createStationGeom(str(arg[1]).strip())## singleGeometry = createStationGeom(str(getUid(arg[1]))) singleLine = createLine(str(arg[5]).strip()) singleAddress = createAddress(str(getUid(arg[1]))) g.add((singleStation, rdf.type, transit.Station)) g.add((singleStation, rdf.type, dul.Place)) g.add((singleStation, dc.identifier, Literal(arg[0]))) g.add((singleStation, rdfs.label, Literal(str(arg[1]).strip()))) g.add((singleStation, dct.description, Literal(str(arg[8]).strip()))) g.add((singleStation, geo.location, singleGeometry)) ## g.add((singleStation, dc.publisher, URIRef(arg[11]))) g.add((singleStation, locationOnt.businessType, URIRef(arg[10]))) g.add((singleStation, transit.route, singleLine)) g.add((singleStation, locn.address, singleAddress)) g.add((singleAddress, rdf.type, schema.PostalAddress)) g.add((singleAddress, rdf.type, dct.Location)) g.add((singleAddress, dct.title, Literal(arg[1]))) g.add((singleAddress, schema.streetAddress, Literal(arg[8]))) g.add((singleLine, rdf.type, transit.RailRoute)) g.add((singleLine, schema.name, Literal(str(arg[5])))) g.add((singleLine, transit.Station, singleStation)) g.add((singleGeometry, rdf.type, geo.Point)) g.add((singleGeometry, geo.lat, Literal(arg[3], datatype=xsd.placeholder))) g.add((singleGeometry, geo.long, Literal(arg[4], datatype=xsd.placeholder))) g.add((singleGeometry, locn.geometry, Literal(arg[9], datatype=geosparql.wktLiteral))) return g
def getTubeSData(row): stationNaptan = row[0] stationName = row[1] stopType = row[2].replace('Naptan', '') lat = row[3] lon = row[4] line = row[5] wifi = row[6] zone = row[7] address = row[8] wkt = ('POINT ' + '(' + lat + ',' + lon + ')').replace(',', ' ') businessType = 'http://data.linkedevents.org/kos/3cixty/subway' publisher = 'https://tfl.gov.uk' stopGUID = getUid(row[0]) lst = [ stationNaptan, #0 stationName, #1 stopType, #2 lat, #3 lon, #4 line, #5 wifi, #6 zone, #7 address, #8 wkt, #9 businessType, #10 publisher, #11 stopGUID ] #12 return lst
def getTubeSData(row): stationNaptan = row[0] stationName = row[1] stopType = row[2].replace('Naptan', '') lat = row[3] lon = row[4] line = row[5] #wifi = row[6] #zone = row[7] #address = row[8] wkt = ('(' + lat + ',' + lon + ')').replace(',', ' ') businessType = 'http://data.linkedevents.org/kos/3cixty/ferrystation' publisher = 'https://tfl.gov.uk' stopGUID = getUid(row[0]) lst = [ stationNaptan, #0 stationName, #1 stopType, #2 lat, #3 lon, #4 line, #5 wkt, #6 businessType, #7 publisher, #8 stopGUID ] #9 return lst
def getBusData(row): if not os.path.exists('DATA/'): os.makedirs(strftime('DATA/')) objectID = row[1] Lat = row[4] Lon = row[5] stopLon, stopLat = convertProj(Lon, Lat) noAddress = '' stopid = objectID stopGeometry = 'POINT (' + str(stopLat) + ' ' + str(stopLon) + ')' stopRoute = URIRef('http://data.linkedevents.org/transit/London/route/') stopGUID = getUid(str(row[2])) stopTitle = Literal(str(row[3])) stopAddress = Literal(noAddress) stopLocnAddress = Literal(noAddress) stopAddressLocality = Literal('London') stopAdminUnitL2 = Literal('London') stopPublisher = URIRef('https://tfl.gov.uk/modes/buses/') stopBusinessType = URIRef('http://data.linkedevents.org/kos/tfl/busstop') stopLabel = Literal('Bus Stop - ' + str(row[3])) lst = [ stopid, #0 stopLon, #1 stopLat, #2 stopGeometry, #3 stopRoute, #4 stopTitle, #5 stopAddress, stopLocnAddress, stopAddressLocality, stopAdminUnitL2, stopPublisher, stopBusinessType, stopLabel, stopGUID ] return lst
def createBikeGraph(arg, g): 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#') geosparql = Namespace('http://www.opengis.net/ont/geosparql#') naptan = Namespace('http://transport.data.gov.uk/def/naptan/') locationOnt = Namespace('http://data.linkedevents.org/def/location#') locn = Namespace('http://www.w3.org/ns/locn#') 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/') xsd = Namespace('http://www.w3.org/2001/XMLSchema#') bikeid = arg[4].encode('utf-8') bikeGUID = getUid(arg[4], arg[1], naptan) bikeLat, bikeLong = float(arg[9]), float(arg[10]) bikeLats = str('{:f}'.format(bikeLat)) bikeLongs = str('{:f}'.format(bikeLong)) nTotalDocks = str(arg[8].encode('utf-8')) address = arg[2].split(',') bikeLabel = address[len(address) - 1].lstrip() + ' ' + str(bikeid) bikeGeometry = "POINT (" + str(bikeLat) + " " + str(bikeLong) + ")" #bikeAddress = Literal(re.sub(r'&(?![A-Za-z]+[0-9]*;|#[0-9]+;|#x[0-9a-fA-F]+;)', r'and',arg[2])) bikeAddress = Literal(arg[2]) #a, b = bikeAddress.strip("\n ' '").split(',') bikeAddressStreet = Literal(bikeAddress.strip("\n ' '").split(',')[0]) #bikeAddressLocality = Literal(bikeAddress.split(',')[1].replace(" ", "", 1)) #bikeAddressLocality = Literal(bikeAddress.strip("\n ' '").split(',')) bikeCreatedDate = arg[5] singleBike = createBikeParkID(bikeGUID) singleAddress = createAddress(bikeGUID) singleGeometry = createGeometry(bikeGUID) bikePublisher = URIRef('https://tfl.gov.uk') bikeBusinessType = URIRef( 'http://data.linkedevents.org/kos/3cixty/bikestation') g.add((singleBike, rdf.type, dul.Place)) g.add((singleBike, dc.identifier, Literal(arg[0]))) g.add((singleBike, rdfs.label, Literal(arg[2]))) #g.add((singleBike, geom.geometry, singleGeometry)) #g.add((singleBike, schema.geo, singleGeometry)) g.add((singleGeometry, rdf.type, geo.Point)) g.add((singleGeometry, geo.lat, Literal(bikeLats, datatype=xsd.placeholder))) g.add( (singleGeometry, geo.long, Literal(bikeLongs, datatype=xsd.placeholder))) g.add((singleGeometry, locn.geometry, Literal(bikeGeometry, datatype=geosparql.wktLiteral))) g.add((singleBike, geo.location, singleGeometry)) g.add((singleAddress, rdf.type, schema.PostalAddress)) #g.add((singleBike, vcard.hasAddress, singleAddress)) g.add((singleBike, locn.address, singleAddress)) g.add((singleAddress, dct.title, bikeAddress)) g.add((singleAddress, schema.streetAddress, bikeAddressStreet)) #g.add((singleAddress, vcard.street_address, bikeAddressStreet)) g.add((singleAddress, locn.address, bikeAddress)) #g.add((singleBike, schema.location, singleAddress)) #g.add((singleBike, vcard.hasAddress, singleAddress)) g.add((singleBike, locn.address, singleAddress)) g.add((singleBike, schema.dateCreated, Literal(bikeCreatedDate, datatype=xsd.dateTime))) g.add((singleBike, schema.url, URIRef("https://api-argon.tfl.gov.uk/Place/%s" % arg[0]))) g.add((singleBike, locationOnt.nTotalDocks, Literal(nTotalDocks, datatype=xsd.int))) g.add((singleBike, dc.publisher, bikePublisher)) g.add((singleBike, locationOnt.businessType, bikeBusinessType)) return g