IVAtoRDF.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:programming-the-semantic-web 作者: utecht 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号