rdflibjsonld在分析图形时从URL中删除/

2024-10-01 07:16:49 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我用来填充和解析rdflib图的代码:

context = {
    "@context": {
    "isGiven": URIRef('<'+'https://w3id.org/ontology#isGiven'+rdfLizerItem['ProductByCategory']+'>'),
    "givenAs": URIRef('<'+'https://w3id.org/ontology#givenAs'+'>'),
    "type":URIRef('<'+'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'+'>'),
    # "recipient":URIRef('<'+varOnt+rdfLizerItem['ProductRecipient']+'>'),
    "@base": '.'
    }
    }

    recipient=URIRef('<https://w3id.org/ontology#'+rdfLizerItem['ProductRecipient']+'>')
    dose =  URIRef('<'+varOnt + rdfLizerItem['Dose']+'>')
    productByCategory = URIRef('<'+varOnt+rdfLizerItem['ProductByCategory']+'>')
    dummyBrand = URIRef('<'+varOnt+rdfLizerItem['ProductByCategory']+'BrandGivenTo'+rdfLizerItem['ProductRecipient']+'>')

    jsonldOutputIsGiven = {"@id": recipient, "isGiven":dose}
    jsonldOutputGivenAs = {"@id":dummyBrand,"type":productByCategory,"givenAs": scoop}
    # graph1 = Graph()
    graph1.parse(data=json.dumps(jsonldOutputIsGiven), format='json-ld', context=context)

    graph1.parse(data=json.dumps(jsonldOutputGivenAs), format='json-ld', context=context)
    graph1.close()
    for s,p,o in graph1:
        pprint.pprint((s,p,o))

在图形的输出中,主题的URL中缺少/。例如:

(rdflib.term.URIRef(u'<https:/w3id.org/ontology#ProductBrandGivenToeSomeone>'),
 rdflib.term.URIRef(u'<https://w3id.org/ontology#givenAs>'),
 rdflib.term.Literal(u'<https://w3id.org/ontology#scoopSome>'))

我需要做什么来确保URL格式正确?你知道吗


Tags: httpsorgjsontypecontextrdflibontologyuriref