RDFIsLiteralFilter represents a filter for literal values of a variable.
Inheritance: RDFFilter
Exemplo n.º 1
0
        /// <summary>
        /// Applies the filter on the column corresponding to the variable in the given datarow
        /// </summary>
        internal override Boolean ApplyFilter(DataRow row, Boolean applyNegation)
        {
            Boolean keepRow = true;

            //Check is performed only if the row contains a column named like the filter's variable
            if (row.Table.Columns.Contains(this.Variable.ToString()))
            {
                //Depends on "IsLiteral" filter, because we must find numeric literals
                RDFIsLiteralFilter isLiteralFilter = new RDFIsLiteralFilter(this.Variable);
                keepRow = isLiteralFilter.ApplyFilter(row, false);

                //Successfull match if it is a literal whose value can be parsed into a "Decimal" object
                if (keepRow)
                {
                    String litVal = row[this.Variable.ToString()].ToString();

                    //Plain Literal
                    if (!litVal.Contains("^^") ||
                        litVal.EndsWith("^^") ||
                        RDFModelUtilities.GetUriFromString(litVal.Substring(litVal.LastIndexOf("^^", StringComparison.Ordinal) + 2)) == null)
                    {
                        try {
                            Decimal.Parse(litVal, CultureInfo.InvariantCulture);
                        }
                        catch {
                            keepRow = false;
                        }
                    }

                    //Typed Literal
                    else
                    {
                        try {
                            Decimal.Parse(litVal.Substring(0, litVal.LastIndexOf("^^", StringComparison.Ordinal)), CultureInfo.InvariantCulture);
                        }
                        catch {
                            keepRow = false;
                        }
                    }
                }

                //Apply the eventual negation
                if (applyNegation)
                {
                    keepRow = !keepRow;
                }
            }

            return(keepRow);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Applies the filter on the column corresponding to the variable in the given datarow
        /// </summary>
        internal override Boolean ApplyFilter(DataRow row, Boolean applyNegation) {
            Boolean keepRow = true;

            //Check is performed only if the row contains a column named like the filter's variable
            if (row.Table.Columns.Contains(this.Variable.ToString())) {

                //Depends on "IsLiteral" filter, because we must find numeric literals
                RDFIsLiteralFilter isLiteralFilter = new RDFIsLiteralFilter(this.Variable);
                keepRow                            = isLiteralFilter.ApplyFilter(row, false);

                //Successfull match if it is a literal whose value can be parsed into a "Decimal" object
                if (keepRow) {
                    String litVal                  = row[this.Variable.ToString()].ToString();

                    //Plain Literal
                    if (!litVal.Contains("^^") || litVal.EndsWith("^^") || RDFModelUtilities.GetUriFromString(litVal.Substring(litVal.LastIndexOf("^^", StringComparison.Ordinal) + 2)) == null) {
                        try {
                            Decimal.Parse(litVal, NumberStyles.Number, CultureInfo.InvariantCulture);
                        }
                        catch {
                            keepRow = false;
                        }
                    }

                    //Typed Literal
                    else {
                        try {
                            Decimal.Parse(litVal.Substring(0, litVal.LastIndexOf("^^", StringComparison.Ordinal)), NumberStyles.Number, CultureInfo.InvariantCulture);
                        }
                        catch {
                            keepRow = false;
                        }
                    }

                }

                //Apply the eventual negation
                if (applyNegation) {
                    keepRow = !keepRow;
                }
            }

            return keepRow;
        }