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


C# Graph.Retract方法代码示例

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


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

示例1: WebETagComputation

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

                Stopwatch timer = new Stopwatch();
                timer.Start();
                String etag = g.GetETag();
                timer.Stop();
                Console.WriteLine("ETag is " + etag);
                Console.WriteLine(etag.Length);
                Console.WriteLine("Took " + timer.Elapsed + " to calculate");
                Console.WriteLine();

                Assert.IsFalse(String.IsNullOrEmpty(etag));
                Assert.AreEqual(40, etag.Length, "Expected ETag Length was 40 characters");

                timer.Reset();
                timer.Start();
                String etag2 = g.GetETag();
                timer.Stop();
                Console.WriteLine("ETag is " + etag2);
                Console.WriteLine("Took " + timer.Elapsed + " to calculate");
                Console.WriteLine();

                Assert.AreEqual(etag, etag2, "ETags should be consistent unless the Graph changes");
                Assert.AreEqual(40, etag2.Length, "Expected ETag Length was 40 characters");

                g.Retract(g.Triples.First());
                timer.Reset();
                timer.Start();
                String etag3 = g.GetETag();
                timer.Stop();
                Console.WriteLine("Graph has now been altered so ETag should change");
                Console.WriteLine("ETag is " + etag3);
                Console.WriteLine("Took " + timer.Elapsed + " to calculate");
                Console.WriteLine();

                Assert.AreNotEqual(etag, etag3, "ETags should change if the Graph changes");
                Assert.AreNotEqual(etag2, etag3, "ETags should change if the Graph changes");
                Assert.AreEqual(40, etag3.Length, "Expected ETag Length was 40 characters");
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Error", ex, true);
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:49,代码来源:ETagTests.cs

示例2: 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

示例3: GraphEventBubbling

        public void GraphEventBubbling()
        {
            try
            {
                this._graphAdded = false;
                this._graphRemoved = false;
                this._graphChanged = false;

                //Create Store and Graph add attach handlers to Store
                TripleStore store = new TripleStore();
                Graph g = new Graph();
                store.GraphAdded += this.HandleGraphAdded;
                store.GraphRemoved += this.HandleGraphRemoved;
                store.GraphChanged += this.HandleGraphChanged;

                //Add the Graph to the Store which should fire the GraphAdded event
                store.Add(g);
                Assert.IsTrue(this._graphAdded, "GraphAdded event of the Triple Store should have fired");

                //Assert a Triple
                INode s = g.CreateBlankNode();
                INode p = g.CreateUriNode("rdf:type");
                INode o = g.CreateUriNode("rdfs:Class");
                Triple t = new Triple(s, p, o);
                g.Assert(t);
                Assert.IsTrue(this._graphChanged, "GraphChanged event of the Triple Store should have fired");

                //Retract the Triple
                this._graphChanged = false;
                g.Retract(t);
                Assert.IsTrue(this._graphChanged, "GraphChanged event of the Triple Store should have fired");

                //Remove the Graph from the Store which should fire the GraphRemoved event
                store.Remove(g.BaseUri);
                Assert.IsTrue(this._graphRemoved, "GraphRemoved event of the Triple Store should have fired");
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Error", ex, true);
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:41,代码来源:EventTests.cs

示例4: 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

示例5: StorageSparqlUniformHttpProtocolAddTriples

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

                StorageSparqlUniformHttpProtocolSaveGraph();

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

                SparqlHttpProtocolConnector sparql = new SparqlHttpProtocolConnector(new Uri(ProtocolTestUri));
                sparql.UpdateGraph("http://example.org/sparqlTest", g.Triples, null);

                Graph h = new Graph();
                sparql.LoadGraph(h, "http://example.org/sparqlTest");

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

                Assert.IsTrue(g.IsSubGraphOf(h), "Retrieved Graph should have the added Triples as a Sub Graph");
            }
            finally
            {
                Options.UriLoaderCaching = true;
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:30,代码来源:SparqlUniformHttpProtocolTest.cs

示例6: RemoveGraphFromContext

 private bool RemoveGraphFromContext(Uri u, IGraph g)
 {
     if (this._manager.UpdateSupported)
     {
         this._manager.UpdateGraph(u, null, g.Triples);
     }
     else
     {
         Graph temp = new Graph();
         temp.BaseUri = g.BaseUri;
         this._manager.LoadGraph(temp, temp.BaseUri);
         temp.Retract(g.Triples);
         this._manager.SaveGraph(temp);
     }
     return true;
 }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:16,代码来源:DotNetRdfGenericRepository.cs

示例7: StorageStardogUpdateNamedGraphAddTriples

        public void StorageStardogUpdateNamedGraphAddTriples()
        {
            try
            {
                //Options.UseBomForUtf8 = false;

                StardogConnector stardog = this.GetConnection();
                Graph g = new Graph();
                g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
                g.BaseUri = new Uri("http://example.org/addGraph");

                INode rdfType = g.CreateUriNode(new Uri(VDS.RDF.Parsing.RdfSpecsHelper.RdfType));
                Graph types = new Graph();
                types.Assert(g.GetTriplesWithPredicate(rdfType));
                g.Retract(g.GetTriplesWithPredicate(rdfType));

                //Save the Graph without the rdf:type triples
                stardog.SaveGraph(g);
                //Then add back in the rdf:type triples
                stardog.UpdateGraph(g.BaseUri, types.Triples, null);

                Graph h = new Graph();
                stardog.LoadGraph(h, new Uri("http://example.org/addGraph"));

                if (g.Triples.Count == h.Triples.Count)
                {
                    Assert.AreEqual(g, h, "Retrieved Graph should be equal to the Saved Graph");
                }
                else
                {
                    Assert.IsTrue(h.HasSubGraph(g), "Retrieved Graph should have the Saved Graph as a subgraph");
                }
                Assert.IsTrue(h.GetTriplesWithPredicate(rdfType).Any(), "Retrieved Graph should not contain any rdf:type Triples");
            }
            finally
            {
                //Options.UseBomForUtf8 = true;
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:39,代码来源:StardogTests.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: 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

示例10: SparqlUpdateModifyWithOptional2

        public void SparqlUpdateModifyWithOptional2()
        {
            Graph g = new Graph();
            g.LoadFromFile("InferenceTest.ttl");
            g.BaseUri = new Uri("http://example.org/vehicles/");

            Graph def = new Graph();
            def.Merge(g);

            TripleStore store = new TripleStore();
            store.Add(g);
            store.Add(def);

            Graph expected = new Graph();
            expected.NamespaceMap.Import(g.NamespaceMap);
            expected.Merge(g);
            expected.Retract(expected.GetTriplesWithPredicate(expected.CreateUriNode("rdf:type")));
            expected.Retract(expected.GetTriplesWithPredicate(expected.CreateUriNode("eg:Speed")));

            String update = "PREFIX ex: <http://example.org/vehicles/> DELETE { ?s a ?type . ?s ex:Speed ?speed } INSERT { } USING <http://example.org/vehicles/> WHERE { ?s a ?type . OPTIONAL { ?s ex:Speed ?speed } }";

            this.TestUpdate(store, expected, update);
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:23,代码来源:ConstructWithOptionalTests.cs


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