本文整理汇总了C#中Triple.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Triple.Equals方法的具体用法?C# Triple.Equals怎么用?C# Triple.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Triple
的用法示例。
在下文中一共展示了Triple.Equals方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
StreamWriter output = new StreamWriter("HashCodeTests.txt");
Console.SetOut(output);
try
{
Console.WriteLine("## Hash Code Tests");
Console.WriteLine("Tests that Literal and URI Nodes produce different Hashes");
Console.WriteLine();
//Create the Nodes
Graph g = new Graph();
IUriNode u = g.CreateUriNode(new Uri("http://www.google.com"));
ILiteralNode 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 Triples
IBlankNode b = g.CreateBlankNode();
IUriNode type = g.CreateUriNode("rdf:type");
Triple t1, t2;
t1 = new Triple(b, type, u);
t2 = new Triple(b, type, l);
Console.WriteLine();
Console.WriteLine("Created two Triples stating a Blank Node has rdf:type of the Nodes created earlier");
Console.WriteLine("String form of Triple 1 (using URI Node) is:");
Console.WriteLine(t1.ToString());
Console.WriteLine("String form of Triple 2 (using Literal Node) is:");
Console.WriteLine(t2.ToString());
Console.WriteLine("Hash Code of Triple 1 is " + t1.GetHashCode());
Console.WriteLine("Hash Code of Triple 2 is " + t2.GetHashCode());
Console.WriteLine("Hash Codes are Equal? " + t1.GetHashCode().Equals(t2.GetHashCode()));
Console.WriteLine("Triples are Equal? " + t1.Equals(t2));
//Now going to look at the Hash Code collisions from the dotNetRDF Store
Console.WriteLine();
Console.WriteLine("Examing the Hash Code Collisions from one of our SQL Store test data sets");
// MicrosoftSqlStoreManager manager = new MicrosoftSqlStoreManager("localhost", "bbcone", "example", "password");
// DataTable collisions = manager.ExecuteQuery(@"SELECT * FROM TRIPLES WHERE tripleHash IN
// (
// SELECT tripleHash FROM TRIPLES GROUP BY tripleHash HAVING COUNT(tripleID)>1
// ) ORDER BY tripleHash");
// foreach (DataRow r in collisions.Rows)
// {
// String s, p, o;
// int hash;
// s = r["tripleSubject"].ToString();
// p = r["triplePredicate"].ToString();
// o = r["tripleObject"].ToString();
// hash = Int32.Parse(r["tripleHash"].ToString());
// INode subj = manager.LoadNode(g, s);
// INode pred = manager.LoadNode(g, p);
// INode obj = manager.LoadNode(g, o);
// Triple t = new Triple(subj, pred, obj);
// Console.WriteLine("Subject (ID " + s + "): " + subj.ToString() + " (Hash " + subj.GetHashCode() + ")");
// Console.WriteLine("Predicate (ID " + p + "): " + pred.ToString() + " (Hash " + pred.GetHashCode() + ")");
// Console.WriteLine("Object (ID " + o + "): " + obj.ToString() + " (Hash " + obj.GetHashCode() + ")");
// Console.WriteLine(t.ToString());
// Console.WriteLine("Triple Hash " + t.GetHashCode());
// Console.WriteLine("Triple Hash Code Construct " + subj.GetHashCode().ToString() + pred.GetHashCode().ToString() + obj.GetHashCode().ToString());
// Console.WriteLine("Triple Hash in Store " + hash);
// Console.WriteLine();
// }
// manager.Dispose();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
finally
{
output.Close();
}
}
示例2: NodesHashCodes
public void NodesHashCodes()
{
Console.WriteLine("Tests that Literal and URI Nodes produce different Hashes");
Console.WriteLine();
//Create the Nodes
Graph g = new Graph();
IUriNode u = g.CreateUriNode(new Uri("http://www.google.com"));
ILiteralNode 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));
Assert.AreNotEqual(u.GetHashCode(), l.GetHashCode());
Assert.AreNotEqual(u, l);
//Create some plain and typed literals which may have colliding Hash Codes
ILiteralNode plain = g.CreateLiteralNode("test^^http://example.org/type");
ILiteralNode 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));
Assert.AreNotEqual(plain.GetHashCode(), typed.GetHashCode());
Assert.AreNotEqual(plain, typed);
//Create Triples
IBlankNode b = g.CreateBlankNode();
IUriNode type = g.CreateUriNode("rdf:type");
Triple t1, t2;
t1 = new Triple(b, type, u);
t2 = new Triple(b, type, l);
Console.WriteLine();
Console.WriteLine("Created two Triples stating a Blank Node has rdf:type of the URI Nodes created earlier");
Console.WriteLine("String form of Triple 1 (using URI Node) is:");
Console.WriteLine(t1.ToString());
Console.WriteLine("String form of Triple 2 (using Literal Node) is:");
Console.WriteLine(t2.ToString());
Console.WriteLine("Hash Code of Triple 1 is " + t1.GetHashCode());
Console.WriteLine("Hash Code of Triple 2 is " + t2.GetHashCode());
Console.WriteLine("Hash Codes are Equal? " + t1.GetHashCode().Equals(t2.GetHashCode()));
Console.WriteLine("Triples are Equal? " + t1.Equals(t2));
Assert.AreNotEqual(t1.GetHashCode(), t2.GetHashCode());
Assert.AreNotEqual(t1, t2);
//Create Triples from the earlier Literal Nodes
t1 = new Triple(b, type, plain);
t2 = new Triple(b, type, typed);
Console.WriteLine();
Console.WriteLine("Created two Triples stating a Blank Node has rdf:type of the Literal Nodes created earlier");
Console.WriteLine("String form of Triple 1 (using Plain Literal) is:");
Console.WriteLine(t1.ToString());
Console.WriteLine("String form of Triple 2 (using Typed Literal) is:");
Console.WriteLine(t2.ToString());
Console.WriteLine("Hash Code of Triple 1 is " + t1.GetHashCode());
Console.WriteLine("Hash Code of Triple 2 is " + t2.GetHashCode());
Console.WriteLine("Hash Codes are Equal? " + t1.GetHashCode().Equals(t2.GetHashCode()));
Console.WriteLine("Triples are Equal? " + t1.Equals(t2));
Assert.AreNotEqual(t1.GetHashCode(), t2.GetHashCode());
Assert.AreNotEqual(t1, t2);
}