当前位置: 首页>>代码示例>>C#>>正文


C# Triple.GetHashCode方法代码示例

本文整理汇总了C#中Triple.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# Triple.GetHashCode方法的具体用法?C# Triple.GetHashCode怎么用?C# Triple.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Triple的用法示例。


在下文中一共展示了Triple.GetHashCode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:91,代码来源:HashCodeTests.cs

示例2: GetNextTripleID

        /// <summary>
        /// Gets the next available Database Triple ID if the Triple is not in the Database of the existing Database Triple ID
        /// </summary>
        /// <param name="t">Triple to get an ID for</param>
        /// <param name="createRequired">Whether the Manager needs to create a Triple Record in the Database</param>
        /// <returns></returns>
        protected virtual int GetNextTripleID(Triple t, out bool createRequired)
        {
            int id = -1;
            createRequired = false;

            try
            {
                Monitor.Enter(this._tripleIDs);
                if (this._nextTripleID == -1)
                {
                    this.LoadTripleIDMap();
                }

                //Use the Triple Collection to record Triples we've requested IDs for
                //This allows us to take advantage of the Triple Collections ability to detect
                //when Triple Hash Codes collide and then we can use this in the next step to
                //do a Database lookup if necessary
                if (!this._tripleCollection.Contains(t))
                {
                    this._tripleCollection.Add(t);
                }

                if (this._tripleIDs.ContainsKey(t.GetHashCode()))
                {
                    id = this._tripleIDs[t.GetHashCode()];

                    if (id == -1 || t.Collides)
                    {
                        //There are multiple Triples with this Hash Code
                        //Lookup from Database
                        String s, p, o;
                        s = this.SaveNode(t.Subject);
                        p = this.SaveNode(t.Predicate);
                        o = this.SaveNode(t.Object);
                        String getTripleID = "SELECT tripleID FROM TRIPLES WHERE tripleSubject=" + s + " AND triplePredicate=" + p + " AND tripleObject=" + o;
                        Object tripleID = this.ExecuteScalar(getTripleID);
                        if (tripleID != null)
                        {
                            return Int32.Parse(tripleID.ToString());
                        }
                        else
                        {
                            id = ++this._nextTripleID;
                            createRequired = true;
                        }
                    }
                }
                else
                {
                    id = ++this._nextTripleID;
                    this._tripleIDs.Add(t.GetHashCode(), id);
                    createRequired = true;
                }
            }
            finally
            {
                Monitor.Exit(this._tripleIDs);
            }
            if (id != -1)
            {
                return id;
            }
            else
            {
                throw new RdfStorageException("Error obtaining a Triple ID");
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:73,代码来源:BaseStoreManager.cs

示例3: 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);

        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:81,代码来源:BasicTests1.cs

示例4: GetIndexNameForTriple

 protected override string GetIndexNameForTriple(Triple t)
 {
     return @"index\spo\" + this.GetHash(t.GetHashCode().ToString());
 }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:4,代码来源:FileIndexManager.cs

示例5: RemoveTriple

        /// <summary>
        /// Removes a Triple from a Graphs Database record
        /// </summary>
        /// <param name="t">Triple to remove</param>
        /// <param name="graphID">Database Graph ID</param>
        public override void RemoveTriple(Triple t, string graphID)
        {
            //If the Triple being removed is in the Buffer to be added still remove it
            lock (this._writerBuffer)
            {
                this._writerBuffer.Remove(new BatchTriple(t, graphID));
            }

            //Does the Triple have a known Database ID
            if (this._tripleIDs.ContainsKey(t.GetHashCode()))
            {
                //Can use the existing ID
                int id = this._tripleIDs[t.GetHashCode()];
                String removeTriple = "DELETE FROM GRAPH_TRIPLES WHERE graphID=" + graphID + " AND tripleID=" + id;
                try
                {
                    this.Open(false);
                    this.ExecuteNonQuery(removeTriple);
                    this.Close(false);
                }
                catch (SqlException sqlEx)
                {
                    this.Close(true, true);
                    throw new RdfStorageException("Unable to unlink a Triple record to a Graph in the Database", sqlEx);
                }

            }
            else
            {
                //Get the IDs for the Nodes
                String s, p, o;
                s = this.SaveNode(t.Subject);
                p = this.SaveNode(t.Predicate);
                o = this.SaveNode(t.Object);

                //Does the Triple exist in the Database
                String getTriple = "SELECT tripleID FROM TRIPLES WHERE tripleHash=" + t.GetHashCode();
                Object id = this.ExecuteScalar(getTriple);
                if (id == null)
                {
                    //Nothing to do since the Triple isn't in the Database and thus can't be linked to the Graph for unlinking to be needed
                }
                else
                {
                    //Remove the link to the Triple
                    String removeTriple = "DELETE FROM GRAPH_TRIPLES WHERE graphID=" + graphID + " AND tripleID=" + id.ToString();
                    try
                    {
                        this.Open(false);
                        this.ExecuteNonQuery(removeTriple);
                        this.Close(false);
                    }
                    catch (SqlException sqlEx)
                    {
                        this.Close(true, true);
                        throw new RdfStorageException("Unable to unlink a Triple record to a Graph in the Database", sqlEx);
                    }
                }
            }
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:65,代码来源:MicrosoftSqlStoreManager.cs

示例6: LoadTriples

        /// <summary>
        /// Loads Triples for the Graph with the given ID into the given Graph object
        /// </summary>
        /// <param name="g">Graph to load into</param>
        /// <param name="graphID">Database Graph ID</param>
        public override void LoadTriples(IGraph g, string graphID)
        {
            //Build the SQL for getting the Triples
            String getTriples = "SELECT * FROM GRAPH_TRIPLES G INNER JOIN TRIPLES T ON G.tripleID=T.tripleID WHERE G.graphID=" + graphID;

            //Get the Data
            this.Open(true);
            DataTable data = this.ExecuteQuery(getTriples);

            //Load the Triples
            String s, p, o;
            INode subj, pred, obj;
            foreach (DataRow r in data.Rows)
            {
                //Get the IDs
                s = r["tripleSubject"].ToString();
                p = r["triplePredicate"].ToString();
                o = r["tripleObject"].ToString();

                //Get the Nodes from these IDs
                subj = this.LoadNode(g, s);
                pred = this.LoadNode(g, p);
                obj = this.LoadNode(g, o);

                Triple t = new Triple(subj, pred, obj);
                g.Assert(t);

                //Store ID for later
                try
                {
                    Monitor.Enter(this._tripleIDs);
                    if (!this._tripleIDs.ContainsKey(t.GetHashCode()))
                    {
                        int id = Int32.Parse(r["tripleID"].ToString());
                        this._tripleIDs.Add(t.GetHashCode(), id);
                    }
                }
                finally
                {
                    Monitor.Exit(this._tripleIDs);
                }
            }

            //Close the Database Connection
            this.Close(true);
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:51,代码来源:MicrosoftSqlStoreManager.cs


注:本文中的Triple.GetHashCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。