Hi Alexander
Here's a couple of examples based on code taken from one of my unit tests:
//Create the Nodes
Graph g = new Graph();
UriNode u = g.CreateUriNode(new Uri("http://www.google.com"));
LiteralNode l = g.CreateLiteralNode("http://www.google.com/");
Console.WriteLine("Created a URI and Literal Node both referring
to 'http://www.google.com'");
Console.WriteLine("String form of URI Node is:");
Console.WriteLine(u.ToString());
Console.WriteLine("String form of Literal Node is:");
Console.WriteLine(l.ToString());
Console.WriteLine("Hash Code of URI Node is " +
u.GetHashCode());
Console.WriteLine("Hash Code of Literal Node is " +
l.GetHashCode());
Console.WriteLine("Hash Codes are Equal? " +
u.GetHashCode().Equals(l.GetHashCode()));
Console.WriteLine("Nodes are equal? " + u.Equals(l));
//Create some plain and typed literals which may have colliding
Hash Codes
LiteralNode plain =
g.CreateLiteralNode("test^^http://example.org/type");
LiteralNode typed = g.CreateLiteralNode("test", new
Uri("http://example.org/type"));
Console.WriteLine();
Console.WriteLine("Created a Plain and Typed Literal where the
String representations are identical");
Console.WriteLine("Plain Literal String form is:");
Console.WriteLine(plain.ToString());
Console.WriteLine("Typed Literal String from is:");
Console.WriteLine(typed.ToString());
Console.WriteLine("Hash Code of Plain Literal is " +
plain.GetHashCode());
Console.WriteLine("Hash Code of Typed Literal is " +
typed.GetHashCode());
Console.WriteLine("Hash Codes are Equal? " +
plain.GetHashCode().Equals(typed.GetHashCode()));
Console.WriteLine("Nodes are equal? " + plain.Equals(typed));
Note that not only can two literals nodes have equivalent string
representations while having different values but as you can see a UriNode
can have an equivalent representation to a LiteralNode. But when you look
at their hash codes and equality they will be none-equal since the actual
values are different.
Hope that clarifies things a bit more for you
Rob
From: Alexander Sidorov [mailto:ale...@gm...]
Sent: 15 April 2010 19:47
To: dot...@li...
Subject: [dotNetRDF-develop] Typed literal
Hi Rob,
Thank you for clarifications.
Could you provide an example of different values that can generate
equivalent strings. I'm just curious :)
Regards,
Alexander
|