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


C# Graph.GetTriplesWithPredicate方法代码示例

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


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

示例1: ParseProfileAttribute

        private bool ParseProfileAttribute(RdfACoreParserContext context, IRdfAEvent evt)
        {
            foreach (Uri u in this.ParseUris(context, evt["profile"]))
            {
                try
                {
                    Graph g = new Graph();
#if !SILVERLIGHT
                    UriLoader.Load(g, u);
#else
                    throw new PlatformNotSupportedException("The @profile attribute is not currently supported under Silverlight/Windows Phone 7");
#endif

                    String prefixQuery = "PREFIX rdfa: <" + RdfAParser.RdfANamespace + "> SELECT SAMPLE(?prefix) AS ?NamespacePrefix SAMPLE(?uri) AS ?NamespaceURI WHERE { ?s rdfa:prefix ?prefix ; rdfa:uri ?uri } GROUP BY ?s HAVING (COUNT(?prefix) = 1 && COUNT(?uri) = 1)";
                    String termQuery = "PREFIX rdfa: <" + RdfAParser.RdfANamespace + "> SELECT SAMPLE(?term) AS ?Term SAMPLE(?uri) AS ?URI WHERE {?s rdfa:term ?term ; rdfa:uri ?uri } GROUP BY ?s HAVING (COUNT(?term) = 1 && COUNT(?uri) = 1)";

                    //Namespace Mappings
                    Object results = g.ExecuteQuery(prefixQuery);
                    if (results is SparqlResultSet)
                    {
                        SparqlResultSet rset = (SparqlResultSet)results;
                        foreach (SparqlResult r in rset.Results)
                        {
                            INode prefixNode = r["NamespacePrefix"];
                            INode nsNode = r["NamespaceURI"];
                            if (prefixNode.NodeType == NodeType.Literal && nsNode.NodeType == NodeType.Literal)
                            {
                                String prefix = ((ILiteralNode)prefixNode).Value.ToLower();
                                String ns = ((ILiteralNode)nsNode).Value;
                                context.Namespaces.AddNamespace(prefix, new Uri(ns));
                            }
                        }
                    }

                    //Term Mappings
                    results = g.ExecuteQuery(termQuery);
                    if (results is SparqlResultSet)
                    {
                        SparqlResultSet rset = (SparqlResultSet)results;
                        foreach (SparqlResult r in rset.Results)
                        {
                            INode termNode = r["Term"];
                            INode uriNode = r["URI"];
                            if (termNode.NodeType == NodeType.Literal && uriNode.NodeType == NodeType.Literal)
                            {
                                String term = ((ILiteralNode)termNode).Value;
                                String uri = ((ILiteralNode)uriNode).Value;
                                if (XmlSpecsHelper.IsNCName(term))
                                {
                                    context.Terms.AddNamespace(term, new Uri(uri));
                                }
                            }
                        }
                    }

                    //Vocabulary Setting
                    INode vocabNode = g.GetTriplesWithPredicate(g.CreateUriNode(new Uri(RdfAParser.RdfANamespace + "vocabulary"))).Select(t => t.Object).FirstOrDefault();
                    if (vocabNode != null)
                    {
                        if (vocabNode.NodeType == NodeType.Literal)
                        {
                            context.DefaultVocabularyUri = new Uri(((ILiteralNode)vocabNode).Value);
                        }
                        else if (vocabNode.NodeType == NodeType.Uri)
                        {
                            context.DefaultVocabularyUri = ((IUriNode)vocabNode).Uri;
                        }
                    }
                }
                catch
                {
                    return false;
                }
            }
            return true;
        }
开发者ID:jbunzel,项目名称:MvcRQ_git,代码行数:76,代码来源:RdfACoreParser.cs

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

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

示例4: SparqlConstructWithOptional

        public void SparqlConstructWithOptional()
        {
            Graph g = new Graph();
            g.LoadFromFile("InferenceTest.ttl");

            Graph expected = new Graph();
            expected.Assert(g.GetTriplesWithPredicate(g.CreateUriNode("rdf:type")));
            expected.Assert(g.GetTriplesWithPredicate(g.CreateUriNode("eg:Speed")));

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

            this.TestConstruct(g, expected, query);
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:13,代码来源:ConstructWithOptionalTests.cs

示例5: SparqlUpdateModifyWithOptional

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

            Graph expected = new Graph();
            expected.Assert(g.GetTriplesWithPredicate(g.CreateUriNode("rdf:type")));
            expected.Assert(g.GetTriplesWithPredicate(g.CreateUriNode("eg:Speed")));

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

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


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