Exemple #1
0
        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 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();
            }
        }
Exemple #3
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));
        }
Exemple #4
0
 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);
     }
 }
 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 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();
            }
            
          
        }
        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();
            }
        }
Exemple #8
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;
 }
Exemple #9
0
 public SparqlLCase(SparqlExpression value)        : base(value.AggregateLevel, value.IsStoreUsed)
 {
     if (value.Const != null)
     {
         Const = value.Const.Change(o => o.ToLower());
     }
     else
     {
         Operator      = result => value.Operator(result).ToLower();
         TypedOperator = result => value.TypedOperator(result).Change(o => o.ToLower());
     }
 }
Exemple #10
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 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 #12
0
        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);
            }
        }
Exemple #13
0
 public SparqlLang(SparqlExpression value)  : base(value.AggregateLevel, value.IsStoreUsed)
 {
     if (value.Const != null)
     {
         Const = new OV_string(((ILanguageLiteral)value.Const).Lang.Substring(1));
     }
     else
     {
         TypedOperator = result => new OV_language(Operator(result));
         Operator      = result =>
         {
             var f = value.TypedOperator(result);
             return(new OV_string(((ILanguageLiteral)f).Lang.Substring(1)));
         };
     }
 }
        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));
        }
 public SparqlDataType(SparqlExpression value)     : base(value.AggregateLevel, value.IsStoreUsed)
 {
     //SetExprType(ObjectVariantEnum.Iri);
     // value.SetExprType(ExpressionTypeEnum.literal);
     if (value.Const != null)
     {
         Const = new OV_iri(((ILiteralNode)value.Const).DataType);
     }
     else
     {
         Operator          =
             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 #16
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();
            }
        }
Exemple #17
0
        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));
        }
        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)
         {
             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);
 }