views.py 文件源码

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

项目:nrp 作者: django-rea 项目源码 文件源码
def agent_type_lod(request, agent_type_name):
    ats = AgentType.objects.all()
    agent_type = None

    #import pdb; pdb.set_trace()
    for at in ats:
        if camelcase(at.name) == agent_type_name:
            agent_type = at

    if not agent_type:
        return HttpResponse({}, content_type='application/json') 

    from rdflib import Graph, Literal, BNode
    from rdflib.namespace import FOAF, RDF, RDFS, OWL, SKOS
    from rdflib.serializer import Serializer
    from rdflib import Namespace, URIRef

    path, instance_abbrv, context, store, vf_ns = get_lod_setup_items()

    if agent_type.name != "Person" and agent_type.name != "Group" and agent_type.name != "Individual":
        class_name = camelcase(agent_type.name)
        ref = URIRef(instance_abbrv + ":agent-type-lod/" +class_name)
        store.add((ref, RDF.type, OWL.Class))
        store.add((ref, SKOS.prefLabel, Literal(class_name, lang="en")))
        if agent_type.party_type == "individual":
            store.add((ref, RDFS.subClassOf, vf_ns.Person))
        else: 
            store.add((ref, RDFS.subClassOf, vf_ns.Group))

    ser = store.serialize(format='json-ld', context=context, indent=4)
    return HttpResponse(ser, content_type='application/json')    
    #return render_to_response("valueaccounting/agent_type.html", {
    #    "agent_type": agent_type,
    #}, context_instance=RequestContext(request))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号