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


C# Graph.Difference方法代码示例

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


在下文中一共展示了Graph.Difference方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GraphDiffEqualGraphs2

        public void GraphDiffEqualGraphs2()
        {
            Graph g = new Graph();
            Graph h = new Graph();
            FileLoader.Load(g, "InferenceTest.ttl");
            FileLoader.Load(h, "InferenceTest.ttl");

            GraphDiffReport report = g.Difference(h);
            TestTools.ShowDifferences(report);

            Assert.IsTrue(report.AreEqual, "Graphs should be equal");
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:12,代码来源:GraphDiffTests.cs

示例2: GraphDiffDifferentGraphs

        public void GraphDiffDifferentGraphs()
        {
            Graph g = new Graph();
            Graph h = new Graph();
            FileLoader.Load(g, "InferenceTest.ttl");
            FileLoader.Load(h, "Turtle.ttl");

            GraphDiffReport report = g.Difference(h);
            TestTools.ShowDifferences(report);

            Assert.IsFalse(report.AreEqual, "Graphs should not be equal");
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:12,代码来源:GraphDiffTests.cs

示例3: StorageSparqlUniformHttpProtocolSaveGraph

        public void StorageSparqlUniformHttpProtocolSaveGraph()
        {
            try
            {
                Options.UriLoaderCaching = false;

                Graph g = new Graph();
                FileLoader.Load(g, "Turtle.ttl");
                g.BaseUri = new Uri("http://example.org/sparqlTest");

                //Save Graph to SPARQL Uniform Protocol
                SparqlHttpProtocolConnector sparql = new SparqlHttpProtocolConnector(new Uri(ProtocolTestUri));
                sparql.SaveGraph(g);
                Console.WriteLine("Graph saved to SPARQL Uniform Protocol OK");

                //Now retrieve Graph from SPARQL Uniform Protocol
                Graph h = new Graph();
                sparql.LoadGraph(h, "http://example.org/sparqlTest");

                Console.WriteLine();
                foreach (Triple t in h.Triples)
                {
                    Console.WriteLine(t.ToString(this._formatter));
                }

                GraphDiffReport diff = g.Difference(h);
                if (!diff.AreEqual)
                {
                    Console.WriteLine();
                    Console.WriteLine("Graphs are different - should be 1 difference due to New Line Normalization");
                    Console.WriteLine("Added Triples");
                    foreach (Triple t in diff.AddedTriples)
                    {
                        Console.WriteLine(t.ToString(this._formatter));
                    }
                    Console.WriteLine("Removed Triples");
                    foreach (Triple t in diff.RemovedTriples)
                    {
                        Console.WriteLine(t.ToString(this._formatter));
                    }

                    Assert.IsTrue(diff.AddedTriples.Count() == 1, "Should only be 1 Triple difference due to New Line normalization");
                    Assert.IsTrue(diff.RemovedTriples.Count() == 1, "Should only be 1 Triple difference due to New Line normalization");
                    Assert.IsFalse(diff.AddedMSGs.Any(), "Should not be any MSG differences");
                    Assert.IsFalse(diff.RemovedMSGs.Any(), "Should not be any MSG differences");
                }
            }
            finally
            {
                Options.UriLoaderCaching = true;
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:52,代码来源:SparqlUniformHttpProtocolTest.cs

示例4: GraphDiffRemovedGroundTriples

        public void GraphDiffRemovedGroundTriples()
        {
            Graph g = new Graph();
            Graph h = new Graph();
            FileLoader.Load(g, "InferenceTest.ttl");
            FileLoader.Load(h, "InferenceTest.ttl");

            //Remove Triples about Ford Fiestas from 2nd Graph
            h.Retract(h.GetTriplesWithSubject(new Uri("http://example.org/vehicles/FordFiesta")));

            GraphDiffReport report = g.Difference(h);
            TestTools.ShowDifferences(report);

            Assert.IsFalse(report.AreEqual, "Graphs should not have been reported as equal");
            Assert.IsTrue(report.RemovedTriples.Any(), "Difference should have reported some Removed Triples");
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:16,代码来源:GraphDiffTests.cs

示例5: ParsingUsingPagingHandler

        public void ParsingUsingPagingHandler(String tempFile, IRdfReader parser)
        {
            Graph g = new Graph();
            EmbeddedResourceLoader.Load(g, "VDS.RDF.Configuration.configuration.ttl");
            g.SaveToFile(tempFile);

            Graph h = new Graph();
            PagingHandler handler = new PagingHandler(new GraphHandler(h), 25);
            parser.Load(handler, tempFile);
            h.Retract(h.Triples.Where(t => !t.IsGroundTriple));

            NTriplesFormatter formatter = new NTriplesFormatter();
            foreach (Triple t in h.Triples)
            {
                Console.WriteLine(t.ToString(formatter));
            }
            Console.WriteLine();

            Assert.IsFalse(h.IsEmpty, "Graph should not be empty");
            Assert.IsTrue(h.Triples.Count <= 25, "Graphs should have <= 25 Triples");

            Graph i = new Graph();
            handler = new PagingHandler(new GraphHandler(i), 25, 25);
            parser.Load(handler, tempFile);
            i.Retract(i.Triples.Where(t => !t.IsGroundTriple));

            foreach (Triple t in i.Triples)
            {
                Console.WriteLine(t.ToString(formatter));
            }
            Console.WriteLine();

            Assert.IsFalse(i.IsEmpty, "Graph should not be empty");
            Assert.IsTrue(i.Triples.Count <= 25, "Graphs should have <= 25 Triples");

            GraphDiffReport report = h.Difference(i);
            Assert.IsFalse(report.AreEqual, "Graphs should not be equal");
            Assert.AreEqual(i.Triples.Count, report.AddedTriples.Count(), "Should be " + i.Triples.Count + " added Triples");
            Assert.AreEqual(h.Triples.Count, report.RemovedTriples.Count(), "Should be " + h.Triples.Count + " removed Triples");
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:40,代码来源:PagingHandlerTests.cs

示例6: TestBinarySearch

        private void TestBinarySearch(IComparer<Triple> comparer, INode s, INode p, INode o, Func<IGraph,Triple,List<Triple>> getExpected)
        {
            IGraph g = this.EnsureTestData();

            ITripleFormatter formatter = new UncompressedNotation3Formatter();
            List<Triple> index = new List<Triple>(g.Triples);
            index.Sort(comparer);

            for (int i = 1; i <= 10000; i++)
            {
                Console.WriteLine("Run #" + i);
                Console.WriteLine();

                INode subj, pred, obj;
                if (s != null)
                {
                    subj = s;
                }
                else
                {
                    subj = g.Triples.Skip(this._rnd.Next(0, g.Triples.Count - 1)).First().Subject;
                }
                if (p != null)
                {
                    pred = p;
                }
                else
                {
                    pred = g.Triples.Skip(this._rnd.Next(0, g.Triples.Count - 1)).First().Predicate;
                }
                if (o != null)
                {
                    obj = o;
                }
                else
                {
                    obj = g.Triples.Skip(this._rnd.Next(0, g.Triples.Count - 1)).First().Object;
                }

                Triple search = new Triple(subj, pred, obj);
                Console.WriteLine("Searching For " + search.ToString(formatter));
                Console.WriteLine();

                List<Triple> expected = getExpected(g, search);
                expected.Sort();
                Console.WriteLine("Expecting " + expected.Count + " Triple(s)");

                List<Triple> actual = index.SearchIndex<Triple>(comparer, search).ToList();
                actual.Sort();
                Console.WriteLine("Got " + actual.Count + " Triple(s)");

                Graph x = new Graph();
                x.Assert(expected);
                Graph y = new Graph();
                y.Assert(actual);

                GraphDiffReport report = x.Difference(y);
                if (!report.AreEqual)
                {
                    Console.WriteLine("Run #" + i + " Failed!");

                    Console.WriteLine("Expected Triples:");
                    foreach (Triple t in x.Triples)
                    {
                        Console.WriteLine(t.ToString(formatter));
                    }
                    Console.WriteLine();

                    Console.WriteLine("Actual Triples:");
                    foreach (Triple t in y.Triples)
                    {
                        Console.WriteLine(t.ToString(formatter));
                    }

                    TestTools.ShowDifferences(report);
                }

                Assert.AreEqual(expected.Count, actual.Count, "Failed Count Check on Run #" + i);
                Assert.IsTrue(expected.All(t => actual.Contains(t)), "Failed Equality Check on Run #" + i);
                Console.WriteLine("Run #" + i + " Passed OK");

                Console.WriteLine();
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:84,代码来源:IndexingTests.cs

示例7: GraphDiffAddedMSG

        public void GraphDiffAddedMSG()
        {
            Graph g = new Graph();
            Graph h = new Graph();
            FileLoader.Load(g, "InferenceTest.ttl");
            FileLoader.Load(h, "InferenceTest.ttl");

            //Add additional Triple to 2nd Graph
            INode blank = h.CreateBlankNode();
            IUriNode subClass = h.CreateUriNode("rdfs:subClassOf");
            IUriNode vehicle = h.CreateUriNode("eg:Vehicle");
            h.Assert(new Triple(blank, subClass, vehicle));

            GraphDiffReport report = g.Difference(h);
            TestTools.ShowDifferences(report);

            Assert.IsFalse(report.AreEqual, "Graphs should not have been reported as equal");
            Assert.IsTrue(report.AddedMSGs.Any(), "Difference should have reported some Added MSGs");
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:19,代码来源:GraphDiffTests.cs

示例8: GraphDiffRemovedMSG

        public void GraphDiffRemovedMSG()
        {
            Graph g = new Graph();
            Graph h = new Graph();
            FileLoader.Load(g, "InferenceTest.ttl");
            FileLoader.Load(h, "InferenceTest.ttl");

            //Remove MSG from 2nd Graph
            h.Retract(h.GetTriplesWithSubject(h.GetBlankNode("autos1")));

            GraphDiffReport report = g.Difference(h);
            TestTools.ShowDifferences(report);

            Assert.IsFalse(report.AreEqual, "Graphs should not have been reported as equal");
            Assert.IsTrue(report.RemovedMSGs.Any(), "Difference should have reported some Removed MSGs");
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:16,代码来源:GraphDiffTests.cs

示例9: SparqlUpdateInsertCommand4

        public void SparqlUpdateInsertCommand4()
        {
            SparqlParameterizedString command = new SparqlParameterizedString();
            command.Namespaces.AddNamespace("rdf", new Uri(NamespaceMapper.RDF));
            command.Namespaces.AddNamespace("rdfs", new Uri(NamespaceMapper.RDFS));
            command.CommandText = "INSERT { ?s rdf:type ?class } USING NAMED <http://example.org/temp> WHERE { GRAPH ?g { ?s a ?type . ?type rdfs:subClassOf+ ?class } };";
            command.CommandText += "INSERT { ?s ?property ?value } USING NAMED <http://example.org/temp> WHERE { GRAPH ?g { ?s ?p ?value . ?p rdfs:subPropertyOf+ ?property } };";
            command.CommandText += "INSERT { ?s rdf:type rdfs:Class } USING NAMED <http://example.org/temp> WHERE { GRAPH ?g { ?s rdfs:subClassOf ?class } };";
            command.CommandText += "INSERT { ?s rdf:type rdf:Property } USING NAMED <http://example.org/temp> WHERE { GRAPH ?g { ?s rdfs:subPropertyOf ?property } };";

            TripleStore store = new TripleStore();
            Graph g = new Graph();
            FileLoader.Load(g, "InferenceTest.ttl");
            g.BaseUri = new Uri("http://example.org/temp");
            store.Add(g);

            SparqlUpdateParser parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds = parser.ParseFromString(command);
            InMemoryDataset dataset = new InMemoryDataset(store);
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(dataset);
            dataset.SetDefaultGraph(store.Graph(null));
            processor.ProcessCommandSet(cmds);

            IGraph def = store.Graph(null);
            TestTools.ShowGraph(def);

            //Apply a RDFS reasoner over the original input and output it into another graph
            //Should be equivalent to the default Graph
            Graph h = new Graph();
            RdfsReasoner reasoner = new RdfsReasoner();
            reasoner.Apply(g, h);

            TestTools.ShowGraph(h);

            GraphDiffReport report = h.Difference(def);
            if (!report.AreEqual)
            {
                TestTools.ShowDifferences(report);

                Assert.IsTrue(report.RemovedTriples.Count() == 1, "Should have only 1 missing Triple (due to rdfs:domain inference which is hard to encode in an INSERT command)");
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:42,代码来源:UpdateTests.cs

示例10: SparqlUpdateInsertCommand

        public void SparqlUpdateInsertCommand()
        {
            SparqlParameterizedString command = new SparqlParameterizedString();
            command.Namespaces.AddNamespace("rdf", new Uri(NamespaceMapper.RDF));
            command.Namespaces.AddNamespace("rdfs", new Uri(NamespaceMapper.RDFS));
            command.CommandText = "INSERT { ?s rdf:type ?class } WHERE { ?s a ?type . ?type rdfs:subClassOf+ ?class };";
            command.CommandText += "INSERT { ?s ?property ?value } WHERE {?s ?p ?value . ?p rdfs:subPropertyOf+ ?property };";
            command.CommandText += "INSERT { ?s rdf:type rdfs:Class } WHERE { ?s rdfs:subClassOf ?class };";
            command.CommandText += "INSERT { ?s rdf:type rdf:Property } WHERE { ?s rdfs:subPropertyOf ?property };";

            TripleStore store = new TripleStore();
            Graph g = new Graph();
            FileLoader.Load(g, "InferenceTest.ttl");
            g.Retract(g.Triples.Where(t => !t.IsGroundTriple));
            g.BaseUri = null;
            store.Add(g);

            SparqlUpdateParser parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds = parser.ParseFromString(command);
            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);
            processor.ProcessCommandSet(cmds);

            TestTools.ShowGraph(g);
            Console.WriteLine();

            //Now reload the test data and apply an RDFS reasoner over it
            //This should give us a Graph equivalent to the one created by the previous INSERT commands
            Graph h = new Graph();
            FileLoader.Load(h, "InferenceTest.ttl");
            h.Retract(h.Triples.Where(t => !t.IsGroundTriple));
            RdfsReasoner reasoner = new RdfsReasoner();
            reasoner.Apply(h);

            GraphDiffReport diff = h.Difference(g);
            if (!diff.AreEqual)
            {
                TestTools.ShowDifferences(diff);
            }

            Assert.AreEqual(h, g, "Graphs should be equal");            
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:41,代码来源:UpdateTests.cs

示例11: StorageDydraSaveToNamedGraph

        public void StorageDydraSaveToNamedGraph()
        {
            try
            {
                Options.HttpDebugging = true;

                Graph orig = new Graph();
                orig.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");

                DydraConnector dydra = this.GetConnection();
                dydra.SaveGraph(orig);

                Graph g = new Graph();
                dydra.LoadGraph(g, orig.BaseUri);

                if (orig.Triples.Count == g.Triples.Count)
                {
                    GraphDiffReport report = orig.Difference(g);
                    if (!report.AreEqual)
                    {
                        TestTools.ShowDifferences(report);
                    }
                    Assert.AreEqual(orig, g, "Graphs should be equal");
                }
                else
                {
                    Assert.IsTrue(g.HasSubGraph(orig), "Original Graph should be a sub-graph of retrieved Graph");
                }
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Error", ex, true);
            }
            finally
            {
                Options.HttpDebugging = false;
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:38,代码来源:DydraTests.cs

示例12: StorageVirtuosoSaveGraph

        public void StorageVirtuosoSaveGraph()
        {
            NTriplesFormatter formatter = new NTriplesFormatter();
            try
            {
                VirtuosoManager manager = new VirtuosoManager("DB", VirtuosoTestUsername, VirtuosoTestPassword);
                Assert.IsNotNull(manager);

                Console.WriteLine("Got the Virtuoso Manager OK");

                //Load in our Test Graph
                TurtleParser ttlparser = new TurtleParser();
                Graph g = new Graph();
                ttlparser.Load(g, "Turtle.ttl");

                Console.WriteLine();
                Console.WriteLine("Loaded Test Graph OK");
                Console.WriteLine("Test Graph contains:");

                Assert.IsFalse(g.IsEmpty, "Test Graph should be non-empty");

                foreach (Triple t in g.Triples)
                {
                    Console.WriteLine(t.ToString(formatter));
                }
                Console.WriteLine();

                //Try to save to Virtuoso
                manager.SaveGraph(g);
                Console.WriteLine("Saved OK");
                Console.WriteLine();

                //Try to retrieve
                Graph h = new Graph();
                manager.LoadGraph(h, "http://example.org");

                Assert.IsFalse(h.IsEmpty, "Retrieved Graph should be non-empty");

                Console.WriteLine("Retrieved the Graph from Virtuoso OK");
                Console.WriteLine("Retrieved Graph contains:");
                foreach (Triple t in h.Triples)
                {
                    Console.WriteLine(t.ToString(formatter));
                }

                Assert.AreEqual(g.Triples.Count, h.Triples.Count, "Graph should have same number of Triples before and after saving");

                GraphDiffReport diff = h.Difference(g);

                Console.WriteLine();
                if (!diff.AreEqual)
                {
                    Console.WriteLine("Some Differences in Graphs detected (should only be due to Virtuoso not running xsd:boolean as true/false");
                    Console.WriteLine();

                    TestTools.ShowDifferences(diff);

                    IUriNode allowedDiffSubject = g.CreateUriNode(":four");
                    IUriNode allowedDiffSubject2 = g.CreateUriNode(":six");
                    Assert.IsTrue(diff.RemovedTriples.All(t => t.Subject.Equals(allowedDiffSubject2) || (t.Subject.Equals(allowedDiffSubject) && (t.Object.ToString().Equals("true^^" + XmlSpecsHelper.XmlSchemaDataTypeBoolean) || t.Object.ToString().Equals("false^^" + XmlSpecsHelper.XmlSchemaDataTypeBoolean)))), "Removed Triples should only be those with subject :four and boolean object");
                    Assert.IsTrue(diff.AddedTriples.All(t => t.Subject.Equals(allowedDiffSubject2) || (t.Subject.Equals(allowedDiffSubject) && (t.Object.ToString().Equals("1") || t.Object.ToString().Equals("0")))), "Added Triples should only be those with subject :four and 1/0 in place of boolean object");
                }
                else
                {
                    Console.WriteLine("Graphs are equal");
                }
            }
            catch (VirtuosoException virtEx)
            {
                TestTools.ReportError("Virtuoso Error", virtEx, true);
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Other Error", ex, true);
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:76,代码来源:VirtuosoTest.cs


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