ropensci / redland-bindings

Redland librdf language bindings
http://librdf.org/bindings/
Other
17 stars 3 forks source link

Can't specify the language for literal nodes #64

Closed gothub closed 6 years ago

gothub commented 6 years ago

It's not possible to specify the language for an RDF literal node using the Node() method. The following NTriples statement shows a literal node with the language specified as Spanish:

<http://example.org/show/218> <http://example.org/show/localName> "Calle Real"@es

To create a node like this, the Node() method needs to be updated to accept a language argument, i.e.:

 literalNode <- new("Node", world, literal="Calle Real", language="es")

then this could be used to create a Statement:

stmt <- new("Statement", world, subject="http://example.org/show/218",
                                predicate="http://example.org/show/localName",
                                object=literalNode)
gothub commented 6 years ago

After experimenting with adding the language tag for literal nodes, the following query is used to test it:

stmt <- new("Statement", 
            world = world,  
            subject="", 
            predicate="http://schema.org/name", 
            object="Jean-Pierre Rampal",
            language="fr")
addStatement(model, stmt)

query <-'SELECT ?o WHERE { ?s ?p ?o}'
queryObj <- new("Query", world, query)
queryResult <- executeQuery(queryObj, model)
r <-getNextResult(queryResult)

The value for r$o is "\"Jean-Pierre Rampal\"@fr" i.e.

> cat(r$o)
"Jean-Pierre Rampal"@fr

So the redland library has created a string within a string.

Is this acceptable?

cboettig commented 6 years ago

Nice, this is great! The string-within-string thing is fine; the same thing already happens if you give a datatype URI.

For printing, in rdflib I've defined a print method that displays triples using a standard serialization (e.g. nquads) via cat, which sidesteps the display issue with the escaped quotations somewhat.

gothub commented 6 years ago

Added to Node initialize() and Statement initialize() in commits 1517e9e2e145e492d6a04c5a3012b2caaf6557f0 and 88da8c85ecbbce645894fc48a9917a434b56f986