Exemplo n.º 1
0
def createGraphForEvents(store,repo_name,events,gfacebook_user=None,gfacebook_user_uriref=None):
	for event in events:
		eventUriRef = URIRef("http://facebook.com/"+event["id"])

		gevent = Graph(store=store,identifier=eventUriRef)
		gevent.add((eventUriRef,RDF.type,fb["Event"]))
		gevent.add((eventUriRef,RDFS.label,Literal(event["name"])))
		gevent.add((eventUriRef,fb["id"],Literal(event["id"])))

		if "attending_total" in event.keys():
			gevent.add((eventUriRef,fb["attending_total"],Literal(event["attending_total"])))

		if(gfacebook_user!=None and gfacebook_user_uriref!=None):
			gfacebook_user.add((gfacebook_user_uriref,ns["was_at"],eventUriRef))

		#add the rest of information
		eventAlreadyExists = sesame_repository.doesEventWithIdExist(repo_name,event["id"])
		if not eventAlreadyExists:
			if "image_url" in event.keys() and event["image_url"]!=None:
				gevent.add((eventUriRef,fb["image_url"],Literal(event["image_url"]["source"])))

			start_time_string = event["start_time"]
			start_time_string_without_timezone = start_time_string.split("+")[0]

			date_added=False
			#try to add date
			try:
				start_time_date = datetime.strptime(start_time_string_without_timezone,'%Y-%m-%dT%H:%M:%S')
				gevent.add((eventUriRef,fb["start_time"],Literal(start_time_string_without_timezone,datatype=XSD.dateTime)))
				date_added=True
			except:
				print "could not process datetime, try date instead"

			if not date_added:
				try:
					start_time_date = datetime.strptime(start_time_string_without_timezone,'%Y-%m-%d')
					gevent.add((eventUriRef,fb["start_time"],Literal(start_time_string_without_timezone,datatype=XSD.date)))
				except:
					print "could not even add event date, something wrong"

			gevent.add((eventUriRef,fb["location"],Literal(event["location"])))
			
			if "eventdata" in event.keys():
				if("description" in event["eventdata"].keys()):
					gevent.add((eventUriRef,fb["description"],Literal(event["eventdata"]["description"])))
				if("venue" in event["eventdata"].keys() and "id" in event["eventdata"]["venue"].keys()):
					gevent.add((eventUriRef,fb["at_venue"],URIRef("http://facebook.com/"+event["eventdata"]["venue"]["id"])))
					if "latitude" in event["eventdata"]["venue"].keys() and "longitude" in event["eventdata"]["venue"].keys():
						gevent.add((eventUriRef,ns["latitude"],Literal(event["eventdata"]["venue"]["latitude"])))
						gevent.add((eventUriRef,ns["longitude"],Literal(event["eventdata"]["venue"]["longitude"])))
Exemplo n.º 2
0
def createGraphForEventArtistsAndGenres(store,repo_name,events):
	count =0 
	allArtistUris = []
	for event in events:
		eventAlreadyExists = sesame_repository.doesEventWithIdExist(repo_name,event["id"])
		if not eventAlreadyExists:
			eventUriRef = URIRef("http://facebook.com/"+event["id"])

			gevent = Graph(store=store,identifier=eventUriRef)
			
			if "eventdata" in event.keys():
				if("description" in event["eventdata"].keys()):
					description = event["eventdata"]["description"]
					genres = dbpedia.extractMusicGenreNamesFromText(description)
					for dbpediaGenreUri in genres:
						gevent.add((eventUriRef,ns["genre"],URIRef(dbpediaGenreUri)))
					artists = dbpedia_spotlight.getArtistEntities(description)
					for artistUri in artists:
						gevent.add((eventUriRef,ns["relatedArtist"],URIRef(artistUri)))
						if artistUri not in allArtistUris:
							allArtistUris.append(artistUri)
		
		count = count+1

		# if count==15:
		# 	break

		print "processed artists for "+str(count)+" out of "+str(len(events))+" events"
	# if count==2:
	# 	break

	#now add soundcloud tracks id data to all artists

	count = 0 
	soundcloudClient = soundcloud_get_tracks.getSoundcloudClient()
	for artistUri in allArtistUris:
		extractArtistInfoAndAddToGraph(store,artistUri,soundcloudClient)
		count = count+1
		print "processed artist info for "+str(count)+" out of "+str(len(allArtistUris))+" artists"