Beispiel #1
0
        public void Equals()
        {
            Triple <int, string, double> p1 = new Triple <int, string, double>(42, new string('z', 3), 4.5);
            Triple <int, string, double> p2 = new Triple <int, string, double>(53, new string('z', 3), 4.5);
            Triple <int, string, double> p3 = new Triple <int, string, double>(42, new string('z', 4), 2.1);
            Triple <int, string, double> p4 = new Triple <int, string, double>(42, new string('z', 3), 4.5);
            Triple <int, string, double> p5 = new Triple <int, string, double>(122, new string('y', 3), 3.14);
            Triple <int, string, double> p6 = new Triple <int, string, double>(122, null, 3.14);
            Triple <int, string, double> p7 = new Triple <int, string, double>(122, null, 3.14);
            bool f;

            f = p1.Equals(p2); Assert.IsFalse(f);
            f = p1.Equals(p3); Assert.IsFalse(f);
            f = p1.Equals(p4); Assert.IsTrue(f);
            f = p1.Equals(p5); Assert.IsFalse(f);
            f = p1.Equals("hi"); Assert.IsFalse(f);
            f = p6.Equals(p7); Assert.IsTrue(f);
            f = p1 == p2; Assert.IsFalse(f);
            f = p1 == p3; Assert.IsFalse(f);
            f = p1 == p4; Assert.IsTrue(f);
            f = p1 == p5; Assert.IsFalse(f);
            f = p6 == p7; Assert.IsTrue(f);
            f = p1 != p2; Assert.IsTrue(f);
            f = p1 != p3; Assert.IsTrue(f);
            f = p1 != p4; Assert.IsFalse(f);
            f = p1 != p5; Assert.IsTrue(f);
            f = p6 != p7; Assert.IsFalse(f);
        }
Beispiel #2
0
        public void Test_Equals()
        {
            var tripOne = new Triple("12.3.4");
            var tripTwo = new Triple("12.3.4");

            // two instances should be equal
            Assert.IsTrue(tripOne.Equals(tripTwo));
            Assert.IsTrue(tripTwo.Equals(tripOne));
            // self equality
            Assert.IsTrue(tripOne.Equals(tripOne));
            Assert.IsTrue(tripTwo.Equals(tripTwo));
        }
Beispiel #3
0
        public void EqualUncomparable()
        {
            var triple1 = new Triple <Unorderable, int, string>(new Unorderable(), 5, "hello");
            var triple2 = new Triple <Unorderable, int, string>(new Unorderable(), 7, "world");
            var triple3 = new Triple <Unorderable, int, string>(new Unorderable(), 5, "hello");

            Assert.IsFalse(triple1.Equals(triple2));
            Assert.IsTrue(triple1.Equals(triple3));
            Assert.IsFalse(triple1 == triple2);
            Assert.IsTrue(triple1 == triple3);

            Assert.IsFalse(triple1.GetHashCode() == triple2.GetHashCode());
            Assert.IsTrue(triple1.GetHashCode() == triple3.GetHashCode());
        }
Beispiel #4
0
        public bool Equals(SudokuRowHeader other)
        {
            if (other == null || this == null)
            {
                return(false);
            }

            return(cellLabel.Equals(other.cellLabel));
        }
Beispiel #5
0
        /// <summary>
        /// Determines whether this instance is equal to another given node.
        /// </summary>
        /// <param name="other">The other node to compare this instance to.</param>
        /// <returns>
        /// <c>true</c> if the given node is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public bool Equals(Node other)
        {
            //
            // edge case for null values

            if ((object)other == null)
            {
                return(false);
            }

            //
            // for two nodes to be equal the representing variable or atom needs to be the same for
            // both nodes, they need to contain the same SAP, and they need to contain the same
            // operator. the trick for nodes in a join graph is that they don't always contain all
            // of these values.

            if (m_item == null)
            {
                if (other.m_item != null)
                {
                    return(false);
                }
            }
            else if (!m_item.Equals(other.m_item))
            {
                return(false);
            }

            if (m_sap == null)
            {
                if (other.m_sap != null)
                {
                    return(false);
                }
            }
            else if (!m_sap.Equals(other.m_sap))
            {
                return(false);
            }

            if (m_operator == null)
            {
                if (other.m_operator != null)
                {
                    return(false);
                }
            }
            else if (!ReferenceEquals(m_operator, other.m_operator))
            {
                return(false);
            }

            return(true);
        }
Beispiel #6
0
 /// <summary>
 /// Equality for Batch Triples.
 /// </summary>
 /// <param name="obj">Object to test.</param>
 /// <returns></returns>
 public override bool Equals(object obj)
 {
     if (obj is BatchTriple)
     {
         BatchTriple other = (BatchTriple)obj;
         return(_graphID == other.GraphID && _t.Equals(other.Triple));
     }
     else
     {
         return(false);
     }
 }
        /// <summary>
        /// Merges multiple ResultObjects of different categories to a single list of ContentObjects.
        /// The merge is based on a set of weights.
        /// </summary>
        /// <param name="results">An array of different ResultObjects for several categories</param>
        /// <param name="ratio">An array with weights for the different categories in the results array</param>
        /// <returns>A list of ContentObjects where the content's value is the weighted score per category. The list is sorted in descending order (the higher the value, the earlier in the list)</returns>
        public List <ContentObject> Merge(ResultObject[] results, CategoryRatio ratio)
        {
            // Attetion! No sanity checks: Must be different result.categories, ratios must sum up to 1.
            List <ContentObject>  totalResults = new List <ContentObject>();
            List <List <Triple> > scores       = Prepare(results);

            while (scores.Count > 0)
            {
                List <Triple> list = Pop(scores);
                while (list.Count > 0)
                {
                    Triple needle = Pop(list);
                    bool   lonely = true;
                    foreach (List <Triple> haystack in scores)
                    {
                        int size = haystack.Count;
                        for (int i = 0; i < size; i++)
                        {
                            if (needle.Equals(haystack[i]))
                            {
                                Triple t = haystack[i];
                                totalResults.Add(MergeWeighted(needle.Key, new [] { needle.Score, t.Score }, new [] { ratio.GetRatio(needle.Category), ratio.GetRatio(t.Category) }));
                                haystack.Remove(t);
                                size--;
                                lonely = false;
                            }
                        }
                    }
                    if (lonely)
                    {
                        double weightedScore = needle.Score * ratio.GetRatio(needle.Category);
                        totalResults.Add(new ContentObject(needle.Key, weightedScore.ToString()));
                    }
                }
            }
            totalResults.Sort((a, b) => - 1 * a.CompareTo(b));


            return(totalResults);
        }
Beispiel #8
0
        /// <summary>
        /// Determines whether this instance is equal to another given edge label.
        /// </summary>
        /// <param name="other">The other edge label to compare this instance to.</param>
        /// <returns>
        /// <c>true</c> if the given edge label is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public bool Equals(EdgeLabel other)
        {
            //
            // edge case for null values

            if ((object)other == null)
            {
                return(false);
            }

            //
            // two edge labels are equal if all items in both labels are equal

            if (!m_left.Equals(other.m_left))
            {
                return(false);
            }

            if (!m_right.Equals(other.m_right))
            {
                return(false);
            }

            if (!m_sharedItem.Equals(other.m_sharedItem))
            {
                return(false);
            }

            if (!m_posLeft.Equals(other.m_posLeft))
            {
                return(false);
            }

            if (!m_posRight.Equals(other.m_posRight))
            {
                return(false);
            }

            return(true);
        }
            public static bool foundNodeMoreThanTriple(IGraph g, INode n, Triple triple)
            {
                var          found  = g.GetTriples(n);
                int          others = 0;
                StringWriter sw     = new StringWriter();

                foreach (var t in found)
                {
                    if (!triple.Equals(t))
                    {
                        others++;
                    }
                    sw.WriteLine("found " + t);
                }
                if (others > 0)
                {
                    return(true);
                }
                string warning = string.Format("cant resolve list node {0} but found {1}", n, sw);

                Warn(warning);
                return(false);
            }
Beispiel #10
0
        public void Test_Equals_negative()
        {
            // two different numbers should not be equal
            var tripOne = new Triple("12.3.4");
            var tripTwo = new Triple("12.1.2");

            Assert.IsFalse(tripOne.Equals(tripTwo));
            Assert.IsFalse(tripTwo.Equals(tripOne));

            tripOne = new Triple("1.2.3");
            tripTwo = new Triple("2.4.6");
            Assert.IsFalse(tripOne.Equals(tripTwo));
            Assert.IsFalse(tripTwo.Equals(tripOne));

            tripOne = new Triple("1.2.3");
            tripTwo = new Triple("1.4.6");
            Assert.IsFalse(tripOne.Equals(tripTwo));
            Assert.IsFalse(tripTwo.Equals(tripOne));

            tripOne = new Triple("1.2.3");
            tripTwo = new Triple("1.2.6");
            Assert.IsFalse(tripOne.Equals(tripTwo));
            Assert.IsFalse(tripTwo.Equals(tripOne));
        }
        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();
            }
        }
Beispiel #12
0
        public void GenericComparable()
        {
            Triple <int, GOddEvenComparable, string> triple1, triple2;

            triple1 = new Triple <int, GOddEvenComparable, string>(4, new GOddEvenComparable(7), "B");
            triple2 = new Triple <int, GOddEvenComparable, string>(7, new GOddEvenComparable(3), "A");
            Assert.IsTrue(triple1.CompareTo(triple2) < 0);
            Assert.IsFalse(triple1.Equals(triple2));
            Assert.IsFalse(triple1.GetHashCode() == triple2.GetHashCode());

            triple1 = new Triple <int, GOddEvenComparable, string>(4, new GOddEvenComparable(7), "B");
            triple2 = new Triple <int, GOddEvenComparable, string>(4, new GOddEvenComparable(2), "A");
            Assert.IsTrue(triple1.CompareTo(triple2) < 0);
            Assert.IsFalse(triple1.Equals(triple2));
            Assert.IsFalse(triple1.GetHashCode() == triple2.GetHashCode());

            triple1 = new Triple <int, GOddEvenComparable, string>(4, new GOddEvenComparable(7), "A");
            triple2 = new Triple <int, GOddEvenComparable, string>(4, new GOddEvenComparable(7), "A");
            Assert.IsTrue(triple1.CompareTo(triple2) == 0);
            Assert.IsTrue(triple1.Equals(triple2));
            Assert.IsTrue(triple1.GetHashCode() == triple2.GetHashCode());

            triple1 = new Triple <int, GOddEvenComparable, string>(7, new GOddEvenComparable(7), "B");
            triple2 = new Triple <int, GOddEvenComparable, string>(4, new GOddEvenComparable(2), "C");
            Assert.IsTrue(triple1.CompareTo(triple2) > 0);
            Assert.IsFalse(triple1.Equals(triple2));
            Assert.IsFalse(triple1.GetHashCode() == triple2.GetHashCode());

            triple1 = new Triple <int, GOddEvenComparable, string>(0, new GOddEvenComparable(8), "A");
            triple2 = new Triple <int, GOddEvenComparable, string>(0, new GOddEvenComparable(2), "A");
            Assert.IsTrue(triple1.CompareTo(triple2) > 0);
            Assert.IsFalse(triple1.Equals(triple2));
            Assert.IsFalse(triple1.GetHashCode() == triple2.GetHashCode());

            Triple <GOddEvenComparable, int, string> triple3, triple4;

            triple3 = new Triple <GOddEvenComparable, int, string>(new GOddEvenComparable(7), 4, "A");
            triple4 = new Triple <GOddEvenComparable, int, string>(new GOddEvenComparable(3), 7, "B");
            Assert.IsTrue(triple3.CompareTo(triple4) > 0);
            Assert.IsFalse(triple3.Equals(triple4));
            Assert.IsFalse(triple3.GetHashCode() == triple4.GetHashCode());

            triple3 = new Triple <GOddEvenComparable, int, string>(new GOddEvenComparable(7), 4, "B");
            triple4 = new Triple <GOddEvenComparable, int, string>(new GOddEvenComparable(2), 4, "A");
            Assert.IsTrue(triple3.CompareTo(triple4) < 0);
            Assert.IsFalse(triple3.Equals(triple4));
            Assert.IsFalse(triple3.GetHashCode() == triple4.GetHashCode());

            triple3 = new Triple <GOddEvenComparable, int, string>(new GOddEvenComparable(7), 4, "C");
            triple4 = new Triple <GOddEvenComparable, int, string>(new GOddEvenComparable(7), 4, "C");
            Assert.IsTrue(triple3.CompareTo(triple4) == 0);
            Assert.IsTrue(triple3.Equals(triple4));
            Assert.IsTrue(triple3.GetHashCode() == triple4.GetHashCode());

            triple3 = new Triple <GOddEvenComparable, int, string>(new GOddEvenComparable(2), 7, "A");
            triple4 = new Triple <GOddEvenComparable, int, string>(new GOddEvenComparable(7), 4, "B");
            Assert.IsTrue(triple3.CompareTo(triple4) > 0);
            Assert.IsFalse(triple3.Equals(triple4));
            Assert.IsFalse(triple3.GetHashCode() == triple4.GetHashCode());

            triple3 = new Triple <GOddEvenComparable, int, string>(new GOddEvenComparable(8), 0, "A");
            triple4 = new Triple <GOddEvenComparable, int, string>(new GOddEvenComparable(2), 0, "A");
            Assert.IsTrue(triple3.CompareTo(triple4) > 0);
            Assert.IsFalse(triple3.Equals(triple4));
            Assert.IsFalse(triple3.GetHashCode() == triple4.GetHashCode());

            triple3 = new Triple <GOddEvenComparable, int, string>(new GOddEvenComparable(2), 4, "A");
            triple4 = new Triple <GOddEvenComparable, int, string>(new GOddEvenComparable(2), 3, "B");
            Assert.IsTrue(triple3.CompareTo(triple4) > 0);
            Assert.IsFalse(triple3.Equals(triple4));
            Assert.IsFalse(triple3.GetHashCode() == triple4.GetHashCode());

            Triple <int, string, GOddEvenComparable> triple5, triple6;

            triple5 = new Triple <int, string, GOddEvenComparable>(4, "B", new GOddEvenComparable(7));
            triple6 = new Triple <int, string, GOddEvenComparable>(7, "A", new GOddEvenComparable(3));
            Assert.IsTrue(triple5.CompareTo(triple6) < 0);
            Assert.IsFalse(triple5.Equals(triple6));
            Assert.IsFalse(triple5.GetHashCode() == triple6.GetHashCode());

            triple5 = new Triple <int, string, GOddEvenComparable>(4, "A", new GOddEvenComparable(7));
            triple6 = new Triple <int, string, GOddEvenComparable>(4, "A", new GOddEvenComparable(2));
            Assert.IsTrue(triple5.CompareTo(triple6) < 0);
            Assert.IsFalse(triple5.Equals(triple6));
            Assert.IsFalse(triple5.GetHashCode() == triple6.GetHashCode());

            triple5 = new Triple <int, string, GOddEvenComparable>(4, "A", new GOddEvenComparable(7));
            triple6 = new Triple <int, string, GOddEvenComparable>(4, "A", new GOddEvenComparable(7));
            Assert.IsTrue(triple5.CompareTo(triple6) == 0);
            Assert.IsTrue(triple5.Equals(triple6));
            Assert.IsTrue(triple5.GetHashCode() == triple6.GetHashCode());

            triple5 = new Triple <int, string, GOddEvenComparable>(7, "B", new GOddEvenComparable(7));
            triple6 = new Triple <int, string, GOddEvenComparable>(4, "C", new GOddEvenComparable(2));
            Assert.IsTrue(triple5.CompareTo(triple6) > 0);
            Assert.IsFalse(triple5.Equals(triple6));
            Assert.IsFalse(triple5.GetHashCode() == triple6.GetHashCode());

            triple5 = new Triple <int, string, GOddEvenComparable>(0, "A", new GOddEvenComparable(8));
            triple6 = new Triple <int, string, GOddEvenComparable>(0, "A", new GOddEvenComparable(2));
            Assert.IsTrue(triple5.CompareTo(triple6) > 0);
            Assert.IsFalse(triple5.Equals(triple6));
            Assert.IsFalse(triple5.GetHashCode() == triple6.GetHashCode());
        }
Beispiel #13
0
        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);

        }