def make_rdf_graph(movies):
mg=ConjunctiveGraph()
mg.bind('fb',FB)
mg.bind('dc',DC)
for movie in movies:
# Make a movie node
movie_node=IVA_MOVIE[movie['id']]
mg.add((movie_node,DC['title'],Literal(movie['title'])))
# Make the director node, give it a name and link it to the movie
dir_node=IVA_PERSON[movie['director']['id']]
mg.add((movie_node,FB['film.film.directed_by'],dir_node))
mg.add((dir_node,DC['title'],Literal(movie['director']['name'])))
for actor in movie['actors']:
# The performance node is a blank node -- it has no URI
performance=BNode()
# The performance is connected to the actor and the movie
actor_node=IVA_PERSON[actor['id']]
mg.add((actor_node,DC['title'],Literal(actor['name'])))
mg.add((performance,FB['film.performance.actor'],actor_node))
# If you had the name of the role, you could also add it to the
# performance node, e.g.
# mg.add((performance,FB['film.performance.role'],Literal('Carrie Bradshaw')))
mg.add((movie_node,FB['film.film.performances'],performance))
return mg
评论列表
文章目录