Пример #1
0
        public SparqlInCollectionExpression(SparqlExpression itemExpression, List <SparqlExpression> collection)
        {
            var cConsts = collection.Select(expression => expression.Const).ToArray();

            if (itemExpression.Const != null)
            {
                if (cConsts.Contains(itemExpression.Const))
                {
                    Const = new OV_bool(true);
                    return;
                }
                if (cConsts.All(c => c != null))
                {
                    Const = new OV_bool(false);
                    return;
                }
                AggregateLevel = SetAggregateLevel(collection.Select(c => c.AggregateLevel).ToArray());
            }
            else
            {
                AggregateLevel = SetAggregateLevel(itemExpression.AggregateLevel,
                                                   SetAggregateLevel(collection.Select(c => c.AggregateLevel).ToArray()));
            }

            Operator = result =>
            {
                var o = itemExpression.Operator(result);
                return(collection.Any(element => element.Operator(result).Equals(o)));
            };
            TypedOperator = o => new OV_bool(Operator(o));
            //SetExprType(ObjectVariantEnum.Bool);
        }
Пример #2
0
        public SparqlSameTerm(SparqlExpression str, SparqlExpression pattern)
        {
            switch (NullablePairExt.Get(str.Const, pattern.Const))
            {
            case NP.bothNull:
                Operator       = result => str.TypedOperator(result).Equals(pattern.TypedOperator(result));
                AggregateLevel = SetAggregateLevel(str.AggregateLevel, pattern.AggregateLevel);
                break;

            case NP.leftNull:
                Operator       = result => str.TypedOperator(result).Equals(pattern.Const);
                AggregateLevel = str.AggregateLevel;
                break;

            case NP.rigthNull:
                Operator       = result => str.Const.Equals(pattern.TypedOperator(result));
                AggregateLevel = pattern.AggregateLevel;
                break;

            case NP.bothNotNull:
                Const = new OV_bool(str.Const.Equals(pattern.Const));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            TypedOperator = result => new OV_bool(Operator(result));
        }
Пример #3
0
        public SparqlStrEnds(SparqlExpression str, SparqlExpression pattern)
        {
            switch (NullablePairExt.Get(str.Const, pattern.Const))
            {
            case NP.bothNull:
                Operator       = result => ((string)str.Operator(result)).EndsWith(pattern.Operator(result));
                AggregateLevel = SetAggregateLevel(str.AggregateLevel, pattern.AggregateLevel);
                TypedOperator  = result => str.TypedOperator(result).Change(o => ((string)o).EndsWith((string)pattern.TypedOperator(result).Content));
                break;

            case NP.leftNull:
                Operator       = result => ((string)str.Operator(result)).EndsWith((string)pattern.Const.Content);
                TypedOperator  = result => pattern.Const.Change(o => ((string)str.Operator(result)).EndsWith(o));
                AggregateLevel = str.AggregateLevel;
                break;

            case NP.rigthNull:
                Operator       = result => ((string)str.Const.Content).EndsWith(pattern.Operator(result));
                TypedOperator  = result => str.Const.Change(o => ((string)o).EndsWith((string)pattern.Operator(result).Content));
                AggregateLevel = pattern.AggregateLevel;
                break;

            case NP.bothNotNull:
                Const = new OV_bool(((string)str.Const.Content).EndsWith((string)pattern.Const.Content));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #4
0
        public SparqlStrAfter(SparqlExpression str, SparqlExpression pattern)
        {
            // TODO: Complete member initialization
            //str.SetExprType(ExpressionTypeEnum.@stringOrWithLang);
            //pattern.SetExprType(ExpressionTypeEnum.@stringOrWithLang);

            // SetExprType(ExpressionTypeEnum.@stringOrWithLang);
            switch (NullablePairExt.Get(str.Const, pattern.Const))
            {
            case NP.bothNull:
                Operator       = result => StringAfter(str.Operator(result), pattern.Operator(result));
                AggregateLevel = SetAggregateLevel(str.AggregateLevel, pattern.AggregateLevel);
                TypedOperator  = result => str.TypedOperator(result).Change(o => StringAfter(o, (string)pattern.TypedOperator(result).Content));
                break;

            case NP.leftNull:
                Operator       = result => StringAfter(str.Operator(result), (string)pattern.Const.Content);
                TypedOperator  = result => pattern.Const.Change(o => StringAfter(str.Operator(result), o));
                AggregateLevel = str.AggregateLevel;
                break;

            case NP.rigthNull:
                Operator       = result => StringAfter((string)str.Const.Content, pattern.Operator(result));
                TypedOperator  = result => str.Const.Change(o => StringAfter(o, (string)pattern.Operator(result).Content));
                AggregateLevel = pattern.AggregateLevel;
                break;

            case NP.bothNotNull:
                Const = new OV_bool(StringAfter((string)str.Const.Content, (string)pattern.Const.Content));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #5
0
        public SparqlLangMatches(SparqlExpression value, SparqlExpression langExpression)
        {
            //     value.SetExprType(ObjectVariantEnum.Str); //todo lang
            //  langExpression.SetExprType(ObjectVariantEnum.Str); //todo lang
            switch (NullablePairExt.Get(value.Const, langExpression.Const))
            {
            case NP.bothNull:
                Operator = result =>
                {
                    var lang      = value.Operator(result);
                    var langRange = langExpression.Operator(result);
                    return(Equals(langRange.Content, "*")
                    ? !string.IsNullOrWhiteSpace(langRange.Content)
                    : Equals(lang, langRange));
                };

                AggregateLevel = SetAggregateLevel(value.AggregateLevel, langExpression.AggregateLevel);
                break;

            case NP.leftNull:
                var rlang = langExpression.Const.Content;
                Operator = result =>
                {
                    var lang = value.Operator(result);
                    return(Equals(rlang, "*")
                            ? !string.IsNullOrWhiteSpace(lang)
                            : Equals(lang, rlang));
                };
                AggregateLevel = value.AggregateLevel;
                break;

            case NP.rigthNull:
                var llang = value.Const.Content;
                if ((llang).Equals("*"))
                {
                    Operator = result => !string.IsNullOrWhiteSpace(langExpression.Operator(result));
                }
                else
                {
                    Operator = result => Equals(llang, langExpression.Operator(result));
                }
                AggregateLevel = langExpression.AggregateLevel;
                break;

            case NP.bothNotNull:
                var ll = value.Const.Content;
                var rl = langExpression.Const.Content;
                Const = new OV_bool(Equals(rl, "*")
                            ? !string.IsNullOrWhiteSpace((string)ll)
                            : Equals(ll, rl));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            TypedOperator = result => new OV_bool(Operator(result));
        }
        internal void SetRegex(SparqlExpression patternExpression)
        {
            var   varConst     = variableExpression.Const;
            var   patternConst = patternExpression.Const;
            Regex regex;

            switch (NullablePairExt.Get(patternConst, varConst))
            {
            case NP.bothNull:
                break;

            case NP.leftNull:
                Operator = result =>
                {
                    string pattern = (string)patternExpression.TypedOperator(result).Content;
                    regex = CreateRegex(pattern);
                    return(regex.IsMatch((string)varConst.Content));
                };
                AggregateLevel = patternExpression.AggregateLevel;
                break;

            case NP.rigthNull:
                var content = (string)patternConst.Content;
                regex = CreateRegex(content);
                var varExpression = variableExpression as SparqlVarExpression;
                if (varExpression != null && isSimple.IsMatch(content))
                {
                    Operator = result =>
                    {
                        if (result.ContainsKey(varExpression.Variable))
                        {
                            return(regex.IsMatch(varExpression.Operator(result)));
                        }
                        return(store.GetTriplesWithTextObject(varExpression.Operator(result))
                               .Select(Selector(result, varExpression.Variable)));
                    };
                }
                else
                {
                    Operator = result => regex.IsMatch(variableExpression.Operator(result));
                }
                AggregateLevel = variableExpression.AggregateLevel;
                break;

            case NP.bothNotNull:
                regex = CreateRegex((string)patternConst.Content);
                Const = new OV_bool(regex.IsMatch((string)variableExpression.Const.Content));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            TypedOperator = result => new OV_bool(Operator(result));
        }
Пример #7
0
 public SparqlIsBlank(SparqlExpression value)  : base(value.AggregateLevel, value.IsStoreUsed)
 {
     //SetExprType(ObjectVariantEnum.Bool);
     if (value.Const != null)
     {
         Const = new OV_bool(value.Const is IBlankNode);
     }
     else
     {
         Operator      = result => value.TypedOperator(result) is IBlankNode;
         TypedOperator = result => new OV_bool(value.TypedOperator(result) is IBlankNode); //todo
     }
 }
Пример #8
0
        public SparqlOrExpression(SparqlExpression l, SparqlExpression r)

        {
            //l.SetExprType(ObjectVariantEnum.Bool);
            //r.SetExprType(ObjectVariantEnum.Bool);
            //SetExprType(ObjectVariantEnum.Bool);
            switch (NullablePairExt.Get(l.Const, r.Const))
            {
            case NP.bothNull:
                Operator       = res => l.Operator(res) || r.Operator(res);
                AggregateLevel = SetAggregateLevel(l.AggregateLevel, r.AggregateLevel);
                break;

            case NP.leftNull:
                if ((bool)l.Const.Content)
                {
                    Const = new OV_bool(true);
                }
                else
                {
                    Operator       = r.Operator;
                    AggregateLevel = r.AggregateLevel;
                }
                break;

            case NP.rigthNull:
                if ((bool)r.Const.Content)
                {
                    Const = new OV_bool(true);
                }
                else
                {
                    Operator       = l.Operator;
                    AggregateLevel = l.AggregateLevel;
                }
                break;

            case NP.bothNotNull:
                Const = new OV_bool((bool)l.Const.Content || (bool)r.Const.Content);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            TypedOperator = result => new OV_bool(Operator(result));
        }
Пример #9
0
 void Booleanliteral(out ObjectVariants value)
 {
     value = null;
     if (la.kind == 27)
     {
         Get();
         value = new OV_bool(true);
     }
     else if (la.kind == 28)
     {
         Get();
         value = new OV_bool(false);
     }
     else
     {
         SynErr(39);
     }
 }
        internal void SetRegex(SparqlExpression patternExpression)
        {
            var   varConst     = variableExpression.Const;
            var   patternConst = patternExpression.Const;
            Regex regex;

            switch (NullablePairExt.Get(patternConst, varConst))
            {
            case NP.bothNull:
                break;

            case NP.leftNull:
                Operator = result =>
                {
                    var pattern = patternExpression.TypedOperator(result).Content;
                    regex = CreateRegex((string)pattern);
                    return(regex.IsMatch((string)varConst.Content));
                };
                AggregateLevel = patternExpression.AggregateLevel;
                break;

            case NP.rigthNull:
                regex = CreateRegex((string)patternConst.Content);
                if (varConst != null)
                {
                    Const = new OV_bool(regex.IsMatch((string)varConst.Content));
                }
                else
                {
                    Operator       = result => regex.IsMatch(variableExpression.Operator(result));
                    AggregateLevel = variableExpression.AggregateLevel;
                }
                break;

            case NP.bothNotNull:
                regex = CreateRegex((string)patternConst.Content);
                Const = new OV_bool(regex.IsMatch((string)variableExpression.Const.Content));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            TypedOperator = result => new OV_bool(Operator(result));
        }
Пример #11
0
 public SparqlIsNum(SparqlExpression value)
     : base(value.AggregateLevel, value.IsStoreUsed)
 {
     if (value.Const != null)
     {
         Const = new OV_bool(value.Const is INumLiteral);
     }
     else
     {
         Operator      = result => value.TypedOperator(result) is INumLiteral;
         TypedOperator = result => new OV_bool(value.TypedOperator(result) is INumLiteral); //todo
     }
     //f is double ||
     //   f is long ||
     //   f is int ||
     //   f is short ||
     //   f is byte ||
     //   f is ulong ||
     //   f is uint ||
     //   f is ushort;
 }
        public SparqlEqualsExpression(SparqlExpression l, SparqlExpression r, NodeGenerator ng)
        {
            var lc = l.Const;
            var rc = r.Const;

            switch (NullablePairExt.Get(lc, rc))
            {
            case NP.bothNull:
                Operator       = result => l.TypedOperator(result).Equals(r.TypedOperator(result));
                AggregateLevel = SetAggregateLevel(l.AggregateLevel, r.AggregateLevel);
                break;

            case NP.leftNull:
                if (rc.Variant == ObjectVariantEnum.Iri)
                {
                    OV_iriint rcCoded = null;
                    Operator = result =>
                    {
                        var lVal = l.TypedOperator(result);
                        if (lVal.Variant == ObjectVariantEnum.Iri)
                        {
                            return(lVal.Equals(rc));
                        }
                        if (lVal.Variant == ObjectVariantEnum.IriInt)
                        {
                            if (rcCoded == null)
                            {
                                rcCoded = (OV_iriint)ng.GetUri((string)rc.Content);
                            }
                            return(((OV_iriint)lVal).code == rcCoded.code);
                        }
                        else
                        {
                            throw new AggregateException();
                        }
                    };
                }
                else
                {
                    Operator = result => l.TypedOperator(result).Equals(rc);
                }
                AggregateLevel = l.AggregateLevel;
                break;

            case NP.rigthNull:
                if (lc.Variant == ObjectVariantEnum.Iri)
                {
                    OV_iriint lcCoded = null;
                    Operator = result =>
                    {
                        var rVal = r.TypedOperator(result);
                        if (rVal.Variant == ObjectVariantEnum.Iri)
                        {
                            return(rVal.Equals(lc));
                        }
                        if (rVal.Variant == ObjectVariantEnum.IriInt)
                        {
                            if (lcCoded == null)
                            {
                                lcCoded = (OV_iriint)ng.GetUri((string)lc.Content);
                            }
                            return(((OV_iriint)rVal).code == lcCoded.code);
                        }
                        else
                        {
                            throw new AggregateException();
                        }
                    };
                }
                else
                {
                    Operator = result => lc.Equals(r.TypedOperator(result));
                }
                AggregateLevel = r.AggregateLevel;
                break;

            case NP.bothNotNull:
                Const = new OV_bool(lc.Equals(rc));
                break;
            }
            TypedOperator = result => new OV_bool(Operator(result));
        }
Пример #13
0
 public SparqlContains(SparqlExpression str, SparqlExpression pattern)
 {
     //SetExprType(ObjectVariantEnum.Bool);
     // str.SetExprType(ExpressionTypeEnum.stringOrWithLang); str.SetExprType(ExpressionTypeEnum.stringOrWithLang);
     //  pattern.SetExprType(ExpressionTypeEnum.stringOrWithLang); str.SetExprType(ExpressionTypeEnum.stringOrWithLang);
     if (str.Const != null)
     {
         if (pattern.Const != null)
         {
             Const = new OV_bool(((string)str.Const.Content).Contains((string)pattern.Const.Content));
         }
         else
         {
             Operator = result =>
             {
                 var ps = pattern.TypedOperator(result);
                 if ((str.Const is OV_langstring && ps is OV_langstring) ||
                     (str.Const is OV_langstring && ps is OV_string) ||
                     (str.Const is OV_string && ps is OV_string))
                 {
                     return(((string)str.Const.Content).Contains((string)ps.Content));
                 }
                 throw new ArgumentException();
             };
             TypedOperator = result => new OV_bool(Operator(result));
         }
     }
     else
     {
         if (pattern.Const != null)
         {
             Operator = result =>
             {
                 var s = str.TypedOperator(result);
                 if ((s is OV_langstring && pattern.Const is OV_langstring) ||
                     (s is OV_langstring && pattern.Const is OV_string) ||
                     (s is OV_string && pattern.Const is OV_string))
                 {
                     return(((string)s.Content).Contains((string)pattern.Const.Content));
                 }
                 throw new ArgumentException();
             };
         }
         else
         {
             Operator = result =>
             {
                 var s  = str.TypedOperator(result);
                 var ps = pattern.TypedOperator(result);
                 if ((s is OV_langstring && ps is OV_langstring) ||
                     (s is OV_langstring && ps is OV_string) ||
                     (s is OV_string && ps is OV_string))
                 {
                     return(((string)s.Content).Contains((string)ps.Content));
                 }
                 throw new ArgumentException();
             };
         }
         TypedOperator = result => new OV_bool(Operator(result));
     }
     AggregateLevel = SetAggregateLevel(str.AggregateLevel, pattern.AggregateLevel);
 }