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


C# Graph.Assert方法代码示例

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


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

示例1: ParsingRdfXmlAmpersands

        public void ParsingRdfXmlAmpersands()
        {
            List<IRdfWriter> writers = new List<IRdfWriter>()
            {
                new RdfXmlWriter(),
                new FastRdfXmlWriter()
            };
            IRdfReader parser = new RdfXmlParser();

            Graph g = new Graph();
            g.BaseUri = new Uri("http://example.org/ampersandsInRdfXml");
            g.Assert(new Triple(g.CreateUriNode(), g.CreateUriNode(new Uri("http://example.org/property")), g.CreateUriNode(new Uri("http://example.org/a&b"))));
            g.Assert(new Triple(g.CreateUriNode(), g.CreateUriNode(new Uri("http://example.org/property")), g.CreateLiteralNode("A & B")));

            foreach (IRdfWriter writer in writers)
            {
                try
                {
                    Console.WriteLine(writer.GetType().ToString());
                    String temp = StringWriter.Write(g, writer);
                    Console.WriteLine(temp);
                    Graph h = new Graph();
                    StringParser.Parse(h, temp);
                    Assert.AreEqual(g, h, "Graphs should be equal");
                    Console.WriteLine();
                }
                catch (Exception ex)
                {
                    TestTools.ReportError("Error", ex, true);
                }
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:32,代码来源:RdfXmlTests.cs

示例2: SparqlFunctionsIsNumeric

        public void SparqlFunctionsIsNumeric()
        {
            Graph g = new Graph();
            IUriNode subj = g.CreateUriNode(new Uri("http://example.org/subject"));
            IUriNode pred = g.CreateUriNode(new Uri("http://example.org/predicate"));

            g.Assert(subj, pred, (12).ToLiteral(g));
            g.Assert(subj, pred, g.CreateLiteralNode("12"));
            g.Assert(subj, pred, g.CreateLiteralNode("12", new Uri(XmlSpecsHelper.XmlSchemaDataTypeNonNegativeInteger)));
            g.Assert(subj, pred, g.CreateLiteralNode("12", new Uri(XmlSpecsHelper.XmlSchemaDataTypeNonPositiveInteger)));
            g.Assert(subj, pred, g.CreateLiteralNode("1200", new Uri(XmlSpecsHelper.XmlSchemaDataTypeByte)));
            g.Assert(subj, pred, ((byte)50).ToLiteral(g));
            g.Assert(subj, pred, g.CreateLiteralNode("-50", new Uri(XmlSpecsHelper.XmlSchemaDataTypeByte)));
            g.Assert(subj, pred, g.CreateLiteralNode("-50", new Uri(XmlSpecsHelper.XmlSchemaDataTypeUnsignedByte)));
            g.Assert(subj, pred, g.CreateUriNode(new Uri("http://example.org")));

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

            SparqlQueryParser parser = new SparqlQueryParser();
            SparqlQuery q = parser.ParseFromString("SELECT ?obj (IsNumeric(?obj) AS ?IsNumeric) WHERE { ?s ?p ?obj }");

            Object results = store.ExecuteQuery(q);

            Assert.IsTrue(results is SparqlResultSet, "Result should be a SPARQL Result Set");
            TestTools.ShowResults(results);
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:27,代码来源:SparqlNewFunctions.cs

示例3: SparqlDefaultGraphExists3

        public void SparqlDefaultGraphExists3()
        {
            SqlDataset dataset = new SqlDataset(new MicrosoftSqlStoreManager("localhost", "unit_test", "example", "password"));

            //Create Default Graph only if required
            if (!dataset.HasGraph(null))
            {
                Graph g = new Graph();
                g.Assert(g.CreateUriNode(new Uri("http://example.org/subject")), g.CreateUriNode(new Uri("http://example.org/predicate")), g.CreateUriNode(new Uri("http://example.org/object")));
                dataset.AddGraph(g);
                dataset.Flush();
            }

            SparqlQueryParser parser = new SparqlQueryParser();
            SparqlQuery q = parser.ParseFromString("ASK WHERE { GRAPH ?g { ?s ?p ?o }}");
            LeviathanQueryProcessor lvn = new LeviathanQueryProcessor(dataset);
            Object results = lvn.ProcessQuery(q);
            if (results is SparqlResultSet)
            {
                Assert.IsTrue(((SparqlResultSet)results).Result);
            }
            else
            {
                Assert.Fail("ASK Query did not return a SPARQL Result Set as expected");
            }

            dataset.Flush();
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:28,代码来源:DefaultGraphTests.cs

示例4: add

 public virtual void add(org.openrdf.model.Statement s, params org.openrdf.model.Resource[] rarr)
 {
     IEnumerable<Uri> contexts = rarr.ToContexts(this._mapping);
     Graph g = new Graph();
     g.Assert(SesameConverter.FromSesame(s, this._mapping));
     this.AddInternal(g, contexts);
 }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:7,代码来源:BaseRepositoryConnection.cs

示例5: WritingCollectionCompressionEmpty2

        public void WritingCollectionCompressionEmpty2()
        {
            Graph g = new Graph();
            g.NamespaceMap.AddNamespace("ex", new Uri("http://example.org/"));
            INode rdfType = g.CreateUriNode("rdf:type");

            g.Assert(g.CreateUriNode("ex:subj"), g.CreateUriNode("ex:pred"), g.CreateUriNode("rdf:nil"));

            CompressingTurtleWriterContext context = new CompressingTurtleWriterContext(g, Console.Out);
            WriterHelper.FindCollections(context);

            Assert.AreEqual(0, context.Collections.Count, "Expected 0 Collection to be found");

            this.CheckCompressionRoundTrip(g);
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:15,代码来源:CollectionCompressionTests.cs

示例6: Test1

        static void Test1()
        {
            Graph g = new Graph();

            g.Assert(new Name("a"), new Name("x"), "1");
            g.Assert(new Name("a"), new Name("y"), "2");
            g.Assert(new Name("a"), new Name("z"), "3");
            g.Assert(new Name("b"), new Name("x"), "1");
            g.Assert(new Name("b"), new Name("y"), "2");
            g.Assert(new Name("b"), new Name("z"), "3");
            g.Assert(new Name("b"), new Name("z"), "4");
            g.Assert(new Name("b"), new Name("z"), "5");
            g.Assert(new Name("c"), new Name("x"), "1");
            g.Assert(new Name("c"), new Name("y"), "2");
            g.Assert(new Name("c"), new Name("y"), "3");
            g.Assert(new Name("c"), new Name("z"), "3");
            g.Assert(new Name("c"), new Name("z"), new Name("d"));
            g.Assert(new Name("c"), new Name("z"), new Name("e"));
            g.Assert(new Name("d"), new Name("z"), "4");
            g.Assert(new Name("d"), new Name("z"), "5");
            g.Assert(new Name("e"), new Name("z"), "6");

            Graph q = new Graph();
            q.Assert(new Name("c"), new Name("z"), new Variable("v0"));
            q.Assert(new Variable("v0"), new Name("z"), new Variable("v1"));


            foreach (var binding in Query.Select(g, q))
            {
                foreach (var entry in binding)
                {
                    Console.WriteLine("{0} : {1}", entry.Key, entry.Value);
                }
                Console.WriteLine("----------------------");
            }
        }
开发者ID:NuGet,项目名称:Entropy,代码行数:36,代码来源:Program.cs

示例7: SparqlDefaultGraphExists2

        public void SparqlDefaultGraphExists2()
        {
            TripleStore store = new TripleStore();
            Graph g = new Graph();
            g.Assert(g.CreateUriNode(new Uri("http://example.org/subject")), g.CreateUriNode(new Uri("http://example.org/predicate")), g.CreateUriNode(new Uri("http://example.org/object")));
            store.Add(g);

            Object results = store.ExecuteQuery("ASK WHERE { GRAPH <dotnetrdf:default-graph> { ?s ?p ?o }}");
            if (results is SparqlResultSet)
            {
                Assert.IsTrue(((SparqlResultSet)results).Result);
            }
            else
            {
                Assert.Fail("ASK Query did not return a SPARQL Result Set as expected");
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:17,代码来源:DefaultGraphTests.cs

示例8: GraphDiffAddedGroundTriples

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

            //Add additional Triple to 2nd Graph
            IUriNode spaceVehicle = h.CreateUriNode("eg:SpaceVehicle");
            IUriNode subClass = h.CreateUriNode("rdfs:subClassOf");
            IUriNode vehicle = h.CreateUriNode("eg:Vehicle");
            h.Assert(new Triple(spaceVehicle, 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.AddedTriples.Any(), "Difference should have reported some Added Triples");
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:19,代码来源:GraphDiffTests.cs

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

示例10: Construct

        public static IGraph Construct(IGraph graph, IGraph query, IGraph template, IDictionary<string, object> parameters = null)
        {
            IGraph result = new Graph();

            List<IDictionary<string, object>> bindings = Query.Select(graph, query, parameters);

            foreach (var binding in bindings)
            {
                foreach (var templateTriple in template.Match(Triple.Empty))
                {
                    //object s = templateTriple.Subject is Variable ? binding[((Variable)templateTriple.Subject).Value] : templateTriple.Subject;
                    //object p = templateTriple.Predicate is Variable ? binding[((Variable)templateTriple.Predicate).Value] : templateTriple.Predicate;
                    //object o = templateTriple.Object is Variable ? binding[((Variable)templateTriple.Object).Value] : templateTriple.Object;

                    object s = Construct(binding, templateTriple.Subject);
                    object p = Construct(binding, templateTriple.Predicate);
                    object o = Construct(binding, templateTriple.Object);

                    result.Assert(s, p, o);
                }
            }

            return result;
        }
开发者ID:NuGet,项目名称:Entropy,代码行数:24,代码来源:Query.cs

示例11: WritingCollectionCompressionNamedListNodes3

        public void WritingCollectionCompressionNamedListNodes3()
        {
            Graph g = new Graph();
            INode data1 = g.CreateBlankNode();
            g.Assert(data1, g.CreateUriNode(new Uri("http://property")), g.CreateLiteralNode("test1"));
            INode data2 = g.CreateBlankNode();
            g.Assert(data2, g.CreateUriNode(new Uri("http://property")), g.CreateLiteralNode("test2"));

            INode listEntry1 = g.CreateUriNode(new Uri("http://test/1"));
            INode rdfFirst = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfListFirst));
            INode rdfRest = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfListRest));
            INode rdfNil = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfListNil));
            g.Assert(listEntry1, rdfFirst, data1);
            g.Assert(listEntry1, rdfRest, rdfNil);

            INode listEntry2 = g.CreateUriNode(new Uri("http://test/2"));
            g.Assert(listEntry2, rdfFirst, data2);
            g.Assert(listEntry2, rdfRest, listEntry1);

            INode root = g.CreateUriNode(new Uri("http://root"));
            g.Assert(root, g.CreateUriNode(new Uri("http://list")), listEntry2);

            NTriplesFormatter formatter = new NTriplesFormatter();
            Console.WriteLine("Original Graph");
            foreach (Triple t in g.Triples)
            {
                Console.WriteLine(t.ToString(formatter));
            }
            Console.WriteLine();

            CompressingTurtleWriterContext context = new CompressingTurtleWriterContext(g, Console.Out);
            WriterHelper.FindCollections(context);
            Console.WriteLine(context.Collections.Count + " Collections Found");
            Console.WriteLine();

            System.IO.StringWriter strWriter = new System.IO.StringWriter();
            CompressingTurtleWriter writer = new CompressingTurtleWriter();
            writer.CompressionLevel = WriterCompressionLevel.High;
            writer.Save(g, strWriter);

            Console.WriteLine("Compressed Turtle");
            Console.WriteLine(strWriter.ToString());
            Console.WriteLine();

            Graph h = new Graph();
            TurtleParser parser = new TurtleParser();
            StringParser.Parse(h, strWriter.ToString());
            Console.WriteLine("Graph after Round Trip to Compressed Turtle");
            foreach (Triple t in h.Triples)
            {
                Console.WriteLine(t.ToString(formatter));
            }

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

示例12: WritingCollectionCompressionCyclic3

        public void WritingCollectionCompressionCyclic3()
        {
            Graph g = new Graph();
            g.NamespaceMap.AddNamespace("ex", new Uri("http://example.org/"));
            g.NamespaceMap.AddNamespace("dnr", new Uri(ConfigurationLoader.ConfigurationNamespace));
            INode a = g.CreateBlankNode();
            INode b = g.CreateBlankNode();
            INode c = g.CreateBlankNode();
            INode d = g.CreateBlankNode();
            INode e = g.CreateBlankNode();

            INode pred = g.CreateUriNode("ex:pred");

            g.Assert(d, pred, a);
            g.Assert(d, pred, g.CreateLiteralNode("D"));
            g.Assert(a, pred, b);
            g.Assert(a, pred, g.CreateLiteralNode("A"));
            g.Assert(b, pred, c);
            g.Assert(b, pred, g.CreateLiteralNode("B"));
            g.Assert(c, pred, a);
            g.Assert(c, pred, g.CreateLiteralNode("C"));
            g.Assert(e, pred, g.CreateLiteralNode("E"));

            CompressingTurtleWriterContext context = new CompressingTurtleWriterContext(g, Console.Out);
            WriterHelper.FindCollections(context);

            Assert.AreEqual(3, context.Collections.Count, "Expected 3 collections (one should be eliminated to break the cycle)");

            this.CheckCompressionRoundTrip(g);
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:30,代码来源:CollectionCompressionTests.cs

示例13: WritingCollectionCompressionComplex1

        public void WritingCollectionCompressionComplex1()
        {
            SparqlConnector connector = new SparqlConnector(new VDS.RDF.Query.SparqlRemoteEndpoint(new Uri("http://dbpedia.org/sparql")));
            Graph g = new Graph();
            g.NamespaceMap.AddNamespace("ex", new Uri("http://example.org/"));
            g.NamespaceMap.AddNamespace("dnr", new Uri(ConfigurationLoader.ConfigurationNamespace));
            INode n = g.CreateBlankNode();

            g.Assert(g.CreateUriNode("ex:subj"), g.CreateUriNode("dnr:genericManager"), n);
            ConfigurationSerializationContext sContext = new ConfigurationSerializationContext(g);
            sContext.NextSubject = n;
            connector.SerializeConfiguration(sContext);

            CompressingTurtleWriterContext context = new CompressingTurtleWriterContext(g, Console.Out);
            WriterHelper.FindCollections(context);

            Assert.AreEqual(2, context.Collections.Count, "Expected 2 collections");

            this.CheckCompressionRoundTrip(g);
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:20,代码来源:CollectionCompressionTests.cs

示例14: WritingCollectionCompressionNamedListNodes2

        public void WritingCollectionCompressionNamedListNodes2()
        {
            Graph g = new Graph();
            g.NamespaceMap.AddNamespace("ex", new Uri("http://example.org/"));
            INode n = g.CreateUriNode("ex:listRoot");
            INode m = g.CreateUriNode("ex:listItem");
            INode rdfType = g.CreateUriNode("rdf:type");
            INode rdfFirst = g.CreateUriNode("rdf:first");
            INode rdfRest = g.CreateUriNode("rdf:rest");
            INode rdfNil = g.CreateUriNode("rdf:nil");

            g.Assert(g.CreateUriNode("ex:subj"), g.CreateUriNode("ex:pred"), n);
            g.Assert(n, rdfFirst, g.CreateLiteralNode("first"));
            g.Assert(n, rdfRest, m);
            g.Assert(m, rdfFirst, g.CreateLiteralNode("second"));
            g.Assert(m, rdfRest, rdfNil);

            CompressingTurtleWriterContext context = new CompressingTurtleWriterContext(g, Console.Out);
            WriterHelper.FindCollections(context);

            Assert.AreEqual(0, context.Collections.Count, "Expected no collections to be found");

            this.CheckCompressionRoundTrip(g);
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:24,代码来源:CollectionCompressionTests.cs

示例15: GraphTripleCreation

        public void GraphTripleCreation()
        {
            //Create two Graphs
            Graph g = new Graph();
            Graph h = new Graph();

            g.NamespaceMap.AddNamespace("ex", new Uri("http://example.org/"));
            h.NamespaceMap.AddNamespace("ex", new Uri("http://example.org/"));

            //Create a Triple in First Graph
            g.Assert(g.CreateBlankNode(), g.CreateUriNode("rdf:type"), g.CreateUriNode("ex:Triple"));
            Assert.AreEqual(1, g.Triples.Count, "Should have 1 Triple in the Graph");

            //Create a Triple in Second Graph
            h.Assert(h.CreateBlankNode(), h.CreateUriNode("rdf:type"), h.CreateUriNode("ex:Triple"));
            Assert.AreEqual(1, h.Triples.Count, "Should have 1 Triple in the Graph");

            //Create a Triple with Nodes from different Graphs (should fail)
            try
            {
                g.Assert(g.CreateBlankNode(), h.CreateBlankNode("rdf:type"), g.CreateBlankNode("ex:Triple"));
                Assert.Fail("Should have thrown an error when Triple was instantiated as Nodes are from different Graphs");
            }
            catch (RdfException)
            {
                Console.WriteLine("Error thrown as expected - Triples must be instantiated with Nodes from the same Graph");
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Exception", ex, true);
            }

            //Create a Triple with Nodes from different Graphs (should fail)
            try
            {
                h.Assert(g.CreateBlankNode(), h.CreateBlankNode("rdf:type"), g.CreateBlankNode("ex:Triple"));
                Assert.Fail("Should have thrown an error when Triple was instantiated as Nodes are from different Graphs");
            }
            catch (RdfException)
            {
                Console.WriteLine("Error thrown as expected - Triples must be instantiated with Nodes from the same Graph");
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Exception", ex, true);
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:47,代码来源:BasicTests1.cs


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