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


C# TripleStore.Graph方法代码示例

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


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

示例1: EnsureTestResults

        private void EnsureTestResults(TripleStore store)
        {
            foreach (IGraph g in store.Graphs)
            {
                TestTools.ShowGraph(g);
                Console.WriteLine();
            }

            Assert.AreEqual(2, store.Graphs.Count, "Expected 2 Graphs");
            Assert.AreEqual(8, store.Graphs.Sum(g => g.Triples.Count), "Expected 4 Triples");

            IGraph def = store.Graph(null);
            IGraph named = store.Graph(new Uri("http://example.org/bnodes#graph"));

            HashSet<INode> subjects = new HashSet<INode>();
            foreach (Triple t in def.Triples)
            {
                subjects.Add(t.Subject);
            }
            foreach (Triple t in named.Triples)
            {
                subjects.Add(t.Subject);
            }

            Console.WriteLine("Subjects:");
            foreach (INode subj in subjects)
            {
                Console.WriteLine(subj.ToString() + " from Graph " + (subj.GraphUri != null ? subj.GraphUri.ToString() : "Default"));
            }
            Assert.AreEqual(4, subjects.Count, "Expected 4 distinct subjects");
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:31,代码来源:StoreHandlerBlankNodeTests.cs

示例2: ParsingStoreHandlerNQuadsImplicitActual

        private void ParsingStoreHandlerNQuadsImplicitActual()
        {
            this.EnsureTestData("test.nq");

            TripleStore store = new TripleStore();
            StreamParams ps = new StreamParams("test.nq", Encoding.ASCII);

            NQuadsParser parser = new NQuadsParser();
            parser.Load(store, ps);

            Assert.IsTrue(store.HasGraph(new Uri("http://www.dotnetrdf.org/configuration#")), "Configuration Vocab Graph should have been parsed from Dataset");
            Graph configOrig = new Graph();
            configOrig.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            IGraph config = store.Graph(new Uri("http://www.dotnetrdf.org/configuration#"));
            Assert.AreEqual(configOrig, config, "Configuration Vocab Graphs should have been equal");

            Assert.IsTrue(store.HasGraph(new Uri("http://www.dotnetrdf.org/leviathan#")), "Leviathan Function Library Graph should have been parsed from Dataset");
            Graph lvnOrig = new Graph();
            lvnOrig.LoadFromEmbeddedResource("VDS.RDF.Query.Expressions.Functions.LeviathanFunctionLibrary.ttl");
            IGraph lvn = store.Graph(new Uri("http://www.dotnetrdf.org/leviathan#"));
            Assert.AreEqual(lvnOrig, lvn, "Leviathan Function Library Graphs should have been equal");

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

示例3: SparqlUpdateAddCommand

        public void SparqlUpdateAddCommand()
        {
            IGraph g = new Graph();
            FileLoader.Load(g, "InferenceTest.ttl");
            g.BaseUri = new Uri("http://example.org/source");

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

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

            Assert.AreNotEqual(g, h, "Graphs should not be equal");

            SparqlUpdateParser parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet commands = parser.ParseFromString("ADD GRAPH <http://example.org/source> TO GRAPH <http://example.org/destination>");

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);
            processor.ProcessCommandSet(commands);

            g = store.Graph(new Uri("http://example.org/source"));
            h = store.Graph(new Uri("http://example.org/destination"));
            Assert.IsFalse(g.IsEmpty, "Source Graph should not be empty");
            Assert.IsFalse(h.IsEmpty, "Destination Graph should not be empty");
            Assert.IsTrue(h.HasSubGraph(g), "Destination Graph should have Source Graph as a subgraph");
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:28,代码来源:UpdateTests.cs

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

示例5: SparqlUpdateInsertCommand3

        public void SparqlUpdateInsertCommand3()
        {
            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 { ?s a ?type . ?type rdfs:subClassOf+ ?class };";
            command.CommandText += "INSERT { ?s ?property ?value } USING NAMED <http://example.org/temp> WHERE {?s ?p ?value . ?p rdfs:subPropertyOf+ ?property };";
            command.CommandText += "INSERT { ?s rdf:type rdfs:Class } USING NAMED <http://example.org/temp> WHERE { ?s rdfs:subClassOf ?class };";
            command.CommandText += "INSERT { ?s rdf:type rdf:Property } USING NAMED <http://example.org/temp> WHERE { ?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);
            Assert.IsTrue(def.IsEmpty, "Graph should be empty as the commands only used USING NAMED (so shouldn't have changed the dataset) and the Active Graph for the dataset was empty so there should have been nothing matched to generate insertions from");
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:27,代码来源:UpdateTests.cs

示例6: SparqlUpdateMoveCommand3

        public void SparqlUpdateMoveCommand3()
        {
            IGraph g = new Graph();
            FileLoader.Load(g, "InferenceTest.ttl");
            g.BaseUri = null;

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

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

            Assert.AreNotEqual(g, h, "Graphs should not be equal");

            SparqlUpdateParser parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet commands = parser.ParseFromString("MOVE DEFAULT TO GRAPH <http://example.org/destination>");

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);
            processor.ProcessCommandSet(commands);

            g = store.HasGraph(null) ? store.Graph(null) : null;
            h = store.Graph(new Uri("http://example.org/destination"));
            Assert.IsFalse(h.IsEmpty, "Destination Graph should not be empty");
            Assert.IsFalse(g == null, "Default Graph should still exist");
            Assert.IsTrue(g.IsEmpty, "Source Graph (the Default Graph) should be Empty");

            Graph orig = new Graph();
            FileLoader.Load(orig, "InferenceTest.ttl");
            Assert.AreEqual(orig, h, "Destination Graph should be equal to the original contents of the Source Graph");
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:32,代码来源:UpdateTests.cs

示例7: SparqlUpdateCopyCommand2

        public void SparqlUpdateCopyCommand2()
        {
            IGraph g = new Graph();
            FileLoader.Load(g, "InferenceTest.ttl");
            g.BaseUri = new Uri("http://example.org/source");

            IGraph h = new Graph();
            FileLoader.Load(h, "Turtle.ttl");
            h.BaseUri = null;

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

            Assert.AreNotEqual(g, h, "Graphs should not be equal");

            SparqlUpdateParser parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet commands = parser.ParseFromString("COPY GRAPH <http://example.org/source> TO DEFAULT");

            LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);
            processor.ProcessCommandSet(commands);

            g = store.Graph(new Uri("http://example.org/source"));
            h = store.Graph(null);
            Assert.IsFalse(g.IsEmpty, "Source Graph should not be empty");
            Assert.IsFalse(h.IsEmpty, "Destination Graph should not be empty");
            Assert.AreEqual(g, h, "Graphs should now be equal");
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:28,代码来源:UpdateTests.cs


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