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


C# IGraph.GetTriplesWithSubjectObject方法代码示例

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


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

示例1: FilterToEnumerable

        private IEnumerable<Triple> FilterToEnumerable(SelectFilter filter, IGraph g)
        {
            //Want to build an IEnumerable based on the Filter
            IEnumerable<Triple> ts = Enumerable.Empty<Triple>();
            INode s, p, o;
            int hash = (g.BaseUri == null) ? new Uri(GraphCollection.DefaultGraphUri).GetEnhancedHashCode() : g.BaseUri.GetEnhancedHashCode();

            if (filter.Subjects != null)
            {
                if (filter.Predicates != null)
                {
                    //Subject-Predicate filter
                    foreach (Entity subj in filter.Subjects)
                    {
                        s = SemWebConverter.FromSemWeb(subj, this.GetMapping(hash, g));
                        foreach (Entity pred in filter.Predicates)
                        {
                            p = SemWebConverter.FromSemWeb(pred, this.GetMapping(hash, g));
                            ts = ts.Concat(g.GetTriplesWithSubjectPredicate(s, p));
                        }
                    }
                }
                else if (filter.Objects != null)
                {
                    //Subject-Object filter
                    foreach (Entity subj in filter.Subjects)
                    {
                        s = SemWebConverter.FromSemWeb(subj, this.GetMapping(hash, g));
                        foreach (Resource obj in filter.Objects)
                        {
                            o = SemWebConverter.FromSemWeb(obj, this.GetMapping(hash, g));
                            ts = ts.Concat(g.GetTriplesWithSubjectObject(s, o));
                        }
                    }
                }
                else
                {
                    //Subjects filter
                    foreach (Entity subj in filter.Subjects)
                    {
                        s = SemWebConverter.FromSemWeb(subj, this.GetMapping(hash, g));
                        ts = ts.Concat(g.GetTriplesWithSubject(s));
                    }
                }
            }
            else if (filter.Predicates != null)
            {
                if (filter.Objects != null)
                {
                    //Predicate-Object Filter
                    foreach (Entity pred in filter.Predicates)
                    {
                        p = SemWebConverter.FromSemWeb(pred, this.GetMapping(hash, g));
                        foreach (Resource obj in filter.Objects)
                        {
                            o = SemWebConverter.FromSemWeb(obj, this.GetMapping(hash, g));
                            ts = ts.Concat(g.GetTriplesWithPredicateObject(p, o));
                        }
                    }
                }
                else
                {
                    //Predicate Filter
                    foreach (Entity pred in filter.Predicates)
                    {
                        p = SemWebConverter.FromSemWeb(pred, this.GetMapping(hash, g));
                        ts = ts.Concat(g.GetTriplesWithPredicate(p));
                    }
                }
            }
            else if (filter.Objects != null)
            {
                //Object Filter
                foreach (Resource obj in filter.Objects)
                {
                    o = SemWebConverter.FromSemWeb(obj, this.GetMapping(hash, g));
                    ts = ts.Concat(g.GetTriplesWithObject(o));
                }
            }
            else
            {
                //Everything is null so this is a Select All
                ts = g.Triples;
            }

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

示例2: TemplateToEnumerable

        /// <summary>
        /// Converts a SemWeb Statement Template to an IEnumerable of Triples
        /// </summary>
        /// <param name="template">Statement Template</param>
        /// <param name="g">Graph the Template should be created for</param>
        /// <returns></returns>
        private IEnumerable<Triple> TemplateToEnumerable(Statement template, IGraph g)
        {
            INode s, p, o;
            int hash;
            if (g.BaseUri == null)
            {
                hash = new Uri(GraphCollection.DefaultGraphUri).GetEnhancedHashCode();
            }
            else
            {
                hash = g.BaseUri.GetEnhancedHashCode();
            }
            if (template.Subject is Variable)
            {
                if (template.Predicate is Variable)
                {
                    if (template.Object is Variable)
                    {
                        //All three things are variables so this just checks that some Triple(s) are present
                        return g.Triples;
                    }
                    else
                    {
                        //Subject & Predicate are Variables
                        //Convert the Object and do a WithObject().Any() call
                        o = SemWebConverter.FromSemWeb(template.Object, this.GetMapping(hash, g));

                        return g.GetTriplesWithObject(o);
                    }
                }
                else if (template.Object is Variable)
                {
                    //Subject & Object are variables
                    //Convert the Predicate and do a WithPredicate() call
                    p = SemWebConverter.FromSemWeb(template.Predicate, this.GetMapping(hash, g));

                    return g.GetTriplesWithPredicate(p);
                }
                else
                {
                    //Subject is a Variable
                    //Convert the Predicate and Object and do a WithPredicateObject() call
                    p = SemWebConverter.FromSemWeb(template.Predicate, this.GetMapping(hash, g));
                    o = SemWebConverter.FromSemWeb(template.Object, this.GetMapping(hash, g));

                    return g.GetTriplesWithPredicateObject(p, o);
                }
            }
            else if (template.Predicate is Variable)
            {
                if (template.Object is Variable)
                {
                    //Predicate & Object are Variables
                    //Convert the Subject and do a WithSubject() call
                    s = SemWebConverter.FromSemWeb(template.Subject, this.GetMapping(hash, g));

                    return g.GetTriplesWithSubject(s);
                }
                else
                {
                    //Predicate is a Variable
                    //Convert the Subject and Object and do a WithSubjectObject() call
                    s = SemWebConverter.FromSemWeb(template.Subject, this.GetMapping(hash, g));
                    o = SemWebConverter.FromSemWeb(template.Object, this.GetMapping(hash, g));

                    return g.GetTriplesWithSubjectObject(s, o);
                }
            }
            else if (template.Object is Variable)
            {
                //Object is a Variable
                //Convert the Subject and Predicate and do a WithSubjectPredicate() call
                s = SemWebConverter.FromSemWeb(template.Subject, this.GetMapping(hash, g));
                p = SemWebConverter.FromSemWeb(template.Predicate, this.GetMapping(hash, g));

                return g.GetTriplesWithSubjectPredicate(s, p);
            }
            else
            {
                //Just convert the Triple and do a Contains() call
                Triple t = SemWebConverter.FromSemWeb(template, this.GetMapping(hash, g));
                if (g.ContainsTriple(t))
                {
                    return t.AsEnumerable();
                }
                else
                {
                    return Enumerable.Empty<Triple>();
                }
            }
        }
开发者ID:almostEric,项目名称:DotNetRDF-4.0,代码行数:97,代码来源:StoreSource.cs


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