Пример #1
0
 /// <summary>
 /// Default-ctor to build a filter on the given pattern
 /// </summary>
 public RDFExistsFilter(RDFPattern pattern)
 {
     if (pattern != null)
     {
         this.Pattern     = pattern;
         this.IsEvaluable = true;
     }
     else
     {
         throw new RDFQueryException("Cannot create RDFExistsFilter because given \"pattern\" parameter is null.");
     }
 }
Пример #2
0
        /// <summary>
        /// Adds the given pattern to the pattern group
        /// </summary>
        public RDFPatternGroup AddPattern(RDFPattern pattern)
        {
            //Accept the pattern if it carries at least one variable
            if (pattern != null && pattern.Variables.Count > 0)
            {
                if (!this.Patterns.Exists(p => p.Equals(pattern)))
                {
                    this.Patterns.Add(pattern);
                    this.PatternGroupID = RDFModelUtilities.CreateHash(this.ToString());

                    //Context
                    if (pattern.Context != null && pattern.Context is RDFVariable)
                    {
                        if (!this.Variables.Exists(v => v.Equals(pattern.Context)))
                        {
                            this.Variables.Add((RDFVariable)pattern.Context);
                        }
                    }

                    //Subject
                    if (pattern.Subject is RDFVariable)
                    {
                        if (!this.Variables.Exists(v => v.Equals(pattern.Subject)))
                        {
                            this.Variables.Add((RDFVariable)pattern.Subject);
                        }
                    }

                    //Predicate
                    if (pattern.Predicate is RDFVariable)
                    {
                        if (!this.Variables.Exists(v => v.Equals(pattern.Predicate)))
                        {
                            this.Variables.Add((RDFVariable)pattern.Predicate);
                        }
                    }

                    //Object
                    if (pattern.Object is RDFVariable)
                    {
                        if (!this.Variables.Exists(v => v.Equals(pattern.Object)))
                        {
                            this.Variables.Add((RDFVariable)pattern.Object);
                        }
                    }
                }
            }
            return(this);
        }
        /// <summary>
        /// Adds the given pattern to the pattern group
        /// </summary>
        public RDFPatternGroup AddPattern(RDFPattern pattern)
        {
            //Accept the pattern if it carries at least one variable
            if (pattern != null && pattern.Variables.Count > 0)
            {
                if (!this.GetPatterns().Any(p => p.Equals(pattern)))
                {
                    this.GroupMembers.Add(pattern);

                    //Context
                    if (pattern.Context != null && pattern.Context is RDFVariable)
                    {
                        if (!this.Variables.Any(v => v.Equals(pattern.Context)))
                        {
                            this.Variables.Add((RDFVariable)pattern.Context);
                        }
                    }

                    //Subject
                    if (pattern.Subject is RDFVariable)
                    {
                        if (!this.Variables.Any(v => v.Equals(pattern.Subject)))
                        {
                            this.Variables.Add((RDFVariable)pattern.Subject);
                        }
                    }

                    //Predicate
                    if (pattern.Predicate is RDFVariable)
                    {
                        if (!this.Variables.Any(v => v.Equals(pattern.Predicate)))
                        {
                            this.Variables.Add((RDFVariable)pattern.Predicate);
                        }
                    }

                    //Object
                    if (pattern.Object is RDFVariable)
                    {
                        if (!this.Variables.Any(v => v.Equals(pattern.Object)))
                        {
                            this.Variables.Add((RDFVariable)pattern.Object);
                        }
                    }
                }
            }
            return(this);
        }
Пример #4
0
        /// <summary>
        /// Adds the given pattern to the templates of the query
        /// </summary>
        public RDFConstructQuery AddTemplate(RDFPattern template)
        {
            if (template != null)
            {
                if (!this.Templates.Any(tp => tp.Equals(template)))
                {
                    this.Templates.Add(template);

                    //Context
                    if (template.Context != null && template.Context is RDFVariable)
                    {
                        if (!this.Variables.Any(v => v.Equals(template.Context)))
                        {
                            this.Variables.Add((RDFVariable)template.Context);
                        }
                    }

                    //Subject
                    if (template.Subject is RDFVariable)
                    {
                        if (!this.Variables.Any(v => v.Equals(template.Subject)))
                        {
                            this.Variables.Add((RDFVariable)template.Subject);
                        }
                    }

                    //Predicate
                    if (template.Predicate is RDFVariable)
                    {
                        if (!this.Variables.Any(v => v.Equals(template.Predicate)))
                        {
                            this.Variables.Add((RDFVariable)template.Predicate);
                        }
                    }

                    //Object
                    if (template.Object is RDFVariable)
                    {
                        if (!this.Variables.Any(v => v.Equals(template.Object)))
                        {
                            this.Variables.Add((RDFVariable)template.Object);
                        }
                    }
                }
            }
            return(this);
        }
Пример #5
0
        /// <summary>
        /// Prints the string representation of a pattern
        /// </summary>
        internal static String PrintPattern(RDFPattern pattern, List <RDFNamespace> prefixes)
        {
            String subj = PrintPatternMember(pattern.Subject, prefixes);
            String pred = PrintPatternMember(pattern.Predicate, prefixes);
            String obj  = PrintPatternMember(pattern.Object, prefixes);

            //CSPO pattern
            if (pattern.Context != null)
            {
                String ctx = PrintPatternMember(pattern.Context, prefixes);
                if (pattern.IsOptional)
                {
                    return("OPTIONAL { GRAPH " + ctx + " { " + subj + " " + pred + " " + obj + " } }");
                }
                return("GRAPH " + ctx + " { " + subj + " " + pred + " " + obj + " }");
            }

            //SPO pattern
            if (pattern.IsOptional)
            {
                return("OPTIONAL { " + subj + " " + pred + " " + obj + " }");
            }
            return(subj + " " + pred + " " + obj);
        }
 /// <summary>
 /// Default-ctor to build a filter on the given pattern
 /// </summary>
 public RDFNotExistsFilter(RDFPattern pattern) : base(pattern)
 {
 }