views.py 文件源码

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

项目:nrp 作者: django-rea 项目源码 文件源码
def agent_relationship_inv_lod(request, agent_assoc_id):
    aa = AgentAssociation.objects.filter(id=agent_assoc_id)
    if not aa:
        return HttpResponse({}, content_type='application/json')
    else:
        agent_association = aa[0]

    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()

    ref = URIRef(instance_abbrv + ":agent-relationship-inv-lod/" + str(agent_association.id) + "/")
    inv_ref = URIRef(instance_abbrv + ":agent-relationship-lod/" + str(agent_association.id) + "/")
    ref_object = URIRef(instance_abbrv + ":agent-lod/" + str(agent_association.is_associate.id) + "/")
    ref_subject = URIRef(instance_abbrv + ":agent-lod/" + str(agent_association.has_associate.id) + "/")
    property_name = camelcase_lower(agent_association.association_type.inverse_label)
    ref_relationship = URIRef(instance_abbrv + ":agent-relationship-type-lod/" + property_name)
    store.add((ref, RDF.type, vf_ns["Relationship"]))
    store.add((ref, vf_ns["subject"], ref_subject)) 
    store.add((ref, vf_ns["object"], ref_object))
    store.add((ref, vf_ns["relationship"], ref_relationship))
    store.add((ref, OWL.inverseOf, inv_ref))

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


问题


面经


文章

微信
公众号

扫码关注公众号