I compare two graphs, one from a Turtle file with simple literal objects, and the other from a file with explicit IRI data types. The graphs are otherwise equal.
Chart A:
<s> <p> "o"
Chart B:
<s> <p> "o"^^xsd:string
According to RDF 1.1 (3.3 Literals) , "[s] imple literals are syntactic sugar for abstract syntax literals with an IRI data type of http://www.w3.org/2001/XMLSchema#string ". This is also reflected in specific syntax specifications ( N-Triples , Turtle , RDF XML ).
Therefore, I would expect that both of my graphs consist of one triple with the URI object node, the predicate URI node p and the literal node o with type xsd: string object. Based on this, I would expect that there will be no difference between them.
However, in practice this is not so:
var graphStringA = "<http://example.com/subject> <http://example.com/predicate> \"object\".";
var graphStringB = "<http://example.com/subject> <http://example.com/predicate> \"object\"^^<http://www.w3.org/2001/XMLSchema#string>.";
var graphA = new Graph();
var graphB = new Graph();
StringParser.Parse(graphA, graphStringA);
StringParser.Parse(graphB, graphStringB);
var diff = graphA.Difference(graphB);
There is one added and one removed tee in the differences report. Graphs are different because the data types for the nodes of an object are different: graphA.Triples.First().Object.Datatypenothing, but graphB.Triples.First().Object.Datatypea valid URI.
It seems to me that to change this behavior I will have to either
- go to LiteralNode (and change its assumptions about literal nodes) or
- create a new GraphDiff (which takes into account the default data type for string literals).
The workaround is to remove the default data types:
private static void RemoveDefaultDatatype(IGraph g)
{
var triplesWithDefaultDatatype =
from triple in g.Triples
where triple.Object is ILiteralNode
let literal = triple.Object as ILiteralNode
where literal.DataType != null
where literal.DataType.AbsoluteUri == "http://www.w3.org/2001/XMLSchema#string" || literal.DataType.AbsoluteUri == "http://www.w3.org/2001/XMLSchema#langString"
select triple;
var triplesWithNoDatatype =
from triple in triplesWithDefaultDatatype
let literal = triple.Object as ILiteralNode
select new Triple(
triple.Subject,
triple.Predicate,
g.CreateLiteralNode(
literal.Value,
literal.Language));
g.Assert(triplesWithNoDatatype.ToArray());
g.Retract(triplesWithDefaultDatatype);
}
dotnetrdf , RDF 1.1, , ?