internal void SetLength(SparqlExpression lengthExpression)
        {
            this.lengthExpression = lengthExpression;
            switch (NullableTripleExt.Get(this.strExpression.Const, this.substExpression.Const, lengthExpression.Const))
            {
            case NT.AllNull:
                this.TypedOperator  = result => this.strExpression.TypedOperator(result).Change(o => o.Substring(this.substExpression.Operator(result), lengthExpression.Operator(result)));
                this.Operator       = result => this.strExpression.Operator(result).Substring(this.substExpression.Operator(result), lengthExpression.Operator(result));
                this.AggregateLevel = SetAggregateLevel(this.strExpression.AggregateLevel, this.substExpression.AggregateLevel, lengthExpression.AggregateLevel);
                break;

            case NT.FirstNotNull:
                this.TypedOperator  = result => this.strExpression.Const.Change(o => o.Substring(this.substExpression.Operator(result), lengthExpression.Operator(result)));
                this.Operator       = result => ((string)this.strExpression.Const.Content).Substring(this.substExpression.Operator(result), lengthExpression.Operator(result));
                this.AggregateLevel = SetAggregateLevel(this.substExpression.AggregateLevel, lengthExpression.AggregateLevel);
                break;

            case NT.SecondNotNull:
                this.TypedOperator  = result => this.strExpression.TypedOperator(result).Change(o => o.Substring(this.substExpression.Const.Content, lengthExpression.Operator(result)));
                this.Operator       = result => this.strExpression.Operator(result).Substring(this.substExpression.Const.Content, lengthExpression.Operator(result));
                this.AggregateLevel = SetAggregateLevel(this.strExpression.AggregateLevel, lengthExpression.AggregateLevel);
                break;

            case NT.ThirdNotNull:
                this.TypedOperator  = result => this.strExpression.TypedOperator(result).Change(o => o.Substring(this.substExpression.Operator(result), lengthExpression.Const.Content));
                this.Operator       = result => this.strExpression.Operator(result).Substring(this.substExpression.Operator(result), lengthExpression.Const.Content);
                this.AggregateLevel = SetAggregateLevel(this.strExpression.AggregateLevel, this.substExpression.AggregateLevel);
                break;

            case (NT)254:    // ~ NT.FirstNotNull
                this.TypedOperator  = result => this.strExpression.TypedOperator(result).Change(o => o.Substring(this.substExpression.Const.Content, lengthExpression.Const.Content));
                this.Operator       = result => this.strExpression.Operator(result).Substring(this.substExpression.Const.Content, lengthExpression.Const.Content);
                this.AggregateLevel = this.strExpression.AggregateLevel;
                break;

            case (NT)253:   // ~NT.SecondNotNull
                this.TypedOperator  = result => this.strExpression.Const.Change(o => o.Substring(this.substExpression.Operator(result), lengthExpression.Const.Content));
                this.Operator       = result => ((string)this.strExpression.Const.Content).Substring(this.substExpression.Operator(result), (int)lengthExpression.Const.Content);
                this.AggregateLevel = this.substExpression.AggregateLevel;
                break;

            case (NT)252:    // ~ NT.ThirdNotNull
                this.TypedOperator  = result => this.strExpression.Const.Change(o => o.Substring(this.substExpression.Const.Content, lengthExpression.Operator(result)));
                this.Operator       = result => ((string)this.strExpression.Const.Content).Substring((int)this.substExpression.Const.Content, lengthExpression.Operator(result));
                this.AggregateLevel = lengthExpression.AggregateLevel;
                break;

            case (NT)255:    // ~NT.AllNull
                this.Const = this.strExpression.Const.Change(o => o.Substring(this.substExpression.Const.Content, lengthExpression.Const.Content));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #2
0
        public void WriteXml(XmlWriter writer)
        {
            writer.WriteStartElement("groupConstrain");
            writer.WriteAttributeString("type", this.GetType().ToString());
            switch (NullableTripleExt.Get(this.sparqlExpression, this.sparqlFunctionCall, this.variableNode))
            {
            case NT.FirstNotNull:
                this.sparqlExpression.WriteXml(writer);
                break;

            case NT.SecondNotNull:
                this.sparqlFunctionCall.WriteXml(writer);
                break;

            case NT.ThirdNotNull:
                this.WriteXml(writer);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            writer.WriteEndElement();
        }
Beispiel #3
0
        public SparqlIf(SparqlExpression conditionExpression1, SparqlExpression sparqlExpression2, SparqlExpression sparqlExpression3)
        {
            switch (NullableTripleExt.Get(conditionExpression1.Const, sparqlExpression2.Const, sparqlExpression3.Const))
            {
            case NT.AllNull:
                Operator = result =>
                {
                    var condition = conditionExpression1.Operator(result);
                    if (condition is bool)
                    {
                        return((bool)condition ? sparqlExpression2.Operator(result) : sparqlExpression3.Operator(result));
                    }
                    throw new ArgumentException();
                };
                TypedOperator = result =>
                {
                    var condition = conditionExpression1.Operator(result);
                    if (condition is bool)
                    {
                        return((bool)condition ? sparqlExpression2.TypedOperator(result) : sparqlExpression3.TypedOperator(result));
                    }
                    throw new ArgumentException();
                };
                AggregateLevel = SetAggregateLevel(conditionExpression1.AggregateLevel, sparqlExpression2.AggregateLevel, sparqlExpression3.AggregateLevel);
                break;

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

                break;

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

                break;

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

                break;

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

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

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

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

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