[Tdwg-guid] Jena examples?

Steve Perry smperry at ku.edu
Mon Sep 25 21:53:45 CEST 2006


Hi Peter,

Ben is right.  To get a TaxonName element (instead of an 
rdf:Description), add the following line of code:

res.addProperty(model.createProperty("
http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), TN_NS + "TaxonName");


This should give you output like :

<rdf:RDF
    xmlns:j.0="http://tdwg.org/2006/03/12/TaxonNames"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <j.0:TaxonName rdf:about="http://test">
    <j.0:testProperty>test</j.0:testProperty>
  </j.0:TaxonName>
</rdf:RDF>


XML namespace prefixes are not preserved in RDF so Jena will supply its 
own prefixes when serializing to one of the XML formats (hence the j.0 
instead of tn).

By the way, the IPNI example you cite has an error:

<tn:nomenclaturalCode rdf:resource="&tn;#botanical" />

Many RDF/XML parsers will see &tn; as an entity which cannot be 
resolved.  Since I don't have a copy of the ontology (and 
http://tdwg.org/2006/03/12/TaxonNames does not resolve), I can only take 
a guess that it should look something like:

<tn:nomenclaturalCode rdf:resource="tn:botanical" />

However, using XML namespace prefixes in resource references inside 
RDF/XML documents tends to cause problems because not all RDF/XML 
parsers are smart enough to dereference the namespace prefix and build a 
fully-qualified resource URI.  A safer form of the above would be the 
fully qualified resource URI which looks like:

<tn:nomenclaturalCode rdf:resource="http://tdwg.org/2006/03/12/TaxonNames/botanical" />


-Steve



Benjamin H Szekely wrote:
> Hi Peter, 
>     In XML/ABBREV mode, the serializer uses rdf:Types for element names. 
> Since your example doesn't have an rdf:Type, it uses the default Jena 
> element names.
>
> - Ben
>
>
> Ben Szekely
> IBM Software Engineer
> Advanced Internet Technology, Cambridge, MA
> bhszekel at us.ibm.com
>
> tdwg-guid-bounces at mailman.nhm.ku.edu wrote on 09/25/2006 11:02:30 AM:
>
>   
>> Hi Everyone,
>>
>> Does anyone have/or know of any good examples of using Jena to output
>> RDF metadata with non-typical namespaces such as TCS/RDF? 
>>
>> Currently I have the following code for my metadata method(I know it's
>> wrong!).
>>
>> String TN_NS = "http://tdwg.org/2006/03/12/TaxonNames/";
>> ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
>> Model model = ModelFactory.createDefaultModel();
>> Resource res = model.createResource("http://test");
>> res.addProperty(model.createProperty(TN_NS,"testProperty"),"test");
>>
>> model.write(byteStream, "RDF/XML-ABBREV");
>> return new MetadataResponse(new
>> ByteArrayInputStream(byteStream.toByteArray()),null,MetadataResponse.RDF
>> _FORMAT);
>>
>> ...which gives me.
>>
>> <rdf:RDF
>>     xmlns:j.0="http://tdwg.org/2006/03/12/TaxonNames/"
>>     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
>>   <rdf:Description rdf:about="http://test">
>>     <j.0:testProperty >test</j.0:testProperty>
>>   </rdf:Description>
>> </rdf:RDF>
>>
>> ...whereas I could really do with something along the lines of the IPNI
>> metadata.
>>
>> <rdf:RDF xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>     xmlns:dc="http://purl.org/dc/elements/1.1/"
>> xmlns:dcterms="http://purl.org/dc/terms/"
>>     xmlns:tn="http://tdwg.org/2006/03/12/TaxonNames/"
>>     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
>>
>>     <!-- example family (has an unlinked typifying name with
>>     
> non-
>   
>> standard format data)-->
>>     <tn:TaxonName
>> rdf:about="urn:lsid:ipni.org:names:30000959-2:1.1.2.1">
>>       <tn:nomenclaturalCode rdf:resource="&tn;#botanical" />
>>       <dc:title>Amaryllidaceae J.St.-Hil.</dc:title>
>>       <dcterms:created>2004-01-20 00:00:00.0</dcterms:created>
>>       <dcterms:modified>2005-06-23
>> 15:45:33.0</dcterms:modified>
>>       <tn:rankString>fam.</tn:rankString>
>>       <tn:nameComplete>Amaryllidaceae</tn:nameComplete>
>>       <tn:uninomial>Amaryllidaceae</tn:uninomial>
>>       <tn:authorship>J.St.-Hil.</tn:authorship>
>>       <tn:publishedIn>Expos. Fam. Nat. 1: 134. 1805 [Feb-Apr
>> 1805]</tn:publishedIn>
>>       <tn:year>1805</tn:year>
>>       <tn:typifiedBy>
>>             <tn:NomenclaturalType>
>>          <dc:title>Amaryllis Linnaeus, nom.
>> cons.</dc:title>
>>       </tn:NomenclaturalType>
>>       </tn:typifiedBy>
>>     </tn:TaxonName>
>>
>> I think the main problem I have is creating resources that aren't
>> defined as vocabularies within Jena already. I can't seem to find a way
>> to create that <tn:TaxonName root resource element.
>>
>> I'm starting to think that just outputting vanilla text could be the
>> best option here, or am I barking up the wrong tree?
>>
>> Many thanks, Peter. 
>>
>> Peter Hollas MSc BSc(hons) (Peter.Hollas at thomson.com)
>> Software Engineer /Systems Administrator
>> Thomson Zoological
>> Innovation Centre
>> York Science Park
>> Heslington
>> York
>> YO10 5DG
>>
>> Tel: 01904-435113
>> Fax: 01904-435114 
>>
>>
>>
>> _______________________________________________
>> TDWG-GUID mailing list
>> TDWG-GUID at mailman.nhm.ku.edu
>> http://mailman.nhm.ku.edu/mailman/listinfo/tdwg-guid
>>     
>
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> TDWG-GUID mailing list
> TDWG-GUID at mailman.nhm.ku.edu
> http://mailman.nhm.ku.edu/mailman/listinfo/tdwg-guid
>   





More information about the tdwg-tag mailing list