W3C home > Mailing lists > Public > semantic-web@w3.org > September 2005

Re: rdflib lang:xml attribute on properties

From: Daniel Krech <eikeon@eikeon.com>
Date: Thu, 8 Sep 2005 09:24:12 -0400
Message-Id: <CFD42AFB-D828-4E70-97A4-14D09F4E7E83@eikeon.com>
Cc: semantic-web@w3.org
To: David Pratt <fairwinds@eastlink.ca>

On Sep 8, 2005, at 8:58 AM, David Pratt wrote:

> Hi. I am using python rdflib.  I have contacted the author of the  
> software but no response to query of how to add lang attribute to  
> properties on adding data to store. Anyone with any experience with  
> rdflib to provide any pointers. There is an api but few examples  
> and googling very little by the way of discussions, lists etc for  
> the library or rdf xml in general.  Anyone using rdflib that can  
> give me a hint.

Hi David, I've had my head down working on some other stuff since I  
got your message yesterday... and hadn't got back far enough yet when  
responding to emails this morning. Others on this list should be able  
to help as well, but I'll attempt a quick answer now.

> An example of the library is below that came with the library.  I  
> am assuming there is a way to specify the languages on a property  
> or literal so that when serialized with give me something like this  
> for example <foaf:nick xml:lang="en">donna</foaf:nick> and when  
> converted to raw triples with give me donna@en.
> # Create a namespace object for the Friend of a friend namespace.
> FOAF = Namespace("http://xmlns.com/foaf/0.1/")
> # Create an identifier to use as the subject for Donna.
> donna = BNode()
> # Add triples using store's add method.
> store.add((donna, RDF.type, FOAF["Person"]))


> store.add((donna, FOAF["nick"], Literal("donna")))


store.add((donna, FOAF["nick"], Literal("donna", lang="en")))

> store.add((donna, FOAF["name"], Literal("Donna Fales")))
> # Serialize the store as RDF/XML to the file foaf.rdf.
> store.save("foaf.rdf", format="pretty-xml")
> Serializing produces:
> <?xml version="1.0" encoding="utf-8"?>
> <rdf:RDF
>   xmlns:foaf='http://xmlns.com/foaf/0.1/'
>   xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
> >
>   <foaf:Person>
>     <foaf:name>Donna Fales</foaf:name>

And instead of:

>     <foaf:nick>donna</foaf:nick>

you will get:

<foaf:nick xml:lang="en">donna</foaf:nick>

>   </foaf:Person>
> </rdf:RDF>
> Regards,
> David

Daniel Krech, http://eikeon.com/
Received on Thursday, 8 September 2005 13:29:42 UTC

This archive was generated by hypermail 2.4.0 : Tuesday, 5 July 2022 08:44:54 UTC