Skip to content

Instantly share code, notes, and snippets.

@betehess
Last active December 23, 2015 19:48
Show Gist options
  • Save betehess/6684747 to your computer and use it in GitHub Desktop.
Save betehess/6684747 to your computer and use it in GitHub Desktop.

The Graph Literal section says the following

Concrete syntaxes MAY support simple literals, consisting of only a lexical form without any datatype IRI or language tag. Simple literals only exist in concrete syntaxes, and are treated as syntactic sugar for abstract syntax literals with the datatype IRI http://www.w3.org/2001/XMLSchema#string.

In practice, it appears that both Jena and Sesame are broken in their handling of RDF Literals. They also break graph isomorphism for the same reasons.

The implementations are also broken according to the Recommendation A Datatype for RDF Plain Literals for some corner-cases (eg. "Alexandre Bertails@").

banana-rdf with Jena

val graph = reader.read("""<http://bertails.org/Alexandre#me> <http://xmlns.com/foaf/0.1/name> "Alexandre Bertails".""", "").get
graph.toIterable.foreach { case triple =>
 val Triple(s, p, o) = triple
 println("triple = "+triple)
 println("o = "+o)
 println("o.getLiteralLexicalForm = "+o.getLiteralLexicalForm)
 println("o.getLiteralDatatypeURI = "+o.getLiteralDatatypeURI)
 println("o.getLiteralLanguage = "+o.getLiteralLanguage)
 println("o.getLiteralLanguage.isEmpty = "+o.getLiteralLanguage.isEmpty)
}

Output

triple = http://bertails.org/Alexandre#me @http://xmlns.com/foaf/0.1/name "Alexandre Bertails"
o = "Alexandre Bertails"
o.getLiteralLexicalForm = Alexandre Bertails
o.getLiteralDatatypeURI = null
o.getLiteralLanguage = 
o.getLiteralLanguage.isEmpty = true
  • getLiteralDatatypeURI should be http://www.w3.org/2001/XMLSchema#string
  • getLiteralLanguage should be null, not the empty String...
  • the invariant that should be enforced: exactly one of getLiteralDatatypeURI or getLiteralLanguage should be defined, the other being null

banana-rdf with Sesame

val graph = reader.read("""<http://bertails.org/Alexandre#me> <http://xmlns.com/foaf/0.1/name> "Alexandre Bertails".""", "").get
graph.toIterable.foreach { case triple =>
 val Triple(s, p, o) = triple
 println("triple = "+triple)
 println("o = "+o)
 foldNode(o)(
  iri => sys.error("don't care"),
  bnode => sys.error("don't care"),
  literal => {
   println("literal.getLabel = "+literal.getLabel)
   println("literal.getDatatype = "+literal.getDatatype)
   println("literal.getLanguage = "+literal.getLanguage)
  }
 )
}

output

triple = (http://bertails.org/Alexandre#me, http://xmlns.com/foaf/0.1/name, "Alexandre Bertails") [null]
o = "Alexandre Bertails"
literal.getLabel = Alexandre Bertails
literal.getDatatype = null
literal.getLanguage = null
  • getDatatype should be http://www.w3.org/2001/XMLSchema#string
  • the invariant that should be enforced: exactly one of getDatatype or getLanguage should be defined, the other being null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment