[redland-dev] xml:lang problems

Dave Beckett dave.beckett at bristol.ac.uk
Wed Sep 29 14:08:58 BST 2004


On Fri, 24 Sep 2004 08:57:53 +0200 (MEST), Sebastian Dietzold <sebastian at dietzold.de> wrote:

> 
> Hi there,
> 
> i've tested a little bit with redland. I like it, because of its php 
> bindings and i want to use it for some private and university projects.
> 
> How can i read the language of a literal? I've seen that the 
> librdf_node_to_string function glues literal and xml:lang attribute with a 
> @ together but this means that the Literals in these two statements had 
> identical strings, isnt it?

No.  They are different.  RDF literals have three components -
string, language OR datatype.

> <rdf:Description rdf:about="http://sebastian.dietzold.de/terms/me">
>          <foaf:nick xml:lang="de">Seebi</foaf:nick>
> </rdf:Description>

An RDF literal (string "Seebi", language "de")

> <rdf:Description rdf:about="http://sebastian.dietzold.de/terms/me">
>          <foaf:nick>Seebi at de</foaf:nick>
> </rdf:Description>

An RDF literal (string "Seebi")

> Or it is possible to check the language in another way?
> 
> And what about included elements? The Literal from the statement
> 
> <rdf:Description xml:lang="de" rdf:about="http://sebastian.dietzold.de/terms/me">
>          <foaf:nick>Seebi</foaf:nick>
> </rdf:Description>
> should also returned in this way as "Seebi at de" or am i wrong?

No, it would be an RDF literal (string "Seebi", language "de")

> How do you solve this problem actually? I hope, i'm not the first who has 
> to deal with the xml:lang attribute :-)

In PHP if you get a redland node object as part of a triple (a
redland librdf_statement) in a variable $n then you can use

  $lang=librdf_node_get_literal_value_language($n)

and $lang will be "de" or "" for these literals.

--
Alternatively you can make nodes and get back the value:

$n=librdf_new_node_from_literal($world,'Seebi','de', librdf_new_uri($world,''));
$lang=librdf_node_get_literal_value_language($n);
print "Language is $lang\n";

Output:
  Language is de


Dave



More information about the redland-dev mailing list