kurious
kurious

Reputation: 1044

rdflib-jsonld generates spurious url when '<' is used in '@id'

I'm using rdflib-jsonld to parse some NoSQL data and insert into Sesame. This is the problematic portion of the code:

context = {
    "@context": {
    "isGiven": URIRef('<'+'http://purl.org/net/something#isGiven'+rdfLizerItem['FooByBar']+'>'),
    "administeredAs": URIRef('<'+'http://purl.org/net/something#administeredAs'+'>'),
    "type":URIRef('<'+'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'+'>'),
    }
    }
    recipient=URIRef('<'+someUrl+rdfLizerItem['FooRecipient']+'>')
    jsonldOutputIsAdmin = {"@id": recipient,"isGiven": URIRef('<'+someUrl+ rdfLizerItem['Quantity']+'>')}
    print jsonldOutputIsAdmin
    g = Graph()
    g.parse(data=json.dumps(jsonldOutputIsAdmin), format='json-ld', context=context)
    g.close()
    for s,p,o in g:
        pprint.pprint ((s,p,o))

The issue is upon the addition of < and > to the URL for @id, the URL of the subject becomes the complete path to it. For example:

(rdflib.term.URIRef(u'file:///C:/path/to/the/url/<http:/purl.org/net/ontologyName#subject>'),
 rdflib.term.URIRef(u'<http://purl.org/net/ontologyName#predicate>'), 
rdflib.term.Literal(u'<http://purl.org/net/ontologyName#object>'))

I want only the URL in the subject and not the file path. What is causing the issue and how I can I resolve it?

I need < and > to be able to export the triples to Sesame.

Upvotes: 0

Views: 131

Answers (1)

snakecharmerb
snakecharmerb

Reputation: 55924

To avoid the filesystem path being applied as a prefix, you need to provide the context with a value for the base IRI

JSON-LD allows IRIs to be specified in a relative form which is resolved against the document base according section 5.1 Establishing a Base URI of [RFC3986]. The base IRI may be explicitly set with a context using the @base keyword.

For example, if you modify your context like this:

context['@context']['@base'] = '.'

you won't see the path prefixing the @id value.

Upvotes: 1

Related Questions