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


C# Graph.CreateBlankNode方法代码示例

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


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

示例1: NodesDistinct

        public void NodesDistinct()
        {
            Graph g = new Graph();
            List<INode> test = new List<INode>()
            {
                g.CreateUriNode("rdf:type"),
                g.CreateUriNode(new Uri("http://example.org")),
                g.CreateBlankNode(),
                g.CreateBlankNode(),
                null,
                g.CreateBlankNode("test"),
                g.CreateLiteralNode("Test text"),
                g.CreateLiteralNode("Test text", "en"),
                g.CreateLiteralNode("Test text", new Uri(XmlSpecsHelper.XmlSchemaDataTypeString)),
                g.CreateUriNode("rdf:type"),
                null,
                g.CreateUriNode(new Uri("http://example.org#test")),
                g.CreateUriNode(new Uri("http://example.org"))
            };

            foreach (INode n in test.Distinct())
            {
                if (n != null)
                {
                    Console.WriteLine(n.ToString());
                }
                else
                {
                    Console.WriteLine("null");
                }
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:32,代码来源:BasicTests1.cs

示例2: WritingCollectionCompressionEmpty1

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

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

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

            Assert.AreEqual(1, context.Collections.Count, "Expected 1 Collection to be found");
            Assert.AreEqual(0, context.Collections.First().Value.Triples.Count, "Expected no Triples to be in the collection");

            this.CheckCompressionRoundTrip(g);
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:17,代码来源:CollectionCompressionTests.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: 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

示例5: WritingCollectionCompressionSimple5

        public void WritingCollectionCompressionSimple5()
        {
            Graph g = new Graph();
            g.NamespaceMap.AddNamespace("ex", new Uri("http://example.org/"));
            INode n = g.CreateBlankNode();
            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(g.CreateUriNode("ex:subj"), g.CreateUriNode("ex:pred2"), n);
            g.Assert(n, rdfFirst, g.CreateLiteralNode("first"));
            g.Assert(n, 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,代码行数:22,代码来源:CollectionCompressionTests.cs

示例6: WritingTripleFormatting

        public void WritingTripleFormatting()
        {
            try
            {
                //Create the Graph and define an additional namespace
                Graph g = new Graph();
                g.NamespaceMap.AddNamespace("ex", new Uri("http://example.org/"));

                //Create URIs used for datatypes
                Uri dtInt = new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger);
                Uri dtFloat = new Uri(XmlSpecsHelper.XmlSchemaDataTypeFloat);
                Uri dtDouble = new Uri(XmlSpecsHelper.XmlSchemaDataTypeDouble);
                Uri dtDecimal = new Uri(XmlSpecsHelper.XmlSchemaDataTypeDecimal);
                Uri dtBoolean = new Uri(XmlSpecsHelper.XmlSchemaDataTypeBoolean);
                Uri dtUnknown = new Uri("http://example.org/unknownType");

                //Create Nodes used for our test Triples
                IBlankNode subjBnode = g.CreateBlankNode();
                IUriNode subjUri = g.CreateUriNode(new Uri("http://example.org/subject"));
                IUriNode predUri = g.CreateUriNode(new Uri("http://example.org/predicate"));
                IUriNode predType = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType));
                IBlankNode objBnode = g.CreateBlankNode();
                IUriNode objUri = g.CreateUriNode(new Uri("http://example.org/object"));
                ILiteralNode objString = g.CreateLiteralNode("This is a literal");
                ILiteralNode objStringLang = g.CreateLiteralNode("This is a literal with a language specifier", "en");
                ILiteralNode objInt = g.CreateLiteralNode("123", dtInt);
                ILiteralNode objFloat = g.CreateLiteralNode("12.3e4", dtFloat);
                ILiteralNode objDouble = g.CreateLiteralNode("12.3e4", dtDouble);
                ILiteralNode objDecimal = g.CreateLiteralNode("12.3", dtDecimal);
                ILiteralNode objTrue = g.CreateLiteralNode("true", dtBoolean);
                ILiteralNode objFalse = g.CreateLiteralNode("false", dtBoolean);
                ILiteralNode objUnknown = g.CreateLiteralNode("This is a literal with an unknown type", dtUnknown);

                List<ITripleFormatter> formatters = new List<ITripleFormatter>()
                {
                    new NTriplesFormatter(),
                    new UncompressedTurtleFormatter(),
                    new UncompressedNotation3Formatter(),
                    new TurtleFormatter(g),
                    new Notation3Formatter(g),
                    new CsvFormatter(),
                    new TsvFormatter()
                };
                List<INode> subjects = new List<INode>()
                {
                    subjBnode,
                    subjUri
                };
                List<INode> predicates = new List<INode>()
                {
                    predUri,
                    predType
                };
                List<INode> objects = new List<INode>()
                {
                    objBnode,
                    objUri,
                    objString,
                    objStringLang,
                    objInt,
                    objFloat,
                    objDouble,
                    objDecimal,
                    objTrue,
                    objFalse,
                    objUnknown
                };
                List<Triple> testTriples = new List<Triple>();
                foreach (INode s in subjects)
                {
                    foreach (INode p in predicates)
                    {
                        foreach (INode o in objects)
                        {
                            testTriples.Add(new Triple(s, p, o));
                        }
                    }
                }

                foreach (Triple t in testTriples)
                {
                    Console.WriteLine("Raw Triple:");
                    Console.WriteLine(t.ToString());
                    Console.WriteLine();
                    foreach (ITripleFormatter f in formatters)
                    {
                        Console.WriteLine(f.GetType().ToString());
                        Console.WriteLine(f.Format(t));
                        Console.WriteLine();
                    }
                    Console.WriteLine();
                }
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Error", ex, true);
            }       
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:98,代码来源:FormattingTests.cs

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

示例8: NodesNullNodeEquality

        public void NodesNullNodeEquality()
        {
            UriNode nullUri = null;
            LiteralNode nullLiteral = null;
            BlankNode nullBNode = null;

            Graph g = new Graph();
            IUriNode someUri = g.CreateUriNode(new Uri("http://example.org"));
            ILiteralNode someLiteral = g.CreateLiteralNode("A Literal");
            IBlankNode someBNode = g.CreateBlankNode();

            Assert.AreEqual(nullUri, nullUri, "Null URI Node should be equal to self");
            Assert.AreEqual(nullUri, null, "Null URI Node should be equal to a null");
            Assert.AreEqual(null, nullUri, "Null should be equal to a Null URI Node");
            Assert.IsTrue(nullUri == nullUri, "Null URI Node should be equal to self");
            Assert.IsTrue(nullUri == null, "Null URI Node should be equal to a null");
            Assert.IsTrue(null == nullUri, "Null should be equal to a Null URI Node");
            Assert.IsFalse(nullUri != nullUri, "Null URI Node should be equal to self");
            Assert.IsFalse(nullUri != null, "Null URI Node should be equal to a null");
            Assert.IsFalse(null != nullUri, "Null should be equal to a Null URI Node");
            Assert.AreNotEqual(nullUri, someUri, "Null URI Node should not be equal to an actual URI Node");
            Assert.AreNotEqual(someUri, nullUri, "Null URI Node should not be equal to an actual URI Node");
            Assert.IsFalse(nullUri == someUri, "Null URI Node should not be equal to an actual URI Node");
            Assert.IsFalse(someUri == nullUri, "Null URI Node should not be equal to an actual URI Node");

            Assert.AreEqual(nullLiteral, nullLiteral, "Null Literal Node should be equal to self");
            Assert.AreEqual(nullLiteral, null, "Null Literal Node should be equal to a null");
            Assert.AreEqual(null, nullLiteral, "Null should be equal to a Null Literal Node");
            Assert.IsTrue(nullLiteral == nullLiteral, "Null Literal Node should be equal to self");
            Assert.IsTrue(nullLiteral == null, "Null Literal Node should be equal to a null");
            Assert.IsTrue(null == nullLiteral, "Null should be equal to a Null Literal Node");
            Assert.IsFalse(nullLiteral != nullLiteral, "Null Literal Node should be equal to self");
            Assert.IsFalse(nullLiteral != null, "Null Literal Node should be equal to a null");
            Assert.IsFalse(null != nullLiteral, "Null should be equal to a Null Literal Node");
            Assert.AreNotEqual(nullLiteral, someLiteral, "Null Literal Node should not be equal to an actual Literal Node");
            Assert.AreNotEqual(someLiteral, nullLiteral, "Null Literal Node should not be equal to an actual Literal Node");
            Assert.IsFalse(nullLiteral == someLiteral, "Null Literal Node should not be equal to an actual Literal Node");
            Assert.IsFalse(someLiteral == nullLiteral, "Null Literal Node should not be equal to an actual Literal Node");

            Assert.AreEqual(nullBNode, nullBNode, "Null BNode Node should be equal to self");
            Assert.AreEqual(nullBNode, null, "Null BNode Node should be equal to a null");
            Assert.AreEqual(null, nullBNode, "Null should be equal to a Null BNode Node");
            Assert.IsTrue(nullBNode == nullBNode, "Null BNode Node should be equal to self");
            Assert.IsTrue(nullBNode == null, "Null BNode Node should be equal to a null");
            Assert.IsTrue(null == nullBNode, "Null should be equal to a Null BNode Node");
            Assert.IsFalse(nullBNode != nullBNode, "Null BNode Node should be equal to self");
            Assert.IsFalse(nullBNode != null, "Null BNode Node should be equal to a null");
            Assert.IsFalse(null != nullBNode, "Null should be equal to a Null BNode Node");
            Assert.AreNotEqual(nullBNode, someBNode, "Null BNode Node should not be equal to an actual BNode Node");
            Assert.AreNotEqual(someBNode, nullBNode, "Null BNode Node should not be equal to an actual BNode Node");
            Assert.IsFalse(nullBNode == someBNode, "Null BNode Node should not be equal to an actual BNode Node");
            Assert.IsFalse(someBNode == nullBNode, "Null BNode Node should not be equal to an actual BNode Node");
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:53,代码来源:BasicTests1.cs

示例9: GenerateStarGraph

        private IGraph GenerateStarGraph(int nodes)
        {
            Graph g = new Graph();
            IUriNode rdfValue = g.CreateUriNode("rdf:value");

            List<IBlankNode> bnodes = new List<IBlankNode>();
            for (int i = 0; i < nodes; i++)
            {
                bnodes.Add(g.CreateBlankNode());
            }

            for (int i = 0; i < bnodes.Count; i++)
            {
                for (int j = 0; j < bnodes.Count; j++)
                {
                    if (i == j) continue;
                    g.Assert(bnodes[i], rdfValue, bnodes[j]);
                }
            }

            return g;
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:22,代码来源:HardGraphMatching.cs

示例10: NodesHashCodes

        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);

        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:81,代码来源:BasicTests1.cs

示例11: GenerateChangeSet

        /// <summary>
        /// Takes lists of Triples added and removed and generates a ChangeSet Batch Graph for these
        /// </summary>
        /// <param name="additions">Triple added</param>
        /// <param name="removals">Triples removed</param>
        /// <returns>Null if there are no Changes to be persisted</returns>
        private IGraph GenerateChangeSet(IEnumerable<Triple> additions, IEnumerable<Triple> removals)
        {
            //Ensure there are no duplicates in the lists
            List<Triple> toAdd = (additions == null) ? new List<Triple>() : additions.Distinct().ToList();
            List<Triple> toRemove = (removals == null) ? new List<Triple>() : removals.Distinct().ToList();

            //Eliminate any additions that have also been retracted
            List<Triple> temp = new List<Triple>();
            foreach (Triple t in toAdd)
            {
                if (toRemove.Contains(t))
                {
                    temp.Add(t);
                }
            }
            //If it was in both lists we don't need to persist the Change as it has effectively not happened
            toAdd.RemoveAll(t => temp.Contains(t));
            toRemove.RemoveAll(t => temp.Contains(t));

            //Nothing to do if both lists are now empty
            if (toAdd.Count == 0 && toRemove.Count == 0) return null;

            //Now we need to build a ChangeSet Graph
            Graph g = new Graph();
            g.BaseUri = new Uri("http://www.dotnetrdf.org/");
            g.NamespaceMap.AddNamespace("cs", new Uri(TalisChangeSetNamespace));

            //Make all the Nodes we need
            IUriNode rdfType = g.CreateUriNode("rdf:type");
            IUriNode changeSet = g.CreateUriNode("cs:ChangeSet");
            IUriNode subjOfChange = g.CreateUriNode("cs:subjectOfChange");
            IUriNode createdDate = g.CreateUriNode("cs:createdDate");
            ILiteralNode now = g.CreateLiteralNode(DateTime.Now.ToString(XmlSpecsHelper.XmlSchemaDateTimeFormat));
            IUriNode creator = g.CreateUriNode("cs:creatorName");
            ILiteralNode dotNetRDF = g.CreateLiteralNode("dotNetRDF");
            IUriNode changeReason = g.CreateUriNode("cs:changeReason");
            ILiteralNode dotNetRDFUpdate = g.CreateLiteralNode("Updates to the store were requested by a dotNetRDF powered application");
            IUriNode precedingChangeset = g.CreateUriNode("cs:precedingChangeSet");
            IUriNode removal = g.CreateUriNode("cs:removal");
            IUriNode addition = g.CreateUriNode("cs:addition");
            IUriNode rdfStmt = g.CreateUriNode("rdf:Statement");
            IUriNode rdfSubj = g.CreateUriNode("rdf:subject");
            IUriNode rdfPred = g.CreateUriNode("rdf:predicate");
            IUriNode rdfObj = g.CreateUriNode("rdf:object");

            //Find the Distinct Subjects from the list
            IEnumerable<INode> subjects = (from t in toAdd select t.Subject).Concat(from t in toRemove select t.Subject).Distinct();
            foreach (INode subj in subjects)
            {
                //Create a ChangeSet for this Subject
                IUriNode report = g.CreateUriNode(new Uri(Tools.ResolveUri(subj.GetHashCode() + "/changes/" + DateTime.Now.ToString(TalisChangeSetIDFormat), g.BaseUri.ToString())));
                g.Assert(new Triple(report, rdfType, changeSet));
                g.Assert(new Triple(report, subjOfChange, Tools.CopyNode(subj, g)));
                g.Assert(new Triple(report, createdDate, now));
                g.Assert(new Triple(report, creator, dotNetRDF));
                g.Assert(new Triple(report, changeReason, dotNetRDFUpdate));

                //Add Additions to this ChangeSet
                foreach (Triple t in toAdd.Where(t2 => t2.Subject.Equals(subj)))
                {
                    IBlankNode b = g.CreateBlankNode();
                    g.Assert(new Triple(report, addition, b));
                    g.Assert(new Triple(b, rdfType, rdfStmt));
                    g.Assert(new Triple(b, rdfSubj, Tools.CopyNode(t.Subject, g)));
                    g.Assert(new Triple(b, rdfPred, Tools.CopyNode(t.Predicate, g)));
                    g.Assert(new Triple(b, rdfObj, Tools.CopyNode(t.Object, g)));
                }

                //Add Removals to this ChangeSet
                foreach (Triple t in toRemove.Where(t2 => t2.Subject.Equals(subj)))
                {
                    IBlankNode b = g.CreateBlankNode();
                    g.Assert(new Triple(report, removal, b));
                    g.Assert(new Triple(b, rdfType, rdfStmt));
                    g.Assert(new Triple(b, rdfSubj, Tools.CopyNode(t.Subject, g)));
                    g.Assert(new Triple(b, rdfPred, Tools.CopyNode(t.Predicate, g)));
                    g.Assert(new Triple(b, rdfObj, Tools.CopyNode(t.Object, g)));
                }
            }

            return g;
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:88,代码来源:TalisPlatformConnector.cs

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

示例13: StorageVirtuosoBlankNodePersistence

        public void StorageVirtuosoBlankNodePersistence()
        {
            try
            {
                //Create our Test Graph
                Graph g = new Graph();
                g.BaseUri = new Uri("http://example.org/bnodes/");

                IBlankNode b = g.CreateBlankNode("blank");
                IUriNode rdfType = g.CreateUriNode("rdf:type");
                IUriNode bnode = g.CreateUriNode(":BlankNode");

                g.Assert(new Triple(b, rdfType, bnode));

                Assert.AreEqual(1, g.Triples.Count, "Should only be 1 Triple in the Test Graph");

                //Connect to Virtuoso
                VirtuosoManager manager = new VirtuosoManager("DB", VirtuosoTestUsername, VirtuosoTestPassword);

                //Save Graph
                manager.SaveGraph(g);

                //Retrieve
                Graph h = new Graph();
                Graph i = new Graph();
                manager.LoadGraph(h, g.BaseUri);
                manager.LoadGraph(i, g.BaseUri);

                Assert.AreEqual(1, h.Triples.Count, "Retrieved Graph should only contain 1 Triple");
                Assert.AreEqual(1, i.Triples.Count, "Retrieved Graph should only contain 1 Triple");

                Console.WriteLine("Contents of Retrieved Graph:");
                foreach (Triple t in h.Triples)
                {
                    Console.WriteLine(t.ToString());
                }
                Console.WriteLine();

                TestTools.CompareGraphs(h, i, true);

                //Save back again
                manager.SaveGraph(h);

                //Retrieve again
                Graph j = new Graph();
                manager.LoadGraph(j, g.BaseUri);

                Console.WriteLine("Contents of Retrieved Graph (Retrieved after saving original Retrieval):");
                foreach (Triple t in j.Triples)
                {
                    Console.WriteLine(t.ToString());
                }
                Console.WriteLine();

                TestTools.CompareGraphs(h, j, false);
                TestTools.CompareGraphs(i, j, false);

                //Save back yet again
                manager.SaveGraph(j);

                //Retrieve yet again
                Graph k = new Graph();
                manager.LoadGraph(k, g.BaseUri);

                Console.WriteLine("Contents of Retrieved Graph (Retrieved after saving second Retrieval):");
                foreach (Triple t in k.Triples)
                {
                    Console.WriteLine(t.ToString());
                }
                Console.WriteLine();

                TestTools.CompareGraphs(j, k, false);
            }
            catch (VirtuosoException virtEx)
            {
                TestTools.ReportError("Virtuoso Error", virtEx, true);
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Other Error", ex, true);
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:82,代码来源:VirtuosoTest.cs

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

示例15: NodesBlankNodeEquality

        public void NodesBlankNodeEquality()
        {
            try
            {
                Graph g = new Graph();
                g.BaseUri = new Uri("http://example.org/BlankNodeEquality");
                Graph h = new Graph();
                h.BaseUri = new Uri("http://example.org/BlankNodeEqualityTwo");
                Graph i = new Graph();
                i.BaseUri = new Uri("http://example.org/BlankNodeEquality");

                Console.WriteLine("Doing some Blank Node Equality Testing");
                Console.WriteLine("Blank Nodes are equal if they have the same ID and come from the same Graph which is established by Reference Equality between the two Graphs");

                IBlankNode b = g.CreateBlankNode();
                IBlankNode c = g.CreateBlankNode();
                IBlankNode d = h.CreateBlankNode();
                IBlankNode e = i.CreateBlankNode();

                //Shouldn't be equal
                Assert.AreNotEqual(b, c, "Two Anonymous Blank Nodes created by a Graph should be non-equal");
                Assert.AreNotEqual(c, d, "Anonymous Blank Nodes created by different Graphs (even with same ID) should be non-equal");
                Assert.AreNotEqual(b, d, "Anonymous Blank Nodes created by different Graphs (even with same ID) should be non-equal");
                Assert.AreNotEqual(d, e, "Anonymous Blank Nodes created by different Graphs (even with same ID) should be non-equal");

                //Should be equal
                Assert.AreEqual(b, b, "A Blank Node should be equal to itself");
                Assert.AreEqual(c, c, "A Blank Node should be equal to itself");
                Assert.AreEqual(d, d, "A Blank Node should be equal to itself");
                Assert.AreEqual(e, e, "A Blank Node should be equal to itself");
                Assert.AreNotEqual(b, e, "First Anonymous Blank Nodes generated by two Graphs with same Graph URI should have same ID but are still not equal");

                //Named Nodes
                IBlankNode one = g.CreateBlankNode("one");
                IBlankNode two = h.CreateBlankNode("one");
                IBlankNode three = i.CreateBlankNode("one");

                Assert.AreNotEqual(one, three, "Two User defined Blank Nodes with identical IDs from two Graphs with the same Graph URI should be non-equal");
                Assert.AreNotEqual(one, two, "Two User defined Blank Nodes with identical IDs from two Graphs with different Graph URIs should be non-equal");
                Assert.AreNotEqual(two, three, "Two User defined Blank Nodes with identical IDs from two Graphs with different Graph URIs should be non-equal");
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Error", ex, true);
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:46,代码来源:BasicTests1.cs


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