On 05/06/12 11:28, Pierre-Yves Chibon wrote:
On Tue, 2012-06-05 at 12:02 +0200, Pierre-Yves Chibon wrote:
So I tried to fix the code using:
String PPCO_URI = "http://www.cropontology.org/rdf/CO_020:";
String ACCESSION_URI = "http://test/accession/";
Model model = ModelFactory.createDefaultModel();
Resource acces = model.createResource(ACCESSION_URI + "Id3");
acces.addProperty(model.createProperty(PPCO_URI + "0000003"),
"Name3");
model.write(System.out);
But it gives me the following backtrace:
SEVERE: com.hp.hpl.jena.shared.InvalidPropertyURIException:
Following the principle of "Keep hitting to wall until you find the
door", I think I found the cause of the problem:
Indeed, when I use:
String PPCO_URI = "http://www.cropontology.org/rdf/CO_020:";
String ACCESSION_URI = "http://test/accession#";
Model model = ModelFactory.createDefaultModel();
Resource acces = model.createResource(ACCESSION_URI + "Id3");
acces.addProperty(model.createProperty(PPCO_URI + "a0000003"),
"Name3");
model.write(System.out);
(ie: Added a 'a' at the beginning of the string)
I get the almost correct RDF:
<rdf:RDF
xmlns:j.0="http://www.cropontology.org/rdf/CO_020:"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="http://test/accession#Id3">
<j.0:a0000003>Name3</j.0:a0000003>
</rdf:Description>
</rdf:RDF>
So the problem seems to rely on the fact that my string "0000003"
contains only number.
Is there a way to fix this or got around it ?
This is a limitation of (RDF/)XML. Qnames must not begin a number;
properties must be qnames.
Jena tries to split the property URI to be legal but in
http://www.cropontology.org/rdf/CO_020:000003
there is no split point (qnames can't contain ":" in the local part
either so splitting at "C" is not legal either).
Can you use Turtle or N-triples (both of which will soon be W3C standards)?
W3C Turtle allows leading digits in prefixed names (as does SPARQL).
And if a property can't be split, writing the URI in <> is legal output.
Jena is conservative and outputs Turtle compatible with older versions
of the de facto spec.
> I am running in a small problem URI wise using jena 2.6.4.
While that's quite old, none of this has fundamentally changed in 2.7.0.
Andy
Thanks,
Pierre