You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Dan Armbrust <da...@gmail.com> on 2011/09/29 19:49:44 UTC

Question about prefixes and N3

Could someone explain this to me?

Given this code:

		Model model_ = ModelFactory.createDefaultModel();
		String uri = new URI("http://foo/contentA/version#").toString();

		model_.setNsPrefix("a", uri);
		model_.setNsPrefix("l", com.hp.hpl.jena.vocabulary.RDFS.label.getURI());
		
		Resource source = model_.getResource(uri +
"951d9b63-bc07-3e58-bbb4-8dffd26e57f1");
		Resource target = model_.getResource(uri +
"a51d9b63-bc07-3e58-bbb4-8dffd26e57f1");
		
		Statement s = model_.createStatement(source,
com.hp.hpl.jena.vocabulary.RDFS.label, target);
		model_.add(s);
		
		RDFWriter rdfWriter = model_.getWriter("N3-TRIPLE");

		File file = new File("export.n3");
		OutputStream out = new FileOutputStream(file);
		rdfWriter.write(model_, out, null);
		out.close();

Jena outputs the following:

    @prefix a:       <http://foo/contentA/version#> .
    @prefix l:       <http://www.w3.org/2000/01/rdf-schema#label> .

    <http://foo/contentA/version#951d9b63-bc07-3e58-bbb4-8dffd26e57f1>
<http://www.w3.org/2000/01/rdf-schema#label>
a:a51d9b63-bc07-3e58-bbb4-8dffd26e57f1 .


You will notice that it uses the prefix for one of my values, but not
the other.  The only difference between these values is one of them
starts with a number, and the other doesn't.

Does a fragment really have to start with a letter?  Is this a bug?
Or a feature?

Also, you can see that I tried to make it write a prefix for the label
to shorten the output... but that didn't work either.  Is there a way
to do that?

Thanks,

Dan

Re: Question about prefixes and N3

Posted by Paolo Castagna <ca...@googlemail.com>.
Dan Armbrust wrote:
>>>                RDFWriter rdfWriter = model_.getWriter("N3-TRIPLE");
>> Clarification: Jena does not implement N3 - it implements Turtle.  N3 goes
>> beyond RDF.
>>
>> Saysing "N3" goes to TURTLE.
> 
> Hmm.  This documentation confused me:
> http://jena.sourceforge.net/IO/iohowto.html#ntriple
> 
> That detail isn't very clear from the docs.

Documentation can always be improved, contributions and help is always welcome!

In relation to IO, see also: http://openjena.org/wiki/RIOT

Paolo

> 
> 
>> try:
>>
>> @prefix rdf:<http://www.w3.org/2000/01/rdf-schema#> .
>>
>> which does abbreviate (and will do other things).
>>
>>        Andy
> 
> Thanks,
> 
> Dan

Re: Question about prefixes and N3

Posted by Dan Armbrust <da...@gmail.com>.
>>                RDFWriter rdfWriter = model_.getWriter("N3-TRIPLE");
>
> Clarification: Jena does not implement N3 - it implements Turtle.  N3 goes
> beyond RDF.
>
> Saysing "N3" goes to TURTLE.

Hmm.  This documentation confused me:
http://jena.sourceforge.net/IO/iohowto.html#ntriple

That detail isn't very clear from the docs.


> try:
>
> @prefix rdf:<http://www.w3.org/2000/01/rdf-schema#> .
>
> which does abbreviate (and will do other things).
>
>        Andy

Thanks,

Dan

Re: Question about prefixes and N3

Posted by Andy Seaborne <an...@apache.org>.
On 29/09/11 18:49, Dan Armbrust wrote:
> Could someone explain this to me?
>
> Given this code:
>
> 		Model model_ = ModelFactory.createDefaultModel();
> 		String uri = new URI("http://foo/contentA/version#").toString();
>
> 		model_.setNsPrefix("a", uri);
> 		model_.setNsPrefix("l", com.hp.hpl.jena.vocabulary.RDFS.label.getURI());
> 		
> 		Resource source = model_.getResource(uri +
> "951d9b63-bc07-3e58-bbb4-8dffd26e57f1");
> 		Resource target = model_.getResource(uri +
> "a51d9b63-bc07-3e58-bbb4-8dffd26e57f1");
> 		
> 		Statement s = model_.createStatement(source,
> com.hp.hpl.jena.vocabulary.RDFS.label, target);
> 		model_.add(s);
> 		
> 		RDFWriter rdfWriter = model_.getWriter("N3-TRIPLE");

Clarification: Jena does not implement N3 - it implements Turtle.  N3 
goes beyond RDF.

Saysing "N3" goes to TURTLE.

>
> 		File file = new File("export.n3");
> 		OutputStream out = new FileOutputStream(file);
> 		rdfWriter.write(model_, out, null);
> 		out.close();
>
> Jena outputs the following:
>
>      @prefix a:<http://foo/contentA/version#>  .
>      @prefix l:<http://www.w3.org/2000/01/rdf-schema#label>  .
>
>      <http://foo/contentA/version#951d9b63-bc07-3e58-bbb4-8dffd26e57f1>
> <http://www.w3.org/2000/01/rdf-schema#label>
> a:a51d9b63-bc07-3e58-bbb4-8dffd26e57f1 .
>
>
> You will notice that it uses the prefix for one of my values, but not
> the other.  The only difference between these values is one of them
> starts with a number, and the other doesn't.
>
> Does a fragment really have to start with a letter?  Is this a bug?
> Or a feature?


Feature - of Turtle.

In Turtle, a prefix name is more qname-like and must start with a 
letter.  Hopefully the emerging standard will fix this. (It's not a 
restriction in SPARQL.)

> Also, you can see that I tried to make it write a prefix for the label
> to shorten the output... but that didn't work either.  Is there a way
> to do that?

It could have done that - the code your running (the old writer) uses 
the same abbreviation code as the XML writer and an XML qname must have 
at least one char in the local part.  It's not true in the Turtle.

try:

@prefix rdf:<http://www.w3.org/2000/01/rdf-schema#> .

which does abbreviate (and will do other things).

	Andy

>
> Thanks,
>
> Dan