Exemple #1
0
        public SparqlStrStarts(SparqlExpression str, SparqlExpression pattern)
        {
            switch (NullablePairExt.Get(str.Const, pattern.Const))
            {
            case NP.bothNull:
                Operator      = result => str.Operator(result).StartsWith(pattern.Operator(result));
                TypedOperator =
                    result => str.TypedOperator(result).Change(o => o.StartsWith(pattern.Operator(result)));
                AggregateLevel = SetAggregateLevel(str.AggregateLevel, pattern.AggregateLevel);
                break;

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

            case NP.rigthNull:

                Operator       = result => ((string)str.Const.Content).StartsWith(pattern.Operator(result));
                TypedOperator  = result => str.Const.Change(o => o.StartsWith(pattern.Operator(result)));
                AggregateLevel = pattern.AggregateLevel;
                break;

            case NP.bothNotNull:
                Const = str.Const.Change(o => o.StartsWith(pattern.Const.Content));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        public virtual void Create()
        {
            var lc = l.Const;
            var rc = r.Const;

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

            case NP.leftNull:
                Operator       = result => @operator(l.Operator(result), rc.Content);
                TypedOperator  = result => ApplyTyped(l.TypedOperator(result), rc);
                AggregateLevel = l.AggregateLevel;
                break;

            case NP.rigthNull:
                Operator       = result => @operator(lc.Content, r.Operator(result));
                TypedOperator  = result => ApplyTyped(lc, r.TypedOperator(result));
                AggregateLevel = r.AggregateLevel;
                break;

            case NP.bothNotNull:
                Const = ApplyTyped(lc, rc);
                break;
            }
        }
        public SparqlSameTerm(SparqlExpression str, SparqlExpression pattern)
        {
            switch (NullablePairExt.Get(str.Const, pattern.Const))
            {
            case NP.bothNull:
                this.Operator       = result => str.TypedOperator(result).Equals(pattern.TypedOperator(result));
                this.AggregateLevel = SetAggregateLevel(str.AggregateLevel, pattern.AggregateLevel);
                break;

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

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

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

            default:
                throw new ArgumentOutOfRangeException();
            }

            this.TypedOperator = result => new OV_bool(this.Operator(result));
        }
 public SparqlStrLength(SparqlExpression value) : base(value.AggregateLevel, value.IsStoreUsed)
 {
     if (value.Const != null)
     {
         Const = new OV_int(((string)value.Const.Content).Length);
     }
     else
     {
         Operator      = result => ((string)value.TypedOperator(result).Content).Length;
         TypedOperator = result => new OV_int(((string)value.TypedOperator(result).Content).Length);
     }
 }
Exemple #5
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
     }
 }
Exemple #6
0
        public SparqlIsIri(SparqlExpression value)
            : base(value.AggregateLevel, value.IsStoreUsed)
        {
            if (value.Const != null)
            {
                this.Const = new OV_bool(value.Const is IIriNode);
            }
            else
            {
                this.Operator      = result => value.TypedOperator(result) is IIriNode;
                this.TypedOperator = result => new OV_bool(value.TypedOperator(result) is IIriNode); // todo
            }

            // SetExprType(ObjectVariantEnum.Bool);
        }
Exemple #7
0
        public SparqlStrEnds(SparqlExpression str, SparqlExpression pattern)
        {
            switch (NullablePairExt.Get(str.Const, pattern.Const))
            {
            case NP.bothNull:
                this.Operator       = result => ((string)str.Operator(result)).EndsWith(pattern.Operator(result));
                this.AggregateLevel = SetAggregateLevel(str.AggregateLevel, pattern.AggregateLevel);
                this.TypedOperator  = result => str.TypedOperator(result).Change(o => ((string)o).EndsWith((string)pattern.TypedOperator(result).Content));
                break;

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

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

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

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        public SparqlStrBefore(SparqlExpression str, SparqlExpression pattern)
        {
            switch (NullablePairExt.Get(str.Const, pattern.Const))
            {
            case NP.bothNull:
                Operator       = result => StringBefore(str.Operator(result), pattern.Operator(result));
                AggregateLevel = SetAggregateLevel(str.AggregateLevel, pattern.AggregateLevel);
                TypedOperator  = result => str.TypedOperator(result).Change(o => StringBefore(o, (string)pattern.TypedOperator(result).Content));
                break;

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

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

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

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        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:
                this.Operator       = result => StringAfter(str.Operator(result), pattern.Operator(result));
                this.AggregateLevel = SetAggregateLevel(str.AggregateLevel, pattern.AggregateLevel);
                this.TypedOperator  = result => str.TypedOperator(result).Change(o => StringAfter(o, (string)pattern.TypedOperator(result).Content));
                break;

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

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

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

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #10
0
        internal void SetRegex(SparqlExpression patternExpression)
        {
            var varConst = this.variableExpression.Const;

            this.pattern = patternExpression;
            var   patternConst = patternExpression.Const;
            Regex regex;

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

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

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

                this.AggregateLevel = this.variableExpression.AggregateLevel;
                break;

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

            default:
                throw new ArgumentOutOfRangeException();
            }

            this.TypedOperator = result => new OV_bool(this.Operator(result));
        }
 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;
 }
Exemple #12
0
 public SparqlUri(SparqlExpression value, RdfQuery11Translator q)  : base(value.AggregateLevel, value.IsStoreUsed)
 {
     if (value.Const != null)
     {
         Const = new OV_iri(q.prolog.GetFromString((string)value.Const.Content));
     }
     else
     {
         Operator = result => new OV_iri(q.prolog.GetFromString((string)value.Operator(result).Content));
         //SetExprType(ObjectVariantEnum.Iri);
         TypedOperator =
             result => new OV_iri(q.prolog.GetFromString((string)value.TypedOperator(result).Content));
     }
 }
        public SparqlUnaryExpression(Func <dynamic, dynamic> @operator, SparqlExpression child)
            : base(child.AggregateLevel, child.IsStoreUsed)
        {
            var childConst = child.Const;

            if (childConst != null)
            {
                Const = childConst.Change(@operator(childConst.Content));
            }
            else
            {
                Operator      = result => @operator(child.Operator(result));
                TypedOperator = results => child.TypedOperator(results).Change(@operator);
            }
        }
        public void SetStartPosition(SparqlExpression value)
        {
            startExpression = value;
            switch (NullablePairExt.Get(strExpression.Const, startExpression.Const))
            {
            case NP.bothNull:
                Operator      = result => strExpression.Operator(result).Substring(startExpression.Operator(result));
                TypedOperator =
                    result =>
                    strExpression.TypedOperator(result)
                    .Change(o => o.Substring(startExpression.Operator(result)));
                AggregateLevel = SetAggregateLevel(strExpression.AggregateLevel, startExpression.AggregateLevel);
                break;

            case NP.leftNull:
                Operator      = result => strExpression.Operator(result).Substring(startExpression.Const.Content);
                TypedOperator =
                    result => startExpression.Const.
                    Change(o => strExpression.Operator(result).Substring(o));
                AggregateLevel = strExpression.AggregateLevel;
                break;

            case NP.rigthNull:
                Operator       = result => ((string)strExpression.Const.Content).Substring(startExpression.Operator(result));
                TypedOperator  = result => strExpression.Const.Change(o => o.Substring(startExpression.Operator(result)));
                AggregateLevel = startExpression.AggregateLevel;
                break;

            case NP.bothNotNull:
                Const = strExpression.Const.Change(o => o.Substring(startExpression.Const.Content));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #15
0
 public SparqlLang(SparqlExpression value)  : base(value.AggregateLevel, value.IsStoreUsed)
 {
     if (value.Const != null)
     {
         this.Const = new OV_string(((ILanguageLiteral)value.Const).Lang.Substring(1));
     }
     else
     {
         this.TypedOperator = result => new OV_language(this.Operator(result));
         this.Operator      = result =>
         {
             var f = value.TypedOperator(result);
             return(new OV_string(((ILanguageLiteral)f).Lang.Substring(1)));
         };
     }
 }
Exemple #16
0
        public SparqlUnaryExpression(Func <dynamic, dynamic> @operator, SparqlExpression child, string symbol)
            : base(child.AggregateLevel, child.IsStoreUsed)
        {
            this._child  = child;
            this._symbol = symbol;
            var childConst = child.Const;

            if (childConst != null)
            {
                this.Const = childConst.Change(@operator(childConst.Content));
            }
            else
            {
                this.Operator      = result => @operator(child.Operator(result));
                this.TypedOperator = results => child.TypedOperator(results).Change(@operator);
            }
        }
Exemple #17
0
 public SparqlDataType(SparqlExpression value)     : base(value.AggregateLevel, value.IsStoreUsed)
 {
     // SetExprType(ObjectVariantEnum.Iri);
     // value.SetExprType(ExpressionTypeEnum.literal);
     if (value.Const != null)
     {
         this.Const = new OV_iri(((ILiteralNode)value.Const).DataType);
     }
     else
     {
         this.Operator = this.TypedOperator = result =>
         {
             var r           = value.TypedOperator(result);
             var literalNode = r as ILiteralNode;
             if (literalNode != null)
             {
                 return(new OV_iri(literalNode.DataType));
             }
             throw new ArgumentException();
         };
     }
 }
Exemple #18
0
        public void Create()
        {
            if (parametersExpression == null)
            {
                switch (
                    NullableTripleExt.Get(stringExpression.Const, patternExpression.Const, replacementExpression.Const))
                {
                case NT.AllNull:
                    Operator = res =>
                               ((string)stringExpression.Operator(res)).Replace(
                        (string)patternExpression.Operator(res),
                        (string)replacementExpression.Operator(res));
                    TypedOperator =
                        res => stringExpression.TypedOperator(res)
                        .Change(o => ((string)o).Replace((string)patternExpression.Operator(res),
                                                         (string)replacementExpression.Operator(res)));
                    break;

                case NT.FirstNotNull:
                    Operator = res =>
                               ((string)stringExpression.Const.Content).Replace(
                        (string)patternExpression.Operator(res),
                        (string)replacementExpression.Operator(res));
                    TypedOperator =
                        res => stringExpression.Const
                        .Change(o => ((string)o).Replace((string)patternExpression.Operator(res),
                                                         (string)replacementExpression.Operator(res)));
                    break;

                case NT.SecondNotNull:
                    Operator = res =>
                               ((string)stringExpression.Operator(res)).Replace(
                        (string)patternExpression.Const.Content,
                        (string)replacementExpression.Operator(res));
                    TypedOperator =
                        res => stringExpression.TypedOperator(res)
                        .Change(o => ((string)o).Replace((string)patternExpression.Const.Content,
                                                         (string)replacementExpression.Operator(res)));
                    break;

                case NT.ThirdNotNull:
                    Operator = res =>
                               ((string)stringExpression.Operator(res)).Replace(
                        (string)patternExpression.Operator(res),
                        (string)replacementExpression.Const.Content);
                    TypedOperator =
                        res => stringExpression.TypedOperator(res)
                        .Change(o => ((string)o).Replace((string)patternExpression.Operator(res),
                                                         (string)replacementExpression.Const.Content));
                    break;

                case ~NT.FirstNotNull:
                    Operator = res =>
                               ((string)stringExpression.Operator(res)).Replace(
                        (string)patternExpression.Const.Content,
                        (string)replacementExpression.Const.Content);
                    TypedOperator =
                        res => stringExpression.TypedOperator(res)
                        .Change(o => ((string)o).Replace((string)patternExpression.Const.Content,
                                                         (string)replacementExpression.Const.Content));
                    break;

                case ~NT.SecondNotNull:
                    Operator = res =>
                               ((string)stringExpression.Const.Content).Replace(
                        (string)patternExpression.Operator(res),
                        (string)replacementExpression.Const.Content);
                    TypedOperator =
                        res => stringExpression.Const
                        .Change(o => ((string)o).Replace((string)patternExpression.Operator(res),
                                                         (string)replacementExpression.Const.Content));
                    break;

                case ~NT.ThirdNotNull:
                    Operator = res =>
                               ((string)stringExpression.Const.Content).Replace(
                        (string)patternExpression.Const.Content,
                        (string)replacementExpression.Operator(res));
                    TypedOperator =
                        res => stringExpression.Const
                        .Change(o => ((string)o).Replace((string)patternExpression.Const.Content,
                                                         (string)replacementExpression.Operator(res)));
                    break;

                case ~NT.AllNull:
                    Const = stringExpression.Const
                            .Change(o => ((string)o).Replace((string)patternExpression.Const.Content,
                                                             (string)replacementExpression.Const.Content));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            else
            {
                if (parametersExpression.Const != null)
                {
                    var flags = GetRegexOptions((string)parametersExpression.Const.Content);
                    switch (
                        NullableTripleExt.Get(stringExpression.Const, patternExpression.Const,
                                              replacementExpression.Const))
                    {
                    case NT.AllNull:
                        Operator = res => Regex.Replace(
                            (string)stringExpression.Operator(res),
                            (string)patternExpression.Operator(res),
                            (string)replacementExpression.Operator(res),
                            flags);
                        TypedOperator =
                            res => stringExpression.TypedOperator(res)
                            .Change(o => Regex.Replace(((string)o), (string)patternExpression.Operator(res),
                                                       (string)replacementExpression.Operator(res),
                                                       flags));
                        break;

                    case NT.FirstNotNull:
                        Operator = res => Regex.Replace(
                            ((string)stringExpression.Const.Content),
                            (string)patternExpression.Operator(res),
                            (string)replacementExpression.Operator(res),
                            flags);
                        TypedOperator =
                            res => stringExpression.Const
                            .Change(o => Regex.Replace(((string)o), (string)patternExpression.Operator(res),
                                                       (string)replacementExpression.Operator(res),
                                                       flags));
                        break;

                    case NT.SecondNotNull:
                        Operator = res => Regex.Replace(
                            ((string)stringExpression.Operator(res)),
                            (string)patternExpression.Const.Content,
                            (string)replacementExpression.Operator(res),
                            flags);
                        TypedOperator =
                            res => stringExpression.TypedOperator(res)
                            .Change(o => Regex.Replace(((string)o), (string)patternExpression.Const.Content,
                                                       (string)replacementExpression.Operator(res),
                                                       flags));
                        break;

                    case NT.ThirdNotNull:
                        Operator = res => Regex.Replace(
                            ((string)stringExpression.Operator(res)),
                            (string)patternExpression.Operator(res),
                            (string)replacementExpression.Const.Content);
                        TypedOperator =
                            res => stringExpression.TypedOperator(res)
                            .Change(o => Regex.Replace(((string)o), (string)patternExpression.Operator(res),
                                                       (string)replacementExpression.Const.Content,
                                                       flags));
                        break;

                    case ~NT.FirstNotNull:
                        Operator = res => Regex.Replace(
                            ((string)stringExpression.Operator(res)),
                            (string)patternExpression.Const.Content,
                            (string)replacementExpression.Const.Content,
                            flags);
                        TypedOperator =
                            res => stringExpression.TypedOperator(res)
                            .Change(o => Regex.Replace(((string)o), (string)patternExpression.Const.Content,
                                                       (string)replacementExpression.Const.Content,
                                                       flags));
                        break;

                    case ~NT.SecondNotNull:
                        Operator = res => Regex.Replace(
                            ((string)stringExpression.Const.Content),
                            (string)patternExpression.Operator(res),
                            (string)replacementExpression.Const.Content);
                        TypedOperator =
                            res => stringExpression.Const
                            .Change(o => Regex.Replace(((string)o), (string)patternExpression.Operator(res),
                                                       (string)replacementExpression.Const.Content,
                                                       flags));
                        break;

                    case ~NT.ThirdNotNull:
                        Operator = res => Regex.Replace(
                            ((string)stringExpression.Const.Content),
                            (string)patternExpression.Const.Content,
                            (string)replacementExpression.Operator(res),
                            flags);
                        TypedOperator =
                            res => stringExpression.Const
                            .Change(o => Regex.Replace(((string)o), (string)patternExpression.Const.Content,
                                                       (string)replacementExpression.Operator(res),
                                                       flags));
                        break;

                    case ~NT.AllNull:
                        Const = stringExpression.Const
                                .Change(o => Regex.Replace(((string)o), (string)patternExpression.Const.Content,
                                                           (string)replacementExpression.Const.Content,
                                                           flags));
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                else
                {
                    switch (NullableTripleExt.Get(stringExpression.Const, patternExpression.Const,
                                                  replacementExpression.Const))
                    {
                    case NT.AllNull:
                        Operator = res => Regex.Replace(
                            (string)stringExpression.Operator(res),
                            (string)patternExpression.Operator(res),
                            (string)replacementExpression.Operator(res),
                            patternExpression.Operator(res));
                        TypedOperator =
                            res => stringExpression.TypedOperator(res)
                            .Change(o => Regex.Replace(((string)o), (string)patternExpression.Operator(res),
                                                       (string)replacementExpression.Operator(res),
                                                       patternExpression.Operator(res)));
                        break;

                    case NT.FirstNotNull:
                        Operator = res => Regex.Replace(
                            ((string)stringExpression.Const.Content),
                            (string)patternExpression.Operator(res),
                            (string)replacementExpression.Operator(res),
                            patternExpression.Operator(res));
                        TypedOperator =
                            res => stringExpression.Const
                            .Change(o => Regex.Replace(((string)o), (string)patternExpression.Operator(res),
                                                       (string)replacementExpression.Operator(res),
                                                       patternExpression.Operator(res)));
                        break;

                    case NT.SecondNotNull:
                        Operator = res => Regex.Replace(
                            ((string)stringExpression.Operator(res)),
                            (string)patternExpression.Const.Content,
                            (string)replacementExpression.Operator(res),
                            patternExpression.Operator(res));
                        TypedOperator =
                            res => stringExpression.TypedOperator(res)
                            .Change(o => Regex.Replace(((string)o), (string)patternExpression.Const.Content,
                                                       (string)replacementExpression.Operator(res),
                                                       patternExpression.Operator(res)));
                        break;

                    case NT.ThirdNotNull:
                        Operator = res => Regex.Replace(
                            ((string)stringExpression.Operator(res)),
                            (string)patternExpression.Operator(res),
                            (string)replacementExpression.Const.Content);
                        TypedOperator =
                            res => stringExpression.TypedOperator(res)
                            .Change(o => Regex.Replace(((string)o), (string)patternExpression.Operator(res),
                                                       (string)replacementExpression.Const.Content,
                                                       patternExpression.Operator(res)));
                        break;

                    case ~NT.FirstNotNull:
                        Operator = res => Regex.Replace(
                            ((string)stringExpression.Operator(res)),
                            (string)patternExpression.Const.Content,
                            (string)replacementExpression.Const.Content,
                            patternExpression.Operator(res));
                        TypedOperator =
                            res => stringExpression.TypedOperator(res)
                            .Change(o => Regex.Replace(((string)o), (string)patternExpression.Const.Content,
                                                       (string)replacementExpression.Const.Content,
                                                       patternExpression.Operator(res)));
                        break;

                    case ~NT.SecondNotNull:
                        Operator = res => Regex.Replace(
                            ((string)stringExpression.Const.Content),
                            (string)patternExpression.Operator(res),
                            (string)replacementExpression.Const.Content);
                        TypedOperator =
                            res => stringExpression.Const
                            .Change(o => Regex.Replace(((string)o), (string)patternExpression.Operator(res),
                                                       (string)replacementExpression.Const.Content,
                                                       patternExpression.Operator(res)));
                        break;

                    case ~NT.ThirdNotNull:
                        Operator = res => Regex.Replace(
                            ((string)stringExpression.Const.Content),
                            (string)patternExpression.Const.Content,
                            (string)replacementExpression.Operator(res),
                            patternExpression.Operator(res));
                        TypedOperator =
                            res => stringExpression.Const
                            .Change(o => Regex.Replace(((string)o), (string)patternExpression.Const.Content,
                                                       (string)replacementExpression.Operator(res),
                                                       patternExpression.Operator(res)));
                        break;

                    case ~NT.AllNull:
                        Operator = res =>
                                   Regex.Replace((string)stringExpression.Const.Content, (string)patternExpression.Const.Content,
                                                 (string)replacementExpression.Const.Content,
                                                 patternExpression.Operator(res));
                        TypedOperator = res => stringExpression.Const
                                        .Change(o => Regex.Replace(((string)o), (string)patternExpression.Const.Content,
                                                                   (string)replacementExpression.Const.Content,
                                                                   patternExpression.Operator(res)));
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }
        }
Exemple #19
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)
                {
                    this.Const = new OV_bool(((string)str.Const.Content).Contains((string)pattern.Const.Content));
                }
                else
                {
                    this.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();
                    };
                    this.TypedOperator = result => new OV_bool(this.Operator(result));
                }
            }
            else
            {
                if (pattern.Const != null)
                {
                    this.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
                {
                    this.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();
                    };
                }

                this.TypedOperator = result => new OV_bool(this.Operator(result));
            }

            this.AggregateLevel = SetAggregateLevel(str.AggregateLevel, pattern.AggregateLevel);
        }
Exemple #20
0
        public SparqlIf(SparqlExpression conditionExpression1, SparqlExpression sparqlExpression2, SparqlExpression sparqlExpression3)
        {
            switch (NullableTripleExt.Get(conditionExpression1.Const, sparqlExpression2.Const, sparqlExpression3.Const))
            {
            case NT.AllNull:
                this.Operator = result =>
                {
                    var condition = conditionExpression1.Operator(result);
                    if (condition is bool)
                    {
                        return((bool)condition ? sparqlExpression2.Operator(result) : sparqlExpression3.Operator(result));
                    }
                    throw new ArgumentException();
                };
                this.TypedOperator = result =>
                {
                    var condition = conditionExpression1.Operator(result);
                    if (condition is bool)
                    {
                        return((bool)condition ? sparqlExpression2.TypedOperator(result) : sparqlExpression3.TypedOperator(result));
                    }
                    throw new ArgumentException();
                };
                this.AggregateLevel = SetAggregateLevel(conditionExpression1.AggregateLevel, sparqlExpression2.AggregateLevel, sparqlExpression3.AggregateLevel);
                break;

            case NT.FirstNotNull:
                if ((bool)conditionExpression1.Const.Content)
                {
                    this.Operator      = sparqlExpression2.Operator;
                    this.TypedOperator = sparqlExpression2.TypedOperator;
                }
                else
                {
                    this.Operator      = sparqlExpression3.Operator;
                    this.TypedOperator = sparqlExpression3.TypedOperator;
                }

                this.AggregateLevel = SetAggregateLevel(sparqlExpression2.AggregateLevel, sparqlExpression3.AggregateLevel);

                break;

            case NT.SecondNotNull:
                this.Operator = result =>
                {
                    var condition = conditionExpression1.Operator(result);
                    if (condition is bool)
                    {
                        return((bool)condition ? sparqlExpression2.Const.Content : sparqlExpression3.Operator(result));
                    }
                    throw new ArgumentException();
                };
                this.TypedOperator = result =>
                {
                    var condition = conditionExpression1.Operator(result);
                    if (condition is bool)
                    {
                        return((bool)condition ? sparqlExpression2.Const : sparqlExpression3.TypedOperator(result));
                    }
                    throw new ArgumentException();
                };
                this.AggregateLevel = SetAggregateLevel(conditionExpression1.AggregateLevel, sparqlExpression3.AggregateLevel);

                break;

            case NT.ThirdNotNull:
                this.Operator = result =>
                {
                    var condition = conditionExpression1.Operator(result);
                    if (condition is bool)
                    {
                        return((bool)condition ? sparqlExpression2.Operator(result) : sparqlExpression3.Const.Content);
                    }
                    throw new ArgumentException();
                };
                this.TypedOperator = result =>
                {
                    var condition = conditionExpression1.Operator(result);
                    if (condition is bool)
                    {
                        return((bool)condition ? sparqlExpression2.TypedOperator(result) : sparqlExpression3.Const);
                    }
                    throw new ArgumentException();
                };
                this.AggregateLevel = SetAggregateLevel(conditionExpression1.AggregateLevel, sparqlExpression2.AggregateLevel);

                break;

            case (NT)252:    // ~NT.ThirdNotNull:
                if ((bool)conditionExpression1.Const.Content)
                {
                    this.Const = sparqlExpression2.Const;
                }
                else
                {
                    this.Operator      = sparqlExpression3.Operator;
                    this.TypedOperator = sparqlExpression3.TypedOperator;
                }

                this.AggregateLevel = sparqlExpression3.AggregateLevel;
                break;

            case (NT)253:    // ~NT.SecondNotNull:
                if ((bool)conditionExpression1.Const.Content)
                {
                    this.Operator      = sparqlExpression2.Operator;
                    this.TypedOperator = sparqlExpression2.TypedOperator;
                }
                else
                {
                    this.Const = sparqlExpression3.Const;
                }

                this.AggregateLevel = sparqlExpression2.AggregateLevel;
                break;

            case (NT)254:    // ~NT.FirstNotNull:
                this.Operator = result =>
                {
                    var condition = conditionExpression1.Operator(result);
                    if (condition is bool)
                    {
                        return((bool)condition ? sparqlExpression2.Const.Content : sparqlExpression3.Const.Content);
                    }
                    throw new ArgumentException();
                };
                this.TypedOperator = result =>
                {
                    var condition = conditionExpression1.Operator(result);
                    if (condition is bool)
                    {
                        return((bool)condition ? sparqlExpression2.Const : sparqlExpression3.Const);
                    }
                    throw new ArgumentException();
                };
                this.AggregateLevel = conditionExpression1.AggregateLevel;
                break;

            case (NT)255:    // ~NT.AllNull:
                this.Const          = (bool)conditionExpression1.Const.Content ? sparqlExpression2.Const : sparqlExpression3.Const;
                this.AggregateLevel = VariableDependenceGroupLevel.Const;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        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));
        }