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@").
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 behttp://www.w3.org/2001/XMLSchema#string
getLiteralLanguage
should benull
, not the empty String...- the invariant that should be enforced: exactly one of
getLiteralDatatypeURI
orgetLiteralLanguage
should be defined, the other beingnull
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 behttp://www.w3.org/2001/XMLSchema#string
- the invariant that should be enforced: exactly one of
getDatatype
orgetLanguage
should be defined, the other beingnull