IVAtoRDF.py 文件源码

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

项目:programming-the-semantic-web 作者: utecht 项目源码 文件源码
def get_in_theaters():
    #stream=urlopen('http://www.videodetective.com/api/intheaters.aspx?DeveloperId={KEY}')
    #stream=urlopen('http://semprog.com/data/intheaters.xml')
    stream=file('intheaters.xml')

    root=parse(stream)
    stream.close()

    movies=[]

    for item in root.getElementsByTagName('item'):
        movie={}

        # Get the ID, title, and director
        movie['id']=getdata(item,'PublishedId')
        movie['title']=getdata(item,'Title')
        movie['director']={'id':getdata(item,'DirectorID'),'name':getdata(item,'Director')}

        # Actor tags are numbered: Actor1, Actor2, etc.
        movie['actors']=[]    
        for i in range(1,6):
            actor=getdata(item,'Actor%d' % i)
            actorid=getdata(item,'ActorId%d' % i)

            if actor!=None and actorid!=None:
                movie['actors'].append({'name':actor,'id':actorid})

        movies.append(movie)

    return movies

# Generate an RDF Graph from the Movie Data
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号