Reputation: 665
I have the following resource: http://test.com/domainOnt/email#[email protected]
As in RDFLib, when you search for this in a graph, it returns a URIRef object. I would like to remove the namespace from the object so that it becomes [email protected]
any help is appreciated
Upvotes: 2
Views: 1726
Reputation: 11
RDFLib classes have this class hierarchy.
As you can see, a URIRef have the defrag
method, here defined.
The part of the URL that you want to get is called 'fragment'. To get it, you can simply do the following:
resource = URIRef('http://test.com/domainOnt/email#[email protected]')
result = resource.fragment
The example provided in RDFLib's documentation to return a URL fragment is the following:
URIRef("http://example.com/some/path/#some-fragment").fragment
>> 'some-fragment'
URIRef("http://example.com/some/path/").fragment
>> ''
Upvotes: 1
Reputation: 860
URIRef objects in RDFLib are unicode objects and have all of the unicode object methods, like split. The following will work if all of your class names are separated from the namespace with a '#'.
resource = URIRef('http://test.com/domainOnt/email#[email protected]')
print resource.split('#')[-1]
This question and answer is quite similar to yours.
Upvotes: 3