0

This is my code to populate and parse an rdflib graph:

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

In the the output from the graph, the subject has a / missing in the URL. For example:

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

What do I need to do to make sure that the URL is correctly formatted?

kurious
  • 1,024
  • 10
  • 29
  • check the `varOnt` variable - perhaps it has a typo? – CaptSolo Apr 22 '16 at 16:30
  • Checked that. It doesn't appear to have a typo: `varOnt = 'https://w3id.org/ont#'` – kurious Apr 22 '16 at 16:32
  • 1
    `'/'` is not a special symbol in Python or JSON so it should not just magically disappear. It is either a typo or something strange is happening. Can you identify the exact place (e.g. line) where this change happens? - What does the JSON-LD string look like before it is pased into RDF model? – CaptSolo Apr 25 '16 at 09:33

0 Answers0