1

I'm trying to change the URI of a resource in a Model. I'm using ResourceUtils.renameResource it works, but when i save the model in a file, the new URI is extended (has the form <http://prefix.com/resource> instead of prefix:resource) even though there is a prefix in the model (@prefix prefix: <http://prefix.com/>). Is there a way to force Jena to use the prefix when replacing the URI of the resource or a method to update the model rewriting every URI using the short version with "prefix:" when possible?

Giuseppedes
  • 129
  • 9
  • RDF works in absolute URIs - prefixes only aboput the surface appearance. Internally, Jena works in Absolute URIs, not prefix names. Prefixes are expanded when reading and used for abbreviation when writing (if possible - not all URIs can be abbreviated - and it depends on the syntax). – AndyS May 29 '17 at 18:39
  • Show how you write the model and what the data actually looks like. Details matter! – AndyS May 29 '17 at 18:41
  • when I write the model I use: `Model model = ModelFactory.createDefaultModel();` than `model.setNsPrefix(PREFIX, NAMESPACE);` and when i add a resource: `Resource res = model.createResource(NAMESPACE + RESOURCE_ID); res.addProperty(someProperty, someObject);` If i print the model on a file, res is written like prefix:resId but when i use `ResourceUtils.renameResource(res, NAMESPACE + NEW_ID);` When I print the model on a file, res is expanded. I know that jena works with expanded URI, but I'd like to use "prefix:" in order to make the file more human-readable. – Giuseppedes May 31 '17 at 09:45
  • I forgot to say that I create the model in an instance of a servlet service, than i read the model and I rename the resource with a different web service, maybe the problem is that ResourceUtilis.renameResource doesn't know about the previous model.setNsPrefix or it doesn't read prefixes from the model and works without checking if the resource can be written in a short way using prefixes. – Giuseppedes May 31 '17 at 09:54
  • Complete, minimal example please. Details like the values of those constants matter. – AndyS Jun 01 '17 at 12:08

1 Answers1

1

It didn't work because there where symbols like "/" and "#" in the new URI after the prefix. Solved replacing that symbols with a dash "-".

Giuseppedes
  • 129
  • 9