1

I have a TTL file like so:

@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix : <http://example.com#> .

:Custom_Object a owl:Class .

Ideally using rdflib or similar, I would like to load this file and change the prefix for http://example.com namespace to something else. After re-serializing the graph, it should look something like:

@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix example: <http://example.com#> .

example:Custom_Object a owl:Class .

I have tried using rdflib's Graph.bind() but it seems to only work the other way (changing the namespace but NOT the prefix).

jarthur
  • 393
  • 1
  • 2
  • 18
  • 1
    `Graph.bind('example', 'http://example.com#')` and then `Graph.bind('', 'http://example.com.old#',replace=True)` does not work? – UninformedUser Oct 13 '20 at 06:00
  • 1
    Interesting, I did try this already without success in my own codebase -- however mine contains a few layers of complexity more than this example (wrapper classes around Graph, etc.). After trying on the above, it does indeed work so I guess there is some more digging to do on my end. Cheers @UninformedUser. – jarthur Oct 13 '20 at 22:39
  • @UninformedUser: you've provided a comment that either is an answer or one that is close to an answer and the questioner has benefited from. Can you please post such comments as Answers so we can better track which SO questions have been answered? The questioners can't mark questions answered with just comments! I'm most keen to see [rdflib] questions answered since I maintain RDFlib. – Nicholas Car Nov 08 '20 at 23:36
  • well, honestly I didn't provide it as an answer because I'm not used to `rdflib` and wasn't sure if this is the correct way, it was basically the only idea I got from the docs and even then it is surely not complete. Because a pending entry `@prefix : .` would still exist. – UninformedUser Nov 09 '20 at 06:08

0 Answers0