示例#1
0
        public void GraphHardMatch2()
        {
            IGraph g = new Graph();
            IGraph h = new Graph();

            int    size = 1 << Dimension;
            Random rnd  = new Random();

            for (int i = 0; i < Runs; i++)
            {
                int a = rnd.Next(size);

                DiHypercube hc1 = new DiHypercube(Dimension, g);
                hc1 = hc1.Duplicate(a).Duplicate(a).Duplicate(a);
                DiHypercube hc2 = new DiHypercube(Dimension, h);
                hc2 = hc2.Duplicate(a).Duplicate(a).Duplicate(a);

                if (i == 0)
                {
                    TestTools.ShowGraph(g);
                    Console.WriteLine();
                    TestTools.ShowGraph(h);
                }

                Assert.IsTrue(g.Equals(h), "Graphs should be equal");
                Console.WriteLine("Run #" + (i + 1) + " passed OK");

                g = new Graph();
                h = new Graph();
            }
        }
示例#2
0
        private INode TestListsBasic(IGraph g)
        {
            List <INode> items    = Enumerable.Range(1, 10).Select(i => i.ToLiteral(g)).OfType <INode>().ToList();
            INode        listRoot = g.AssertList(items);

            TestTools.ShowGraph(g);

            Assert.AreEqual(items.Count * 2, g.Triples.Count, "Expected " + (items.Count * 2) + " Triples");
            List <INode> listItems = g.GetListItems(listRoot).ToList();

            Assert.AreEqual(items.Count, listItems.Count, "Expected " + items.Count + " Items in the List");

            for (int i = 0; i < items.Count; i++)
            {
                Assert.AreEqual(items[i], listItems[i], "Items were not in list in correct order");
            }

            Assert.IsTrue(listRoot.IsListRoot(g), "Should be considered a list root");

            List <INode> listNodes = g.GetListNodes(listRoot).Skip(1).ToList();

            foreach (INode n in listNodes)
            {
                Assert.IsFalse(n.IsListRoot(g), "Should not be considered a list root");
            }

            return(listRoot);
        }
示例#3
0
 public void HandleGraphRemoved(Object sender, TripleStoreEventArgs args)
 {
     this._graphRemoved = true;
     Console.WriteLine("GraphRemoved event occurred on a " + sender.GetType().Name + " instance");
     TestTools.ShowGraph(args.GraphEvent.Graph);
     Console.WriteLine();
 }
示例#4
0
        public void PelletIcv()
        {
            PelletServer server  = new PelletServer(PelletTestServer);
            Type         svcType = typeof(IntegrityConstraintValidationService);

            foreach (KnowledgeBase kb in server.KnowledgeBases)
            {
                if (kb.SupportsService(svcType))
                {
                    Console.WriteLine(kb.Name + " supports ICV");
                    IntegrityConstraintValidationService svc = (IntegrityConstraintValidationService)kb.GetService(svcType);

                    ITripleStore store = svc.Validate();
                    Console.WriteLine("ICV returned " + store.Graphs.Count + " with " + store.Graphs.Sum(g => g.Triples.Count) + " Triples");

                    foreach (Graph g in store.Graphs)
                    {
                        TestTools.ShowGraph(g);
                        Console.WriteLine();
                    }
                }
                else
                {
                    Console.WriteLine(kb.Name + " does not support the ICV Service");
                }
                Console.WriteLine();
            }
        }
示例#5
0
        public void GraphHardMatchStar()
        {
            for (int i = 0; i < Runs; i++)
            {
                IGraph g = this.GenerateStarGraph(StarNodes);
                IGraph h = this.GenerateStarGraph(StarNodes);

                if (i == 0)
                {
                    TestTools.ShowGraph(g);
                    TestTools.ShowGraph(h);
                }

                Assert.AreEqual(g, h, "Graphs should have been equal");

                Console.WriteLine("Run #" + (i + 1) + " Passed");
            }
        }
示例#6
0
        public void GraphHardMatchCyclic2()
        {
            Random rnd = new Random();

            for (int i = 0; i < Runs; i++)
            {
                IGraph g = this.GenerateCyclicGraph(CycleNodes, rnd.Next(CycleNodes), CycleDropNodes);
                IGraph h = this.GenerateCyclicGraph(CycleNodes, rnd.Next(CycleNodes), CycleDropNodes);

                if (i == 0)
                {
                    TestTools.ShowGraph(g);
                    TestTools.ShowGraph(h);
                }

                Assert.AreEqual(g, h, "Graphs should be equal");
                Console.WriteLine("Run #" + (i + 1) + " Passed");
            }
        }
示例#7
0
        public void PelletRealize()
        {
            PelletServer server  = new PelletServer(PelletTestServer);
            Type         svcType = typeof(RealizeService);

            foreach (KnowledgeBase kb in server.KnowledgeBases)
            {
                if (kb.SupportsService(svcType))
                {
                    Console.WriteLine(kb.Name + " supports Realize");
                    RealizeService svc = (RealizeService)kb.GetService(svcType);
                    IGraph         g   = svc.Realize();
                    TestTools.ShowGraph(g);
                }
                else
                {
                    Console.WriteLine(kb.Name + " does not support the Realize Service");
                }
                Console.WriteLine();
            }
        }
示例#8
0
        public void PelletPredict()
        {
            PelletServer server  = new PelletServer(PelletTestServer);
            Type         svcType = typeof(PredictService);

            foreach (KnowledgeBase kb in server.KnowledgeBases)
            {
                if (kb.SupportsService(svcType))
                {
                    Console.WriteLine(kb.Name + " supports Prediction");
                    PredictService svc = (PredictService)kb.GetService(svcType);

                    IGraph g = svc.PredictRaw("wine:DAnjou", "wine:locatedIn");
                    TestTools.ShowGraph(g);
                }
                else
                {
                    Console.WriteLine(kb.Name + " does not support the Prediction Service");
                }
                Console.WriteLine();
            }
        }
示例#9
0
        public void PelletSimilarity()
        {
            PelletServer server  = new PelletServer(PelletTestServer);
            Type         svcType = typeof(SimilarityService);

            foreach (KnowledgeBase kb in server.KnowledgeBases)
            {
                if (kb.SupportsService(svcType))
                {
                    Console.WriteLine(kb.Name + " supports Similarity");
                    SimilarityService svc = (SimilarityService)kb.GetService(svcType);

                    IGraph g = svc.SimilarityRaw(5, "wine:Red");
                    TestTools.ShowGraph(g);
                }
                else
                {
                    Console.WriteLine(kb.Name + " does not support the Similarity Service");
                }
                Console.WriteLine();
            }
        }
示例#10
0
        public void GraphLists2()
        {
            Graph g        = new Graph();
            INode listRoot = this.TestListsBasic(g);

            //Try extending the list
            List <INode> items = Enumerable.Range(11, 10).Select(i => i.ToLiteral(g)).OfType <INode>().ToList();

            g.AddToList(listRoot, items);
            TestTools.ShowGraph(g);

            Assert.AreEqual(items.Count * 4, g.Triples.Count, "Expected " + (items.Count * 4) + " Triples");
            List <INode> listItems = g.GetListItems(listRoot).ToList();

            Assert.AreEqual(items.Count * 2, listItems.Count, "Expected " + (items.Count * 2) + " Items in the List");

            for (int i = 0; i < items.Count; i++)
            {
                Assert.AreEqual(items[i], listItems[i + 10], "Items were not in list in correct order");
            }

            g.RetractList(listRoot);
            Assert.AreEqual(0, g.Triples.Count, "Should be no triples after the list is retracted");
        }
示例#11
0
        public void GraphLists3()
        {
            Graph g        = new Graph();
            INode listRoot = this.TestListsBasic(g);

            //Try removing items from the list
            List <INode> items = Enumerable.Range(1, 10).Where(i => i % 2 == 0).Select(i => i.ToLiteral(g)).OfType <INode>().ToList();

            g.RemoveFromList(listRoot, items);
            TestTools.ShowGraph(g);

            Assert.AreEqual(items.Count * 2, g.Triples.Count, "Expected " + (items.Count * 2) + " Triples");
            List <INode> listItems = g.GetListItems(listRoot).ToList();

            Assert.AreEqual(items.Count * 2, listItems.Count * 2, "Expected " + (items.Count * 2) + " Items in the List");

            for (int i = 0; i < items.Count; i++)
            {
                Assert.IsFalse(listItems.Contains(items[i]), "Item " + items[i].ToString() + " which should have been removed from the list is still present");
            }

            g.RetractList(listRoot);
            Assert.AreEqual(0, g.Triples.Count, "Should be no triples after the list is retracted");
        }
示例#12
0
        public void GraphLists2()
        {
            Graph g        = new Graph();
            INode listRoot = this.TestListsBasic(g);

            //Try extending the list
            List <INode> items = Enumerable.Range(11, 10).Select(i => i.ToLiteral(g)).OfType <INode>().ToList();

            g.AddToList(listRoot, items);
            TestTools.ShowGraph(g);

            Assert.Equal(items.Count * 4, g.Triples.Count);
            List <INode> listItems = g.GetListItems(listRoot).ToList();

            Assert.Equal(items.Count * 2, listItems.Count);

            for (int i = 0; i < items.Count; i++)
            {
                Assert.Equal(items[i], listItems[i + 10]);
            }

            g.RetractList(listRoot);
            Assert.Equal(0, g.Triples.Count);
        }