/// <summary>
 /// Default-ctor to build an equality filter between the given variable and the given RDF term 
 /// </summary>
 public RDFSameTermFilter(RDFVariable variable, RDFPatternMember rdfTerm) {
     if (variable != null) {
         if (rdfTerm != null) {
             this.Variable = variable;
             this.RDFTerm  = rdfTerm;
             this.FilterID = RDFModelUtilities.CreateHash(this.ToString());
         }
         else {
             throw new RDFQueryException("Cannot create RDFSameTermFilter because \"rdfTerm\" parameter is null.");
         }
     }
     else {
         throw new RDFQueryException("Cannot create RDFSameTermFilter because \"variable\" parameter is null.");
     }
 }
 /// <summary>
 /// Default-ctor to build a comparison filter of the given type on the given filters
 /// </summary>
 public RDFComparisonFilter(RDFQueryEnums.RDFComparisonFlavors comparisonFlavor, RDFPatternMember leftMember, RDFPatternMember rightMember) {
     if (leftMember != null) {
         if (rightMember != null) {
             this.ComparisonFlavor = comparisonFlavor;
             this.LeftMember       = leftMember;
             this.RightMember      = rightMember;
             this.FilterID         = RDFModelUtilities.CreateHash(this.ToString());
         }
         else {
             throw new RDFQueryException("Cannot create RDFComparisonFilter because given \"rightMember\" parameter is null.");
         }
     }
     else {
         throw new RDFQueryException("Cannot create RDFComparisonFilter because given \"leftMember\" parameter is null.");
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Evaluates this constraint against the given data graph
        /// </summary>
        internal override RDFValidationReport ValidateConstraint(RDFShapesGraph shapesGraph, RDFGraph dataGraph, RDFShape shape, RDFPatternMember focusNode, List <RDFPatternMember> valueNodes)
        {
            RDFValidationReport report = new RDFValidationReport();

            #region Evaluation
            if (valueNodes.Count < this.MinCount)
            {
                report.AddResult(new RDFValidationResult(shape,
                                                         RDFVocabulary.SHACL.MIN_COUNT_CONSTRAINT_COMPONENT,
                                                         focusNode,
                                                         shape is RDFPropertyShape ? ((RDFPropertyShape)shape).Path : null,
                                                         null,
                                                         shape.Messages,
                                                         shape.Severity));
            }
            #endregion

            return(report);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the value nodes of the given focus node
        /// </summary>
        internal static List <RDFPatternMember> GetValueNodesOf(this RDFGraph dataGraph, RDFShape shape, RDFPatternMember focusNode)
        {
            List <RDFPatternMember> result = new List <RDFPatternMember>();

            if (shape != null && dataGraph != null)
            {
                switch (shape)
                {
                //sh:NodeShape
                case RDFNodeShape nodeShape:
                    result.Add(focusNode);
                    break;

                //sh:PropertyShape
                case RDFPropertyShape propertyShape:
                    if (focusNode is RDFResource)
                    {
                        foreach (var triple in dataGraph.SelectTriplesBySubject((RDFResource)focusNode)
                                 .SelectTriplesByPredicate(((RDFPropertyShape)shape).Path))
                        {
                            result.Add(triple.Object);
                        }
                    }
                    break;
                }
            }
            return(RDFQueryUtilities.RemoveDuplicates(result));
        }
Esempio n. 5
0
        /// <summary>
        /// Gives a formatted string representation of the given pattern member
        /// </summary>
        internal static String PrintRDFPatternMember(RDFPatternMember patternMember)
        {
            if (patternMember != null) {

                #region Variable
                if (patternMember is RDFVariable) {
                    return patternMember.ToString();
                }
                #endregion

                #region Non-Variable

                #region Resource/Context
                if (patternMember is RDFResource || patternMember is RDFContext) {
                    if (patternMember is RDFResource && ((RDFResource)patternMember).IsBlank) {
                        return patternMember.ToString();
                    }
                    return "<" + patternMember + ">";
                }
                #endregion

                #region Literal
                if (patternMember is RDFPlainLiteral) {
                    if (((RDFPlainLiteral)patternMember).Language != String.Empty) {
                        return "\"" + ((RDFPlainLiteral)patternMember).Value + "\"@" + ((RDFPlainLiteral)patternMember).Language;
                    }
                    return "\"" + ((RDFPlainLiteral)patternMember).Value + "\"";
                }
                return "\"" + ((RDFTypedLiteral)patternMember).Value + "\"^^<" + RDFModelUtilities.GetDatatypeFromEnum(((RDFTypedLiteral)patternMember).Datatype) + ">";
                #endregion

                #endregion

            }
            throw new RDFQueryException("Cannot print pattern member because given \"patternMember\" parameter is null.");
        }
Esempio n. 6
0
        /// <summary>
        /// Evaluates this constraint against the given data graph
        /// </summary>
        internal override RDFValidationReport ValidateConstraint(RDFShapesGraph shapesGraph, RDFGraph dataGraph, RDFShape shape, RDFPatternMember focusNode, List <RDFPatternMember> valueNodes)
        {
            RDFValidationReport report = new RDFValidationReport();

            //Search for given not shape
            RDFShape notShape = shapesGraph.SelectShape(this.NotShape.ToString());

            if (notShape == null)
            {
                return(report);
            }

            #region Evaluation
            foreach (RDFPatternMember valueNode in valueNodes)
            {
                RDFValidationReport notShapeReport = RDFValidationEngine.ValidateShape(shapesGraph, dataGraph, notShape, new List <RDFPatternMember>()
                {
                    valueNode
                });
                if (notShapeReport.Conforms)
                {
                    report.AddResult(new RDFValidationResult(shape,
                                                             RDFVocabulary.SHACL.NOT_CONSTRAINT_COMPONENT,
                                                             focusNode,
                                                             shape is RDFPropertyShape ? ((RDFPropertyShape)shape).Path : null,
                                                             valueNode,
                                                             shape.Messages,
                                                             shape.Severity));
                }
            }
            #endregion

            return(report);
        }
Esempio n. 7
0
        /// <summary>
        /// Evaluates this constraint against the given data graph
        /// </summary>
        internal override RDFValidationReport ValidateConstraint(RDFShapesGraph shapesGraph, RDFGraph dataGraph, RDFShape shape, RDFPatternMember focusNode, List <RDFPatternMember> valueNodes)
        {
            RDFValidationReport report = new RDFValidationReport();

            #region Evaluation
            foreach (RDFPatternMember valueNode in valueNodes)
            {
                if (dataGraph.Any(t => t.Subject.Equals(focusNode) &&
                                  t.Predicate.Equals(this.DisjointPredicate) &&
                                  t.Object.Equals(valueNode)))
                {
                    report.AddResult(new RDFValidationResult(shape,
                                                             RDFVocabulary.SHACL.DISJOINT_CONSTRAINT_COMPONENT,
                                                             focusNode,
                                                             shape is RDFPropertyShape ? ((RDFPropertyShape)shape).Path : null,
                                                             valueNode,
                                                             shape.Messages,
                                                             shape.Severity));
                }
            }
            #endregion

            return(report);
        }
        public void SelectDogsOrCats_UnionWithNext_Test()
        {
            // CREATE SELECT QUERY
            RDFSelectQuery selectQuery = new RDFSelectQuery();

            selectQuery.AddPrefix(RDFNamespaceRegister.GetByPrefix("dc"));
            selectQuery.AddPrefix(RDFNamespaceRegister.GetByPrefix("foaf"));

            var x = new RDFVariable("x");
            var y = new RDFVariable("y");

            RDFPatternMember dogOfPredicate = GraphBuilder2.dogOf;
            RDFPatternMember catOfPredicate = GraphBuilder2.catOf;

            var x_dogOf_y = new RDFPattern(x, dogOfPredicate, y);
            var x_catOf_y = new RDFPattern(x, catOfPredicate, y);

            //var orFilter = new RDFBooleanOrFilter(x_dogOf_y, x_catOf_y);

            // CREATE PATTERN GROUP FROM A LIST OF PATTERNS
            var pg1 = new RDFPatternGroup("PG1");

            pg1.AddPattern(x_dogOf_y.UnionWithNext());
            pg1.AddPattern(x_catOf_y);

            selectQuery.AddPatternGroup(pg1);

            selectQuery.AddProjectionVariable(x);
            selectQuery.AddProjectionVariable(y);

            selectQuery.AddModifier(new RDFOrderByModifier(x, RDFQueryEnums.RDFOrderByFlavors.ASC));



            var sparqlCommand = selectQuery.ToString();

            /*
             * Generates this sparql command
             *
             * PREFIX dc: <http://purl.org/dc/elements/1.1/>
             * PREFIX foaf: <http://xmlns.com/foaf/0.1/>
             *
             * SELECT ?X ?Y
             * WHERE {
             * {
             * { ?X dc:dogOf ?Y }
             * UNION
             * { ?X dc:catOf ?Y }
             * }
             * }
             * ORDER BY ASC(?X)
             */

            // APPLY SELECT QUERY TO GRAPH
            RDFSelectQueryResult selectQueryResult = selectQuery.ApplyToGraph(graph);

            // EXPORT SELECT QUERY RESULTS TO SPARQL XML FORMAT (FILE)
            selectQueryResult.ToSparqlXmlResult(@"C:\TEMP\select_results.srq");

            Assert.Equal(2, selectQueryResult.SelectResultsCount);

            //DataRow row = selectQueryResult.SelectResults.Rows[0];
            //var dog = row[0].ToString();
            //var person = row[1].ToString();
            //Assert.Equal(pluto.URI.ToString(), dog);
            //Assert.Equal(mickeyMouse.URI.ToString(), person);


            /*
             * Generates this file content
             *
             * <?xml version="1.0" encoding="utf-8"?>
             * <sparql xmlns="http://www.w3.org/2005/sparql-results#">
             * <head>
             * <variable name="?X" />
             * <variable name="?Y" />
             * </head>
             * <results>
             * <result>
             * <binding name="?X">
             * <uri>https://en.wikipedia.org/wiki/Figaro_(Disney)</uri>
             * </binding>
             * <binding name="?Y">
             * <uri>https://en.wikipedia.org/wiki/Minnie_Mouse</uri>
             * </binding>
             * </result>
             * <result>
             * <binding name="?X">
             * <uri>https://en.wikipedia.org/wiki/Pluto_(Disney)</uri>
             * </binding>
             * <binding name="?Y">
             * <uri>https://en.wikipedia.org/wiki/Mickey_Mouse</uri>
             * </binding>
             * </result>
             * </results>
             * </sparql>
             */
        }
Esempio n. 9
0
        /// <summary>
        /// Evaluates this constraint against the given data graph
        /// </summary>
        internal override RDFValidationReport ValidateConstraint(RDFShapesGraph shapesGraph, RDFGraph dataGraph, RDFShape shape, RDFPatternMember focusNode, List <RDFPatternMember> valueNodes)
        {
            RDFValidationReport report = new RDFValidationReport();

            #region Evaluation
            foreach (RDFPatternMember valueNode in valueNodes)
            {
                switch (valueNode)
                {
                //Resource
                case RDFResource valueNodeResource:
                    report.AddResult(new RDFValidationResult(shape,
                                                             RDFVocabulary.SHACL.DATATYPE_CONSTRAINT_COMPONENT,
                                                             focusNode,
                                                             shape is RDFPropertyShape ? ((RDFPropertyShape)shape).Path : null,
                                                             valueNode,
                                                             shape.Messages,
                                                             shape.Severity));
                    break;

                //PlainLiteral
                case RDFPlainLiteral valueNodePlainLiteral:
                    if (this.Datatype != RDFModelEnums.RDFDatatypes.XSD_STRING ||
                        !string.IsNullOrEmpty(valueNodePlainLiteral.Language))
                    {
                        report.AddResult(new RDFValidationResult(shape,
                                                                 RDFVocabulary.SHACL.DATATYPE_CONSTRAINT_COMPONENT,
                                                                 focusNode,
                                                                 shape is RDFPropertyShape ? ((RDFPropertyShape)shape).Path : null,
                                                                 valueNode,
                                                                 shape.Messages,
                                                                 shape.Severity));
                    }
                    break;

                //TypedLiteral
                case RDFTypedLiteral valueNodeTypedLiteral:
                    if (this.Datatype != valueNodeTypedLiteral.Datatype)
                    {
                        report.AddResult(new RDFValidationResult(shape,
                                                                 RDFVocabulary.SHACL.DATATYPE_CONSTRAINT_COMPONENT,
                                                                 focusNode,
                                                                 shape is RDFPropertyShape ? ((RDFPropertyShape)shape).Path : null,
                                                                 valueNode,
                                                                 shape.Messages,
                                                                 shape.Severity));
                    }
                    break;
                }
            }
            #endregion

            return(report);
        }
Esempio n. 10
0
        /// <summary>
        /// Creates a graph from a datatable with "Subject-Predicate-Object" columns.
        /// </summary>
        public static RDFGraph FromDataTable(DataTable table)
        {
            var result = new RDFGraph();

            //Check the structure of the datatable for consistency against the "S-P-O" RDF model
            if (table != null && table.Columns.Count == 3)
            {
                if (table.Columns.Contains("?SUBJECT") &&
                    table.Columns.Contains("?PREDICATE") &&
                    table.Columns.Contains("?OBJECT"))
                {
                    #region CONTEXT
                    //Parse the name of the datatable for Uri, in order to assign the graph name
                    Uri graphUri;
                    if (Uri.TryCreate(table.TableName, UriKind.Absolute, out graphUri))
                    {
                        result.SetContext(graphUri);
                    }
                    #endregion

                    //Iterate the rows of the datatable
                    foreach (DataRow tableRow in table.Rows)
                    {
                        #region SUBJECT
                        //Parse the triple subject
                        if (!tableRow.IsNull("?SUBJECT") && !String.IsNullOrEmpty(tableRow["?SUBJECT"].ToString()))
                        {
                            RDFPatternMember rowSubj = RDFQueryUtilities.ParseRDFPatternMember(tableRow["?SUBJECT"].ToString());
                            if (rowSubj is RDFResource)
                            {
                                #region PREDICATE
                                //Parse the triple predicate
                                if (!tableRow.IsNull("?PREDICATE") && !String.IsNullOrEmpty(tableRow["?PREDICATE"].ToString()))
                                {
                                    RDFPatternMember rowPred = RDFQueryUtilities.ParseRDFPatternMember(tableRow["?PREDICATE"].ToString());
                                    if (rowPred is RDFResource && !((RDFResource)rowPred).IsBlank)
                                    {
                                        #region OBJECT
                                        //Parse the triple object
                                        if (!tableRow.IsNull("?OBJECT"))
                                        {
                                            RDFPatternMember rowObj = RDFQueryUtilities.ParseRDFPatternMember(tableRow["?OBJECT"].ToString());
                                            if (rowObj is RDFResource)
                                            {
                                                result.AddTriple(new RDFTriple((RDFResource)rowSubj, (RDFResource)rowPred, (RDFResource)rowObj));
                                            }
                                            else
                                            {
                                                result.AddTriple(new RDFTriple((RDFResource)rowSubj, (RDFResource)rowPred, (RDFLiteral)rowObj));
                                            }
                                        }
                                        else
                                        {
                                            throw new RDFModelException("Cannot read RDF graph from datatable because given \"table\" parameter contains a row having NULL value in the \"?OBJECT\" column.");
                                        }
                                        #endregion
                                    }
                                    else
                                    {
                                        throw new RDFModelException("Cannot read RDF graph from datatable because given \"table\" parameter contains a row having a blank resource or a literal in the \"?PREDICATE\" column.");
                                    }
                                }
                                else
                                {
                                    throw new RDFModelException("Cannot read RDF graph from datatable because given \"table\" parameter contains a row having null or empty value in the \"?PREDICATE\" column.");
                                }
                                #endregion
                            }
                            else
                            {
                                throw new RDFModelException("Cannot read RDF graph from datatable because given \"table\" parameter contains a row not having a resource in the \"?SUBJECT\" column.");
                            }
                        }
                        else
                        {
                            throw new RDFModelException("Cannot read RDF graph from datatable because given \"table\" parameter contains a row having null or empty value in the \"?SUBJECT\" column.");
                        }
                        #endregion
                    }
                }
                else
                {
                    throw new RDFModelException("Cannot read RDF graph from datatable because given \"table\" parameter does not have the required columns \"?SUBJECT\", \"?PREDICATE\", \"?OBJECT\".");
                }
            }
            else
            {
                throw new RDFModelException("Cannot read RDF graph from datatable because given \"table\" parameter is null, or it does not have exactly 3 columns.");
            }

            return(result);
        }
Esempio n. 11
0
        /// <summary>
        /// Evaluates this constraint against the given data graph
        /// </summary>
        internal override RDFValidationReport ValidateConstraint(RDFShapesGraph shapesGraph, RDFGraph dataGraph, RDFShape shape, RDFPatternMember focusNode, List <RDFPatternMember> valueNodes)
        {
            RDFValidationReport report = new RDFValidationReport();

            //Search for given xone shapes
            List <RDFShape> xoneShapes = new List <RDFShape>();

            foreach (RDFResource xoneShapeUri in this.XoneShapes.Values)
            {
                RDFShape xoneShape = shapesGraph.SelectShape(xoneShapeUri.ToString());
                if (xoneShape != null)
                {
                    xoneShapes.Add(xoneShape);
                }
            }

            #region Evaluation
            foreach (RDFPatternMember valueNode in valueNodes)
            {
                Int32 valueNodeConformsCounter = 0;
                foreach (RDFShape xoneShape in xoneShapes)
                {
                    RDFValidationReport xoneShapeReport = RDFValidationEngine.ValidateShape(shapesGraph, dataGraph, xoneShape, new List <RDFPatternMember>()
                    {
                        valueNode
                    });
                    if (xoneShapeReport.Conforms)
                    {
                        valueNodeConformsCounter++;
                    }
                }

                if (valueNodeConformsCounter != 1)
                {
                    report.AddResult(new RDFValidationResult(shape,
                                                             RDFVocabulary.SHACL.XONE_CONSTRAINT_COMPONENT,
                                                             focusNode,
                                                             shape is RDFPropertyShape ? ((RDFPropertyShape)shape).Path : null,
                                                             valueNode,
                                                             shape.Messages,
                                                             shape.Severity));
                }
            }
            #endregion

            return(report);
        }
        /// <summary>
        /// Evaluates this constraint against the given data graph
        /// </summary>
        internal override RDFValidationReport ValidateConstraint(RDFShapesGraph shapesGraph, RDFGraph dataGraph, RDFShape shape, RDFPatternMember focusNode, List <RDFPatternMember> valueNodes)
        {
            RDFValidationReport     report         = new RDFValidationReport();
            List <RDFPatternMember> classInstances = dataGraph.GetInstancesOfClass(this.ClassType);

            #region Evaluation
            foreach (RDFPatternMember valueNode in valueNodes)
            {
                switch (valueNode)
                {
                //Resource
                case RDFResource valueNodeResource:
                    if (!classInstances.Any(x => x.Equals(valueNodeResource)))
                    {
                        report.AddResult(new RDFValidationResult(shape,
                                                                 RDFVocabulary.SHACL.CLASS_CONSTRAINT_COMPONENT,
                                                                 focusNode,
                                                                 shape is RDFPropertyShape ? ((RDFPropertyShape)shape).Path : null,
                                                                 valueNode,
                                                                 shape.Messages,
                                                                 shape.Severity));
                    }
                    break;

                //Literal
                case RDFLiteral valueNodeLiteral:
                    report.AddResult(new RDFValidationResult(shape,
                                                             RDFVocabulary.SHACL.CLASS_CONSTRAINT_COMPONENT,
                                                             focusNode,
                                                             shape is RDFPropertyShape ? ((RDFPropertyShape)shape).Path : null,
                                                             valueNode,
                                                             shape.Messages,
                                                             shape.Severity));
                    break;
                }
            }
            #endregion

            return(report);
        }
        /// <summary>
        /// Evaluates this constraint against the given data graph
        /// </summary>
        internal override RDFValidationReport ValidateConstraint(RDFShapesGraph shapesGraph, RDFGraph dataGraph, RDFShape shape, RDFPatternMember focusNode, List <RDFPatternMember> valueNodes)
        {
            RDFValidationReport report = new RDFValidationReport();

            //Search for given property shape
            RDFPropertyShape propertyShape = shapesGraph.SelectShape(this.PropertyShapeUri.ToString()) as RDFPropertyShape;

            if (propertyShape == null)
            {
                return(report);
            }

            #region Evaluation
            RDFValidationReport propertyShapeReport = RDFValidationEngine.ValidateShape(shapesGraph, dataGraph, propertyShape, valueNodes);
            if (!propertyShapeReport.Conforms)
            {
                report.MergeResults(propertyShapeReport);
            }
            #endregion

            return(report);
        }
        /// <summary>
        /// Evaluates this constraint against the given data graph
        /// </summary>
        internal override RDFValidationReport ValidateConstraint(RDFShapesGraph shapesGraph, RDFGraph dataGraph, RDFShape shape, RDFPatternMember focusNode, List <RDFPatternMember> valueNodes)
        {
            RDFValidationReport report = new RDFValidationReport();

            #region Evaluation
            if (this.Closed)
            {
                //Extend ignored properties with paths of property constraints
                List <RDFResource> allowedProperties = new List <RDFResource>(this.IgnoredProperties.Values);
                IEnumerable <RDFPropertyConstraint> propertyConstraints = shape.Constraints.OfType <RDFPropertyConstraint>();
                foreach (RDFPropertyConstraint propertyConstraint in propertyConstraints)
                {
                    RDFPropertyShape propertyShape = shapesGraph.SelectShape(propertyConstraint.PropertyShapeUri.ToString()) as RDFPropertyShape;
                    if (propertyShape != null)
                    {
                        allowedProperties.Add(propertyShape.Path);
                    }
                }

                //Detect unallowed predicates
                foreach (RDFPatternMember valueNode in valueNodes)
                {
                    if (valueNode is RDFResource valueNodeResource)
                    {
                        RDFGraph valuenodeResourceGraph          = dataGraph.SelectTriplesBySubject(valueNodeResource);
                        IEnumerable <RDFTriple> unallowedTriples = valuenodeResourceGraph.Where(t => !allowedProperties.Any(p => p.Equals(t.Predicate)));
                        foreach (RDFTriple unallowedTriple in unallowedTriples)
                        {
                            report.AddResult(new RDFValidationResult(shape,
                                                                     RDFVocabulary.SHACL.CLOSED_CONSTRAINT_COMPONENT,
                                                                     valueNodeResource,
                                                                     unallowedTriple.Predicate as RDFResource,
                                                                     unallowedTriple.Object,
                                                                     shape.Messages,
                                                                     shape.Severity));
                        }
                    }
                }
            }
            #endregion

            return(report);
        }
Esempio n. 15
0
        /// <summary>
        /// Evaluates this constraint against the given data graph
        /// </summary>
        internal override RDFValidationReport ValidateConstraint(RDFShapesGraph shapesGraph, RDFGraph dataGraph, RDFShape shape, RDFPatternMember focusNode, List <RDFPatternMember> valueNodes)
        {
            RDFValidationReport report = new RDFValidationReport();

            //Search for given or shapes
            List <RDFShape> orShapes = new List <RDFShape>();

            foreach (RDFResource orShapeUri in this.OrShapes.Values)
            {
                RDFShape orShape = shapesGraph.SelectShape(orShapeUri.ToString());
                if (orShape != null)
                {
                    orShapes.Add(orShape);
                }
            }

            #region Evaluation
            foreach (RDFPatternMember valueNode in valueNodes)
            {
                bool valueNodeConforms = false;
                foreach (RDFShape orShape in orShapes)
                {
                    RDFValidationReport orShapeReport = RDFValidationEngine.ValidateShape(shapesGraph, dataGraph, orShape, new List <RDFPatternMember>()
                    {
                        valueNode
                    });
                    if (orShapeReport.Conforms)
                    {
                        valueNodeConforms = true;
                        break;
                    }
                }

                if (!valueNodeConforms)
                {
                    report.AddResult(new RDFValidationResult(shape,
                                                             RDFVocabulary.SHACL.OR_CONSTRAINT_COMPONENT,
                                                             focusNode,
                                                             shape is RDFPropertyShape ? ((RDFPropertyShape)shape).Path : null,
                                                             valueNode,
                                                             shape.Messages,
                                                             shape.Severity));
                }
            }
            #endregion

            return(report);
        }
Esempio n. 16
0
        /// <summary>
        /// Evaluates this constraint against the given data graph
        /// </summary>
        internal override RDFValidationReport ValidateConstraint(RDFShapesGraph shapesGraph, RDFGraph dataGraph, RDFShape shape, RDFPatternMember focusNode, List <RDFPatternMember> valueNodes)
        {
            RDFValidationReport report = new RDFValidationReport();

            #region Evaluation
            foreach (RDFPatternMember valueNode in valueNodes)
            {
                if (!this.InValues.Any(v => v.Value.Equals(valueNode)))
                {
                    report.AddResult(new RDFValidationResult(shape,
                                                             RDFVocabulary.SHACL.IN_CONSTRAINT_COMPONENT,
                                                             focusNode,
                                                             shape is RDFPropertyShape ? ((RDFPropertyShape)shape).Path : null,
                                                             valueNode,
                                                             shape.Messages,
                                                             shape.Severity));
                }
            }
            #endregion

            return(report);
        }
Esempio n. 17
0
 /// <summary>
 /// Evaluates this constraint against the given data graph
 /// </summary>
 internal abstract RDFValidationReport ValidateConstraint(RDFShapesGraph shapesGraph,
                                                          RDFGraph dataGraph,
                                                          RDFShape shape,
                                                          RDFPatternMember focusNode,
                                                          List <RDFPatternMember> valueNodes);
        public void SelectDogs()
        {
            // CREATE SELECT QUERY
            RDFSelectQuery selectQuery = new RDFSelectQuery();

            selectQuery.AddPrefix(RDFNamespaceRegister.GetByPrefix("dc"));
            selectQuery.AddPrefix(RDFNamespaceRegister.GetByPrefix("foaf"));

            var x = new RDFVariable("x");
            var y = new RDFVariable("y");

            RDFPatternMember predicate = GraphBuilder2.dogOf;

            var x_dogOf_y = new RDFPattern(x, predicate, y);

            // CREATE PATTERN GROUP FROM A LIST OF PATTERNS
            var patterns = new List <RDFPattern>()
            {
                x_dogOf_y
            };
            var pg1 = new RDFPatternGroup("PG1", patterns);

            // ADD PATTERN GROUPS TO QUERY
            selectQuery.AddPatternGroup(pg1);

            selectQuery.AddProjectionVariable(x);
            selectQuery.AddProjectionVariable(y);

            // APPLY SELECT QUERY TO GRAPH

            var sparqlCommand = selectQuery.ToString();

            /*
             * Generates this sparql command
             *
             * PREFIX dc: <http://purl.org/dc/elements/1.1/>
             * PREFIX foaf: <http://xmlns.com/foaf/0.1/>
             *
             * SELECT ?X ?Y
             * WHERE {
             * {
             * ?X dc:dogOf ?Y .
             * }
             * }
             */

            RDFSelectQueryResult selectQueryResult = selectQuery.ApplyToGraph(graph);

            // EXPORT SELECT QUERY RESULTS TO SPARQL XML FORMAT (FILE)
            selectQueryResult.ToSparqlXmlResult(@"C:\TEMP\select_results.srq");

            Assert.Equal(1, selectQueryResult.SelectResultsCount);

            DataRow row    = selectQueryResult.SelectResults.Rows[0];
            var     dog    = row[0].ToString();
            var     person = row[1].ToString();

            Assert.Equal(pluto.URI.ToString(), dog);
            Assert.Equal(mickeyMouse.URI.ToString(), person);


            /*
             * Generates this file content
             *
             * <?xml version="1.0" encoding="utf-8"?>
             * <sparql xmlns="http://www.w3.org/2005/sparql-results#">
             * <head>
             * <variable name="?X" />
             * <variable name="?Y" />
             * </head>
             * <results>
             * <result>
             * <binding name="?X">
             * <uri>https://en.wikipedia.org/wiki/Pluto_(Disney)</uri>
             * </binding>
             * <binding name="?Y">
             * <uri>https://en.wikipedia.org/wiki/Mickey_Mouse</uri>
             * </binding>
             * </result>
             * </results>
             * </sparql>
             */
        }
Esempio n. 19
0
        /// <summary>
        /// Evaluates this constraint against the given data graph
        /// </summary>
        internal override RDFValidationReport ValidateConstraint(RDFShapesGraph shapesGraph, RDFGraph dataGraph, RDFShape shape, RDFPatternMember focusNode, List <RDFPatternMember> valueNodes)
        {
            RDFValidationReport report = new RDFValidationReport();

            #region Evaluation
            foreach (RDFPatternMember valueNode in valueNodes)
            {
                Int32 comparison = RDFQueryUtilities.CompareRDFPatternMembers(this.Value, valueNode);
                if (comparison == -99 || comparison > 0)
                {
                    report.AddResult(new RDFValidationResult(shape,
                                                             RDFVocabulary.SHACL.MIN_INCLUSIVE_CONSTRAINT_COMPONENT,
                                                             focusNode,
                                                             shape is RDFPropertyShape ? ((RDFPropertyShape)shape).Path : null,
                                                             valueNode,
                                                             shape.Messages,
                                                             shape.Severity));
                }
            }
            #endregion

            return(report);
        }
        /// <summary>
        /// Evaluates this constraint against the given data graph
        /// </summary>
        internal override RDFValidationReport ValidateConstraint(RDFShapesGraph shapesGraph, RDFGraph dataGraph, RDFShape shape, RDFPatternMember focusNode, List <RDFPatternMember> valueNodes)
        {
            RDFValidationReport report = new RDFValidationReport();

            #region Evaluation
            foreach (RDFPatternMember valueNode in valueNodes)
            {
                switch (valueNode)
                {
                //Resource
                case RDFResource valueNodeResource:
                    if (valueNodeResource.IsBlank ||
                        !this.RegEx.IsMatch(valueNodeResource.ToString()))
                    {
                        report.AddResult(new RDFValidationResult(shape,
                                                                 RDFVocabulary.SHACL.PATTERN_CONSTRAINT_COMPONENT,
                                                                 focusNode,
                                                                 shape is RDFPropertyShape ? ((RDFPropertyShape)shape).Path : null,
                                                                 valueNode,
                                                                 shape.Messages,
                                                                 shape.Severity));
                    }
                    break;

                //Literal
                case RDFLiteral valueNodeLiteral:
                    if (!this.RegEx.IsMatch(valueNodeLiteral.Value))
                    {
                        report.AddResult(new RDFValidationResult(shape,
                                                                 RDFVocabulary.SHACL.PATTERN_CONSTRAINT_COMPONENT,
                                                                 focusNode,
                                                                 shape is RDFPropertyShape ? ((RDFPropertyShape)shape).Path : null,
                                                                 valueNode,
                                                                 shape.Messages,
                                                                 shape.Severity));
                    }
                    break;
                }
            }
            #endregion

            return(report);
        }
Esempio n. 21
0
        /// <summary>
        /// Evaluates this constraint against the given data graph
        /// </summary>
        internal override RDFValidationReport ValidateConstraint(RDFShapesGraph shapesGraph, RDFGraph dataGraph, RDFShape shape, RDFPatternMember focusNode, List <RDFPatternMember> valueNodes)
        {
            RDFValidationReport report = new RDFValidationReport();

            #region Evaluation
            List <RDFPatternMember> predicateNodes = dataGraph.Where(t => t.Subject.Equals(focusNode) &&
                                                                     t.Predicate.Equals(this.LessThanOrEqualsPredicate))
                                                     .Select(x => x.Object)
                                                     .ToList();

            foreach (RDFPatternMember valueNode in valueNodes)
            {
                foreach (RDFPatternMember predicateNode in predicateNodes)
                {
                    Int32 comparison = RDFQueryUtilities.CompareRDFPatternMembers(valueNode, predicateNode);
                    if (comparison == -99 || comparison > 0)
                    {
                        report.AddResult(new RDFValidationResult(shape,
                                                                 RDFVocabulary.SHACL.LESS_THAN_OR_EQUALS_CONSTRAINT_COMPONENT,
                                                                 focusNode,
                                                                 shape is RDFPropertyShape ? ((RDFPropertyShape)shape).Path : null,
                                                                 valueNode,
                                                                 shape.Messages,
                                                                 shape.Severity));
                    }
                }
            }
            #endregion

            return(report);
        }
Esempio n. 22
0
        /// <summary>
        /// Evaluates this constraint against the given data graph
        /// </summary>
        internal override RDFValidationReport ValidateConstraint(RDFShapesGraph shapesGraph, RDFGraph dataGraph, RDFShape shape, RDFPatternMember focusNode, List <RDFPatternMember> valueNodes)
        {
            RDFValidationReport report = new RDFValidationReport(new RDFResource());

            #region Evaluation
            foreach (RDFPatternMember valueNode in valueNodes)
            {
                switch (valueNode)
                {
                //PlainLiteral
                case RDFPlainLiteral valueNodePlainLiteral:
                    bool langMatches        = false;
                    var  langTagsEnumerator = this.LanguageTags.GetEnumerator();
                    while (langTagsEnumerator.MoveNext() && !langMatches)
                    {
                        //NO language is found in the variable
                        if (langTagsEnumerator.Current == String.Empty)
                        {
                            langMatches = !Regex.IsMatch(valueNodePlainLiteral.ToString(), "@[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$", RegexOptions.IgnoreCase);
                        }

                        //ANY language is found in the variable
                        else if (langTagsEnumerator.Current == "*")
                        {
                            langMatches = Regex.IsMatch(valueNodePlainLiteral.ToString(), "@[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$", RegexOptions.IgnoreCase);
                        }

                        //GIVEN language is found in the variable
                        else
                        {
                            langMatches = Regex.IsMatch(valueNodePlainLiteral.ToString(), "@" + langTagsEnumerator.Current + "(-[a-zA-Z0-9]{1,8})*$", RegexOptions.IgnoreCase);
                        }
                    }
                    if (!langMatches)
                    {
                        report.AddResult(new RDFValidationResult(shape,
                                                                 RDFVocabulary.SHACL.LANGUAGE_IN_CONSTRAINT_COMPONENT,
                                                                 focusNode,
                                                                 shape is RDFPropertyShape ? ((RDFPropertyShape)shape).Path : null,
                                                                 valueNode,
                                                                 shape.Messages,
                                                                 shape.Severity));
                    }
                    break;

                //Resource/TypedLiteral
                default:
                    report.AddResult(new RDFValidationResult(shape,
                                                             RDFVocabulary.SHACL.LANGUAGE_IN_CONSTRAINT_COMPONENT,
                                                             focusNode,
                                                             shape is RDFPropertyShape ? ((RDFPropertyShape)shape).Path : null,
                                                             valueNode,
                                                             shape.Messages,
                                                             shape.Severity));
                    break;
                }
            }
            #endregion

            return(report);
        }
Esempio n. 23
0
        /// <summary>
        /// Evaluates this constraint against the given data graph
        /// </summary>
        internal override RDFValidationReport ValidateConstraint(RDFShapesGraph shapesGraph, RDFGraph dataGraph, RDFShape shape, RDFPatternMember focusNode, List <RDFPatternMember> valueNodes)
        {
            RDFValidationReport report = new RDFValidationReport();

            //Search for given qualified value shape
            RDFShape qualifiedValueShape = shapesGraph.SelectShape(this.QualifiedValueShapeUri.ToString());

            if (qualifiedValueShape == null)
            {
                return(report);
            }

            #region Evaluation
            if (this.QualifiedValueMinCount.HasValue || this.QualifiedValueMaxCount.HasValue)
            {
                int conformingValues = 0;
                foreach (RDFPatternMember valueNode in valueNodes)
                {
                    RDFValidationReport qualifiedValueShapeReport = RDFValidationEngine.ValidateShape(shapesGraph, dataGraph, qualifiedValueShape, new List <RDFPatternMember>()
                    {
                        valueNode
                    });
                    if (qualifiedValueShapeReport.Conforms)
                    {
                        conformingValues++;
                    }
                }

                if (this.QualifiedValueMinCount.HasValue && conformingValues < this.QualifiedValueMinCount)
                {
                    report.AddResult(new RDFValidationResult(shape,
                                                             RDFVocabulary.SHACL.QUALIFIED_MIN_COUNT_CONSTRAINT_COMPONENT,
                                                             focusNode,
                                                             shape is RDFPropertyShape ? ((RDFPropertyShape)shape).Path : null,
                                                             null,
                                                             shape.Messages,
                                                             shape.Severity));
                }

                if (this.QualifiedValueMaxCount.HasValue && conformingValues > this.QualifiedValueMaxCount)
                {
                    report.AddResult(new RDFValidationResult(shape,
                                                             RDFVocabulary.SHACL.QUALIFIED_MAX_COUNT_CONSTRAINT_COMPONENT,
                                                             focusNode,
                                                             shape is RDFPropertyShape ? ((RDFPropertyShape)shape).Path : null,
                                                             null,
                                                             shape.Messages,
                                                             shape.Severity));
                }
            }
            #endregion

            return(report);
        }
        /// <summary>
        /// Compares the given pattern members, throwing a "Type Error" whenever the comparison operator detects sematically incompatible members;
        /// </summary>
        public static Int32 CompareRDFPatternMembers(RDFPatternMember left, RDFPatternMember right) {

            #region CornerCase Comparisons
            if (left      == null) {
                if (right == null) {
                    return  0;
                }
                return -1;
            }
            if (right     == null) {
                return 1;
            }
            #endregion

            #region Effective  Comparisons

            #region RESOURCE/CONTEXT
            if (left is RDFResource      || left is RDFContext) {

                //RESOURCE/CONTEXT VS RESOURCE/CONTEXT
                if (right is RDFResource || right is RDFContext) {
                    return String.Compare(left.ToString(), right.ToString(), StringComparison.Ordinal);
                }

                //RESOURCE/CONTEXT VS "XSD:ANYURI" TYPED LITERAL
                if (right is RDFTypedLiteral && ((RDFTypedLiteral)right).Datatype.Equals(RDFDatatypeRegister.GetByPrefixAndDatatype(RDFVocabulary.XSD.PREFIX, "anyURI"))) {
                    return String.Compare(left.ToString(), ((RDFTypedLiteral)right).Value, StringComparison.Ordinal);
                }

                //RESOURCE/CONTEXT VS LITERAL
                return -1;

            }
            #endregion

            #region PLAINLITERAL
            if (left is RDFPlainLiteral) {

                //PLAIN LITERAL VS RESOURCE/CONTEXT
                if (right is RDFResource || right is RDFContext) {
                    return 1;
                }

                //PLAIN LITERAL VS PLAIN LITERAL
                if (right is RDFPlainLiteral) {
                    return String.Compare(left.ToString(), right.ToString(), StringComparison.Ordinal);
                }

                //PLAIN LITERAL VS "XSD:STRING" TYPED LITERAL
                if (((RDFTypedLiteral)right).Datatype.Equals(RDFDatatypeRegister.GetByPrefixAndDatatype(RDFVocabulary.XSD.PREFIX, "string"))) {
                    return String.Compare(left.ToString(), ((RDFTypedLiteral)right).Value, StringComparison.Ordinal);
                }

                //PLAIN LITERAL VS TYPED LITERAL
                return -1;

            }
            #endregion

            #region TYPEDLITERAL
            //TYPED LITERAL VS RESOURCE/CONTEXT
            if (right is RDFResource || right is RDFContext) {

                //"XSD:ANYURI" TYPED LITERAL VS RESOURCE/CONTEXT
                if (left is RDFTypedLiteral && ((RDFTypedLiteral)left).Datatype.Equals(RDFDatatypeRegister.GetByPrefixAndDatatype(RDFVocabulary.XSD.PREFIX, "anyURI"))) {
                    return String.Compare(((RDFTypedLiteral)left).Value, right.ToString(), StringComparison.Ordinal);
                }

                //TYPED LITERAL VS RESOURCE/CONTEXT
                return 1;

            }

            //TYPED LITERAL VS PLAIN LITERAL
            if (right is RDFPlainLiteral) {

                //"XSD:STRING" TYPED LITERAL VS PLAIN LITERAL
                if (((RDFTypedLiteral)left).Datatype.Equals(RDFDatatypeRegister.GetByPrefixAndDatatype(RDFVocabulary.XSD.PREFIX, "string"))) {
                    return String.Compare(((RDFTypedLiteral)left).Value, right.ToString(), StringComparison.Ordinal);
                }

                //TYPED LITERAL VS PLAIN LITERAL
                return 1;

            }

            //TYPED LITERAL VS TYPED LITERAL
            //SEMANTICALLY COMPATIBLE CATEGORY
            if (((RDFTypedLiteral)left).Datatype.Category.Equals(((RDFTypedLiteral)right).Datatype.Category)) {
                Int32 comparison = 0;
                switch (((RDFTypedLiteral)left).Datatype.Category) {

                    case RDFModelEnums.RDFDatatypeCategory.Numeric:
                        Decimal leftValueDecimal    = Decimal.Parse(((RDFTypedLiteral)left).Value,  NumberStyles.Number, CultureInfo.InvariantCulture);
                        Decimal rightValueDecimal   = Decimal.Parse(((RDFTypedLiteral)right).Value, NumberStyles.Number, CultureInfo.InvariantCulture);
                        comparison                  = leftValueDecimal.CompareTo(rightValueDecimal);
                        break;

                    case RDFModelEnums.RDFDatatypeCategory.Boolean:
                        Boolean leftValueBoolean    = Boolean.Parse(((RDFTypedLiteral)left).Value);
                        Boolean rightValueBoolean   = Boolean.Parse(((RDFTypedLiteral)right).Value);
                        comparison                  = leftValueBoolean.CompareTo(rightValueBoolean);
                        break;

                    case RDFModelEnums.RDFDatatypeCategory.DateTime:
                        DateTime leftValueDateTime;
                        DateTime rightValueDateTime;

                        //Detect exact type of left typed literal (dateTime, date, time, gYearMonth, gMonthDay, gYear, gMonth, gDay)
                        if (((RDFTypedLiteral)left).Datatype.Equals(RDFDatatypeRegister.GetByPrefixAndDatatype(RDFVocabulary.XSD.PREFIX, "dateTime"))) {
                            try {
                                leftValueDateTime  = DateTime.ParseExact(((RDFTypedLiteral)left).Value, "yyyy-MM-ddTHH:mm:ssK", CultureInfo.InvariantCulture);
                            }
                            catch {
                                leftValueDateTime  = DateTime.ParseExact(((RDFTypedLiteral)left).Value, "yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture);
                            }
                        }
                        else if (((RDFTypedLiteral)left).Datatype.Equals(RDFDatatypeRegister.GetByPrefixAndDatatype(RDFVocabulary.XSD.PREFIX, "date"))) {
                            try {
                                leftValueDateTime  = DateTime.ParseExact(((RDFTypedLiteral)left).Value, "yyyy-MM-ddK", CultureInfo.InvariantCulture);
                            }
                            catch {
                                leftValueDateTime  = DateTime.ParseExact(((RDFTypedLiteral)left).Value, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                            }
                        }
                        else if (((RDFTypedLiteral)left).Datatype.Equals(RDFDatatypeRegister.GetByPrefixAndDatatype(RDFVocabulary.XSD.PREFIX, "time"))) {
                            try {
                                leftValueDateTime  = DateTime.ParseExact(((RDFTypedLiteral)left).Value, "HH:mm:ssK", CultureInfo.InvariantCulture);
                            }
                            catch {
                                leftValueDateTime  = DateTime.ParseExact(((RDFTypedLiteral)left).Value, "HH:mm:ss", CultureInfo.InvariantCulture);
                            }
                        }
                        else if (((RDFTypedLiteral)left).Datatype.Equals(RDFDatatypeRegister.GetByPrefixAndDatatype(RDFVocabulary.XSD.PREFIX, "gYearMonth"))) {
                            try {
                                leftValueDateTime  = DateTime.ParseExact(((RDFTypedLiteral)left).Value, "yyyy-MMK", CultureInfo.InvariantCulture);
                            }
                            catch {
                                leftValueDateTime  = DateTime.ParseExact(((RDFTypedLiteral)left).Value, "yyyy-MM", CultureInfo.InvariantCulture);
                            }
                        }
                        else if (((RDFTypedLiteral)left).Datatype.Equals(RDFDatatypeRegister.GetByPrefixAndDatatype(RDFVocabulary.XSD.PREFIX, "gMonthDay"))) {
                            try {
                                leftValueDateTime  = DateTime.ParseExact(((RDFTypedLiteral)left).Value, "--MM-ddK", CultureInfo.InvariantCulture);
                            }
                            catch {
                                leftValueDateTime  = DateTime.ParseExact(((RDFTypedLiteral)left).Value, "--MM-dd", CultureInfo.InvariantCulture);
                            }
                        }
                        else if (((RDFTypedLiteral)left).Datatype.Equals(RDFDatatypeRegister.GetByPrefixAndDatatype(RDFVocabulary.XSD.PREFIX, "gYear"))) {
                            try {
                                leftValueDateTime  = DateTime.ParseExact(((RDFTypedLiteral)left).Value, "yyyyK", CultureInfo.InvariantCulture);
                            }
                            catch {
                                leftValueDateTime  = DateTime.ParseExact(((RDFTypedLiteral)left).Value, "yyyy", CultureInfo.InvariantCulture);
                            }
                        }
                        else if (((RDFTypedLiteral)left).Datatype.Equals(RDFDatatypeRegister.GetByPrefixAndDatatype(RDFVocabulary.XSD.PREFIX, "gMonth"))) {
                            try {
                                leftValueDateTime  = DateTime.ParseExact(((RDFTypedLiteral)left).Value, "MMK", CultureInfo.InvariantCulture);
                            }
                            catch {
                                leftValueDateTime  = DateTime.ParseExact(((RDFTypedLiteral)left).Value, "MM", CultureInfo.InvariantCulture);
                            }
                        }
                        else if (((RDFTypedLiteral)left).Datatype.Equals(RDFDatatypeRegister.GetByPrefixAndDatatype(RDFVocabulary.XSD.PREFIX, "gDay"))) {
                            try {
                                leftValueDateTime  = DateTime.ParseExact(((RDFTypedLiteral)left).Value, "ddK", CultureInfo.InvariantCulture);
                            }
                            catch {
                                leftValueDateTime  = DateTime.ParseExact(((RDFTypedLiteral)left).Value, "dd", CultureInfo.InvariantCulture);
                            }
                        }
                        else {
                            throw new RDFQueryException("Cannot parse typed literal of DateTime category because unknown format detected. Please, switch to one of XSD types: 'dateTime', 'date', 'time', 'gYearMonth', 'gMonthDay', 'gYear', 'gMonth', 'gDay'.");
                        }

                        //Detect exact type of right typed literal (dateTime, date, time, gYearMonth, gMonthDay, gYear, gMonth, gDay)
                        if (((RDFTypedLiteral)right).Datatype.Equals(RDFDatatypeRegister.GetByPrefixAndDatatype(RDFVocabulary.XSD.PREFIX, "dateTime"))) {
                            try {
                                rightValueDateTime = DateTime.ParseExact(((RDFTypedLiteral)right).Value, "yyyy-MM-ddTHH:mm:ssK", CultureInfo.InvariantCulture);
                            }
                            catch {
                                rightValueDateTime = DateTime.ParseExact(((RDFTypedLiteral)right).Value, "yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture);
                            }
                        }
                        else if (((RDFTypedLiteral)right).Datatype.Equals(RDFDatatypeRegister.GetByPrefixAndDatatype(RDFVocabulary.XSD.PREFIX, "date"))) {
                            try {
                                rightValueDateTime = DateTime.ParseExact(((RDFTypedLiteral)right).Value, "yyyy-MM-ddK", CultureInfo.InvariantCulture);
                            }
                            catch {
                                rightValueDateTime = DateTime.ParseExact(((RDFTypedLiteral)right).Value, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                            }
                        }
                        else if (((RDFTypedLiteral)right).Datatype.Equals(RDFDatatypeRegister.GetByPrefixAndDatatype(RDFVocabulary.XSD.PREFIX, "time"))) {
                            try {
                                rightValueDateTime = DateTime.ParseExact(((RDFTypedLiteral)right).Value, "HH:mm:ssK", CultureInfo.InvariantCulture);
                            }
                            catch {
                                rightValueDateTime = DateTime.ParseExact(((RDFTypedLiteral)right).Value, "HH:mm:ss", CultureInfo.InvariantCulture);
                            }
                        }
                        else if (((RDFTypedLiteral)right).Datatype.Equals(RDFDatatypeRegister.GetByPrefixAndDatatype(RDFVocabulary.XSD.PREFIX, "gYearMonth"))) {
                            try {
                                rightValueDateTime = DateTime.ParseExact(((RDFTypedLiteral)right).Value, "yyyy-MMK", CultureInfo.InvariantCulture);
                            }
                            catch {
                                rightValueDateTime = DateTime.ParseExact(((RDFTypedLiteral)right).Value, "yyyy-MM", CultureInfo.InvariantCulture);
                            }
                        }
                        else if (((RDFTypedLiteral)right).Datatype.Equals(RDFDatatypeRegister.GetByPrefixAndDatatype(RDFVocabulary.XSD.PREFIX, "gMonthDay"))) {
                            try {
                                rightValueDateTime = DateTime.ParseExact(((RDFTypedLiteral)right).Value, "--MM-ddK", CultureInfo.InvariantCulture);
                            }
                            catch {
                                rightValueDateTime = DateTime.ParseExact(((RDFTypedLiteral)right).Value, "--MM-dd", CultureInfo.InvariantCulture);
                            }
                        }
                        else if (((RDFTypedLiteral)right).Datatype.Equals(RDFDatatypeRegister.GetByPrefixAndDatatype(RDFVocabulary.XSD.PREFIX, "gYear"))) {
                            try {
                                rightValueDateTime = DateTime.ParseExact(((RDFTypedLiteral)right).Value, "yyyyK", CultureInfo.InvariantCulture);
                            }
                            catch {
                                rightValueDateTime = DateTime.ParseExact(((RDFTypedLiteral)right).Value, "yyyy", CultureInfo.InvariantCulture);
                            }
                        }
                        else if (((RDFTypedLiteral)right).Datatype.Equals(RDFDatatypeRegister.GetByPrefixAndDatatype(RDFVocabulary.XSD.PREFIX, "gMonth"))) {
                            try {
                                rightValueDateTime = DateTime.ParseExact(((RDFTypedLiteral)right).Value, "MMK", CultureInfo.InvariantCulture);
                            }
                            catch {
                                rightValueDateTime = DateTime.ParseExact(((RDFTypedLiteral)right).Value, "MM", CultureInfo.InvariantCulture);
                            }
                        }
                        else if (((RDFTypedLiteral)right).Datatype.Equals(RDFDatatypeRegister.GetByPrefixAndDatatype(RDFVocabulary.XSD.PREFIX, "gDay"))) {
                            try {
                                rightValueDateTime = DateTime.ParseExact(((RDFTypedLiteral)right).Value, "ddK", CultureInfo.InvariantCulture);
                            }
                            catch {
                                rightValueDateTime = DateTime.ParseExact(((RDFTypedLiteral)right).Value, "dd", CultureInfo.InvariantCulture);
                            }
                        }
                        else {
                            throw new RDFQueryException("Cannot parse typed literal of DateTime category because unknown format detected. Please, switch to one of XSD types: 'dateTime', 'date', 'time', 'gYearMonth', 'gMonthDay', 'gYear', 'gMonth', 'gDay'.");
                        }

                        comparison                  = leftValueDateTime.CompareTo(rightValueDateTime);
                        break;

                    case RDFModelEnums.RDFDatatypeCategory.TimeSpan:
                        TimeSpan leftValueDuration  = XmlConvert.ToTimeSpan(((RDFTypedLiteral)left).Value);
                        TimeSpan rightValueDuration = XmlConvert.ToTimeSpan(((RDFTypedLiteral)right).Value);
                        comparison                  = leftValueDuration.CompareTo(rightValueDuration);
                        break;

                    case RDFModelEnums.RDFDatatypeCategory.String:
                        String leftValueString      = ((RDFTypedLiteral)left).Value;
                        String rightValueString     = ((RDFTypedLiteral)right).Value;
                        comparison                  = String.Compare(leftValueString, rightValueString, StringComparison.Ordinal);
                        break;

                }
                return comparison;
            }

            //SEMANTICALLY NOT COMPATIBLE CATEGORY
            throw new RDFQueryException("Type Error: Typed Literal cannot be compared to Typed Literal with different category.");

            #endregion

            #endregion

        }
Esempio n. 25
0
        /// <summary>
        /// Evaluates this constraint against the given data graph
        /// </summary>
        internal override RDFValidationReport ValidateConstraint(RDFShapesGraph shapesGraph, RDFGraph dataGraph, RDFShape shape, RDFPatternMember focusNode, List <RDFPatternMember> valueNodes)
        {
            RDFValidationReport report = new RDFValidationReport();

            #region Evaluation
            if (this.UniqueLang)
            {
                HashSet <string>       reportedLangs     = new HashSet <string>();
                List <RDFPlainLiteral> langlitValueNodes = valueNodes.OfType <RDFPlainLiteral>()
                                                           .Where(vn => !string.IsNullOrEmpty(vn.Language))
                                                           .ToList();

                foreach (RDFPlainLiteral innerlanglitValueNode in langlitValueNodes)
                {
                    foreach (RDFPlainLiteral outerlanglitValueNode in langlitValueNodes)
                    {
                        if (!innerlanglitValueNode.Equals(outerlanglitValueNode) &&
                            innerlanglitValueNode.Language.Equals(outerlanglitValueNode.Language))
                        {
                            //Ensure to not report twice the same language tag
                            if (!reportedLangs.Contains(innerlanglitValueNode.Language))
                            {
                                reportedLangs.Add(innerlanglitValueNode.Language);
                                report.AddResult(new RDFValidationResult(shape,
                                                                         RDFVocabulary.SHACL.UNIQUE_LANG_CONSTRAINT_COMPONENT,
                                                                         focusNode,
                                                                         shape is RDFPropertyShape ? ((RDFPropertyShape)shape).Path : null,
                                                                         null,
                                                                         shape.Messages,
                                                                         shape.Severity));
                            }
                        }
                    }
                }
            }
            #endregion

            return(report);
        }
Esempio n. 26
0
        /// <summary>
        /// Compares the given pattern members, throwing a "Type Error" whenever the comparison operator detects sematically incompatible members;
        /// </summary>
        internal static Int32 CompareRDFPatternMembers(RDFPatternMember left, RDFPatternMember right)
        {
            #region NULLS
            if (left      == null) {
                if (right == null) {
                    return  0;
                }
                return -1;
            }
            if (right     == null) {
                return 1;
            }
            #endregion

            #region RESOURCE/CONTEXT
            if (left      is RDFResource || left is RDFContext) {

                //RESOURCE/CONTEXT VS RESOURCE/CONTEXT/PLAINLITERAL
                if (right is RDFResource || right is RDFContext || right is RDFPlainLiteral) {
                    return String.Compare(left.ToString(), right.ToString(), StringComparison.Ordinal);
                }

                //RESOURCE/CONTEXT VS TYPEDLITERAL
                else {
                    if (((RDFTypedLiteral)right).HasStringDatatype()) {
                        return String.Compare(left.ToString(), ((RDFTypedLiteral)right).Value, StringComparison.Ordinal);
                    }
                    return -99; //Type Error
                }

            }
            #endregion

            #region PLAINLITERAL
            else if (left is RDFPlainLiteral) {

                //PLAINLITERAL VS RESOURCE/CONTEXT/PLAINLITERAL
                if (right is RDFResource || right is RDFContext || right is RDFPlainLiteral) {
                    return String.Compare(left.ToString(), right.ToString(), StringComparison.Ordinal);
                }

                //PLAINLITERAL VS TYPEDLITERAL
                else {
                    if (((RDFTypedLiteral)right).HasStringDatatype()) {
                        return String.Compare(left.ToString(), ((RDFTypedLiteral)right).Value, StringComparison.Ordinal);
                    }
                    return -99; //Type Error
                }

            }
            #endregion

            #region TYPEDLITERAL
               else {

                //TYPEDLITERAL VS RESOURCE/CONTEXT/PLAINLITERAL
                if (right is RDFResource || right is RDFContext || right is RDFPlainLiteral) {
                    if (((RDFTypedLiteral)left).HasStringDatatype()) {
                        return String.Compare(((RDFTypedLiteral)left).Value, right.ToString(), StringComparison.Ordinal);
                    }
                    return -99; //Type Error
                }

                //TYPEDLITERAL VS TYPEDLITERAL
                else {
                    if (((RDFTypedLiteral)left).HasBooleanDatatype()       && ((RDFTypedLiteral)right).HasBooleanDatatype()) {
                        Boolean leftValueBoolean    = Boolean.Parse(((RDFTypedLiteral)left).Value);
                        Boolean rightValueBoolean   = Boolean.Parse(((RDFTypedLiteral)right).Value);
                        return leftValueBoolean.CompareTo(rightValueBoolean);
                    }
                    else if (((RDFTypedLiteral)left).HasDatetimeDatatype() && ((RDFTypedLiteral)right).HasDatetimeDatatype()) {
                        DateTime leftValueDateTime  = DateTime.Parse(((RDFTypedLiteral)left).Value,  CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
                        DateTime rightValueDateTime = DateTime.Parse(((RDFTypedLiteral)right).Value, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
                        return leftValueDateTime.CompareTo(rightValueDateTime);
                    }
                    else if (((RDFTypedLiteral)left).HasDecimalDatatype()  && ((RDFTypedLiteral)right).HasDecimalDatatype()) {
                        Decimal leftValueDecimal    = Decimal.Parse(((RDFTypedLiteral)left).Value,  CultureInfo.InvariantCulture);
                        Decimal rightValueDecimal   = Decimal.Parse(((RDFTypedLiteral)right).Value, CultureInfo.InvariantCulture);
                        return leftValueDecimal.CompareTo(rightValueDecimal);
                    }
                    else if (((RDFTypedLiteral)left).HasStringDatatype()   && ((RDFTypedLiteral)right).HasStringDatatype()) {
                        String leftValueString      = ((RDFTypedLiteral)left).Value;
                        String rightValueString     = ((RDFTypedLiteral)right).Value;
                        return leftValueString.CompareTo(rightValueString);
                    }
                    else if (((RDFTypedLiteral)left).HasTimespanDatatype() && ((RDFTypedLiteral)right).HasTimespanDatatype()) {
                        TimeSpan leftValueDuration  = XmlConvert.ToTimeSpan(((RDFTypedLiteral)left).Value);
                        TimeSpan rightValueDuration = XmlConvert.ToTimeSpan(((RDFTypedLiteral)right).Value);
                        return leftValueDuration.CompareTo(rightValueDuration);
                    }
                    else {
                        return -99; //Type Error
                    }
                }

            }
            #endregion
        }
Esempio n. 27
0
        private static void ParseShapeConstraints(DataRow shapesRow, RDFGraph graph, RDFShape shape)
        {
            //sh:and
            if (!shapesRow.IsNull("?AND"))
            {
                RDFPatternMember reifSubj = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?AND"));
                if (reifSubj is RDFResource)
                {
                    RDFAndConstraint andConstraint = new RDFAndConstraint();
                    RDFCollection    andColl       = RDFModelUtilities.DeserializeCollectionFromGraph(graph, (RDFResource)reifSubj, RDFModelEnums.RDFTripleFlavors.SPO);
                    andColl.Items.ForEach(item => {
                        andConstraint.AddShape((RDFResource)item);
                    });
                    shape.AddConstraint(andConstraint);
                }
            }

            //sh:class
            if (!shapesRow.IsNull("?CLASS"))
            {
                RDFPatternMember cls = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?CLASS"));
                if (cls is RDFResource)
                {
                    shape.AddConstraint(new RDFClassConstraint((RDFResource)cls));
                }
            }

            //sh:closed
            if (!shapesRow.IsNull("?CLOSED"))
            {
                RDFPatternMember closed = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?CLOSED"));
                if (closed is RDFTypedLiteral &&
                    ((RDFTypedLiteral)closed).HasBooleanDatatype())
                {
                    RDFClosedConstraint closedConstraint = new RDFClosedConstraint(Boolean.Parse(((RDFTypedLiteral)closed).Value));

                    //sh:ignoredProperties
                    RDFPatternMember reifSubj = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?IGNOREDPROPERTIES"));
                    if (reifSubj is RDFResource)
                    {
                        RDFCollection ignoredPropsColl = RDFModelUtilities.DeserializeCollectionFromGraph(graph, (RDFResource)reifSubj, RDFModelEnums.RDFTripleFlavors.SPO);
                        ignoredPropsColl.Items.ForEach(item => {
                            closedConstraint.AddIgnoredProperty((RDFResource)item);
                        });
                    }

                    shape.AddConstraint(closedConstraint);
                }
            }

            //sh:datatype
            if (!shapesRow.IsNull("?DATATYPE"))
            {
                RDFPatternMember datatype = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?DATATYPE"));
                if (datatype is RDFResource)
                {
                    shape.AddConstraint(new RDFDatatypeConstraint(RDFModelUtilities.GetDatatypeFromString(datatype.ToString())));
                }
            }

            //sh:disjoint
            if (!shapesRow.IsNull("?DISJOINT"))
            {
                RDFPatternMember disjpred = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?DISJOINT"));
                if (disjpred is RDFResource)
                {
                    shape.AddConstraint(new RDFDisjointConstraint((RDFResource)disjpred));
                }
            }

            //sh:equals
            if (!shapesRow.IsNull("?EQUALS"))
            {
                RDFPatternMember eqpred = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?EQUALS"));
                if (eqpred is RDFResource)
                {
                    shape.AddConstraint(new RDFEqualsConstraint((RDFResource)eqpred));
                }
            }

            //sh:hasValue
            if (!shapesRow.IsNull("?HASVALUE"))
            {
                RDFPatternMember value = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?HASVALUE"));
                if (value is RDFResource)
                {
                    shape.AddConstraint(new RDFHasValueConstraint((RDFResource)value));
                }
                else if (value is RDFLiteral)
                {
                    shape.AddConstraint(new RDFHasValueConstraint((RDFLiteral)value));
                }
            }

            //sh:in
            if (!shapesRow.IsNull("?IN"))
            {
                RDFPatternMember reifSubj = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?IN"));
                if (reifSubj is RDFResource)
                {
                    RDFModelEnums.RDFTripleFlavors inCollFlavor = RDFModelUtilities.DetectCollectionFlavorFromGraph(graph, (RDFResource)reifSubj);
                    RDFCollection   inColl       = RDFModelUtilities.DeserializeCollectionFromGraph(graph, (RDFResource)reifSubj, inCollFlavor);
                    RDFInConstraint inConstraint = new RDFInConstraint(inColl.ItemType);
                    inColl.Items.ForEach(item => {
                        if (inColl.ItemType == RDFModelEnums.RDFItemTypes.Literal)
                        {
                            inConstraint.AddValue((RDFLiteral)item);
                        }
                        else
                        {
                            inConstraint.AddValue((RDFResource)item);
                        }
                    });
                    shape.AddConstraint(inConstraint);
                }
            }

            //sh:languageIn
            if (!shapesRow.IsNull("?LANGUAGEIN"))
            {
                RDFPatternMember reifSubj = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?LANGUAGEIN"));
                if (reifSubj is RDFResource)
                {
                    RDFCollection langTagsColl = RDFModelUtilities.DeserializeCollectionFromGraph(graph, (RDFResource)reifSubj, RDFModelEnums.RDFTripleFlavors.SPL);
                    shape.AddConstraint(new RDFLanguageInConstraint(langTagsColl.Select(x => x.ToString()).ToList()));
                }
            }

            //sh:lessThan
            if (!shapesRow.IsNull("?LESSTHAN"))
            {
                RDFPatternMember ltpred = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?LESSTHAN"));
                if (ltpred is RDFResource)
                {
                    shape.AddConstraint(new RDFLessThanConstraint((RDFResource)ltpred));
                }
            }

            //sh:lessThanOrEquals
            if (!shapesRow.IsNull("?LESSTHANOREQUALS"))
            {
                RDFPatternMember lteqpred = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?LESSTHANOREQUALS"));
                if (lteqpred is RDFResource)
                {
                    shape.AddConstraint(new RDFLessThanOrEqualsConstraint((RDFResource)lteqpred));
                }
            }

            //sh:maxCount
            if (!shapesRow.IsNull("?MAXCOUNT"))
            {
                RDFPatternMember maxCount = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?MAXCOUNT"));
                if (maxCount is RDFTypedLiteral && ((RDFTypedLiteral)maxCount).Datatype.Equals(RDFModelEnums.RDFDatatypes.XSD_INTEGER))
                {
                    shape.AddConstraint(new RDFMaxCountConstraint(int.Parse(((RDFTypedLiteral)maxCount).Value)));
                }
            }

            //sh:maxExclusive
            if (!shapesRow.IsNull("?MAXEXCLUSIVE"))
            {
                RDFPatternMember value = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?MAXEXCLUSIVE"));
                if (value is RDFResource)
                {
                    shape.AddConstraint(new RDFMaxExclusiveConstraint((RDFResource)value));
                }
                else if (value is RDFLiteral)
                {
                    shape.AddConstraint(new RDFMaxExclusiveConstraint((RDFLiteral)value));
                }
            }

            //sh:maxInclusive
            if (!shapesRow.IsNull("?MAXINCLUSIVE"))
            {
                RDFPatternMember value = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?MAXINCLUSIVE"));
                if (value is RDFResource)
                {
                    shape.AddConstraint(new RDFMaxInclusiveConstraint((RDFResource)value));
                }
                else if (value is RDFLiteral)
                {
                    shape.AddConstraint(new RDFMaxInclusiveConstraint((RDFLiteral)value));
                }
            }

            //sh:maxLength
            if (!shapesRow.IsNull("?MAXLENGTH"))
            {
                RDFPatternMember maxLength = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?MAXLENGTH"));
                if (maxLength is RDFTypedLiteral && ((RDFTypedLiteral)maxLength).Datatype.Equals(RDFModelEnums.RDFDatatypes.XSD_INTEGER))
                {
                    shape.AddConstraint(new RDFMaxLengthConstraint(int.Parse(((RDFTypedLiteral)maxLength).Value)));
                }
            }

            //sh:minCount
            if (!shapesRow.IsNull("?MINCOUNT"))
            {
                RDFPatternMember minCount = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?MINCOUNT"));
                if (minCount is RDFTypedLiteral && ((RDFTypedLiteral)minCount).Datatype.Equals(RDFModelEnums.RDFDatatypes.XSD_INTEGER))
                {
                    shape.AddConstraint(new RDFMinCountConstraint(int.Parse(((RDFTypedLiteral)minCount).Value)));
                }
            }

            //sh:minExclusive
            if (!shapesRow.IsNull("?MINEXCLUSIVE"))
            {
                RDFPatternMember value = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?MINEXCLUSIVE"));
                if (value is RDFResource)
                {
                    shape.AddConstraint(new RDFMinExclusiveConstraint((RDFResource)value));
                }
                else if (value is RDFLiteral)
                {
                    shape.AddConstraint(new RDFMinExclusiveConstraint((RDFLiteral)value));
                }
            }

            //sh:minInclusive
            if (!shapesRow.IsNull("?MININCLUSIVE"))
            {
                RDFPatternMember value = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?MININCLUSIVE"));
                if (value is RDFResource)
                {
                    shape.AddConstraint(new RDFMinInclusiveConstraint((RDFResource)value));
                }
                else if (value is RDFLiteral)
                {
                    shape.AddConstraint(new RDFMinInclusiveConstraint((RDFLiteral)value));
                }
            }

            //sh:minLength
            if (!shapesRow.IsNull("?MINLENGTH"))
            {
                RDFPatternMember minLength = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?MINLENGTH"));
                if (minLength is RDFTypedLiteral && ((RDFTypedLiteral)minLength).Datatype.Equals(RDFModelEnums.RDFDatatypes.XSD_INTEGER))
                {
                    shape.AddConstraint(new RDFMinLengthConstraint(int.Parse(((RDFTypedLiteral)minLength).Value)));
                }
            }

            //sh:node
            if (!shapesRow.IsNull("?NODE"))
            {
                RDFPatternMember nodeshapeUri = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?NODE"));
                if (nodeshapeUri is RDFResource)
                {
                    shape.AddConstraint(new RDFNodeConstraint((RDFResource)nodeshapeUri));
                }
            }

            //sh:nodeKind
            if (!shapesRow.IsNull("?NODEKIND"))
            {
                RDFPatternMember nodeKind = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?NODEKIND"));
                if (nodeKind is RDFResource)
                {
                    if (nodeKind.Equals(RDFVocabulary.SHACL.BLANK_NODE))
                    {
                        shape.AddConstraint(new RDFNodeKindConstraint(RDFValidationEnums.RDFNodeKinds.BlankNode));
                    }
                    else if (nodeKind.Equals(RDFVocabulary.SHACL.BLANK_NODE_OR_IRI))
                    {
                        shape.AddConstraint(new RDFNodeKindConstraint(RDFValidationEnums.RDFNodeKinds.BlankNodeOrIRI));
                    }
                    else if (nodeKind.Equals(RDFVocabulary.SHACL.BLANK_NODE_OR_LITERAL))
                    {
                        shape.AddConstraint(new RDFNodeKindConstraint(RDFValidationEnums.RDFNodeKinds.BlankNodeOrLiteral));
                    }
                    else if (nodeKind.Equals(RDFVocabulary.SHACL.IRI))
                    {
                        shape.AddConstraint(new RDFNodeKindConstraint(RDFValidationEnums.RDFNodeKinds.IRI));
                    }
                    else if (nodeKind.Equals(RDFVocabulary.SHACL.IRI_OR_LITERAL))
                    {
                        shape.AddConstraint(new RDFNodeKindConstraint(RDFValidationEnums.RDFNodeKinds.IRIOrLiteral));
                    }
                    else if (nodeKind.Equals(RDFVocabulary.SHACL.LITERAL))
                    {
                        shape.AddConstraint(new RDFNodeKindConstraint(RDFValidationEnums.RDFNodeKinds.Literal));
                    }
                }
            }

            //sh:not
            if (!shapesRow.IsNull("?NOT"))
            {
                RDFPatternMember notshapeUri = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?NOT"));
                if (notshapeUri is RDFResource)
                {
                    shape.AddConstraint(new RDFNotConstraint((RDFResource)notshapeUri));
                }
            }

            //sh:or
            if (!shapesRow.IsNull("?OR"))
            {
                RDFPatternMember reifSubj = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?OR"));
                if (reifSubj is RDFResource)
                {
                    RDFOrConstraint orConstraint = new RDFOrConstraint();
                    RDFCollection   orColl       = RDFModelUtilities.DeserializeCollectionFromGraph(graph, (RDFResource)reifSubj, RDFModelEnums.RDFTripleFlavors.SPO);
                    orColl.Items.ForEach(item => {
                        orConstraint.AddShape((RDFResource)item);
                    });
                    shape.AddConstraint(orConstraint);
                }
            }

            //sh:pattern
            if (!shapesRow.IsNull("?PATTERN"))
            {
                RDFPatternMember regexPattern = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?PATTERN"));
                if (regexPattern is RDFTypedLiteral && ((RDFTypedLiteral)regexPattern).Datatype.Equals(RDFModelEnums.RDFDatatypes.XSD_STRING))
                {
                    //sh:flags
                    RegexOptions regexOptions = RegexOptions.None;
                    if (!shapesRow.IsNull("?FLAGS"))
                    {
                        RDFPatternMember regexFlags = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?FLAGS"));
                        if (regexFlags is RDFTypedLiteral && ((RDFTypedLiteral)regexFlags).Datatype.Equals(RDFModelEnums.RDFDatatypes.XSD_STRING))
                        {
                            if (((RDFTypedLiteral)regexFlags).Value.Contains("i"))
                            {
                                regexOptions |= RegexOptions.IgnoreCase;
                            }
                            if (((RDFTypedLiteral)regexFlags).Value.Contains("s"))
                            {
                                regexOptions |= RegexOptions.Singleline;
                            }
                            if (((RDFTypedLiteral)regexFlags).Value.Contains("m"))
                            {
                                regexOptions |= RegexOptions.Multiline;
                            }
                            if (((RDFTypedLiteral)regexFlags).Value.Contains("x"))
                            {
                                regexOptions |= RegexOptions.IgnorePatternWhitespace;
                            }
                        }
                    }
                    shape.AddConstraint(new RDFPatternConstraint(new Regex(((RDFTypedLiteral)regexPattern).Value, regexOptions)));
                }
            }

            //sh:property
            if (!shapesRow.IsNull("?PROPERTY"))
            {
                RDFPatternMember propertyshapeUri = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?PROPERTY"));
                if (propertyshapeUri is RDFResource)
                {
                    shape.AddConstraint(new RDFPropertyConstraint((RDFResource)propertyshapeUri));
                }
            }

            //sh:qualifiedValueShape
            if (!shapesRow.IsNull("?QUALIFIEDVALUESHAPE"))
            {
                RDFPatternMember qualifiedValueShapeUri = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?QUALIFIEDVALUESHAPE"));
                if (qualifiedValueShapeUri is RDFResource)
                {
                    //sh:qualifiedMinCount
                    int?qualifiedMinCountValue = null;
                    if (!shapesRow.IsNull("?QUALIFIEDMINCOUNT"))
                    {
                        RDFPatternMember qualifiedMinCount = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?QUALIFIEDMINCOUNT"));
                        if (qualifiedMinCount is RDFTypedLiteral && ((RDFTypedLiteral)qualifiedMinCount).Datatype.Equals(RDFModelEnums.RDFDatatypes.XSD_INTEGER))
                        {
                            qualifiedMinCountValue = int.Parse(((RDFTypedLiteral)qualifiedMinCount).Value);
                        }
                    }
                    //sh:qualifiedMaxCount
                    int?qualifiedMaxCountValue = null;
                    if (!shapesRow.IsNull("?QUALIFIEDMAXCOUNT"))
                    {
                        RDFPatternMember qualifiedMaxCount = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?QUALIFIEDMAXCOUNT"));
                        if (qualifiedMaxCount is RDFTypedLiteral && ((RDFTypedLiteral)qualifiedMaxCount).Datatype.Equals(RDFModelEnums.RDFDatatypes.XSD_INTEGER))
                        {
                            qualifiedMaxCountValue = int.Parse(((RDFTypedLiteral)qualifiedMaxCount).Value);
                        }
                    }
                    shape.AddConstraint(new RDFQualifiedValueShapeConstraint((RDFResource)qualifiedValueShapeUri, qualifiedMinCountValue, qualifiedMaxCountValue));
                }
            }

            //sh:uniqueLang
            if (!shapesRow.IsNull("?UNIQUELANG"))
            {
                RDFPatternMember uniqueLang = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?UNIQUELANG"));
                if (uniqueLang is RDFTypedLiteral &&
                    ((RDFTypedLiteral)uniqueLang).HasBooleanDatatype())
                {
                    shape.AddConstraint(new RDFUniqueLangConstraint(Boolean.Parse(((RDFTypedLiteral)uniqueLang).Value)));
                }
            }

            //sh:xone
            if (!shapesRow.IsNull("?XONE"))
            {
                RDFPatternMember reifSubj = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?XONE"));
                if (reifSubj is RDFResource)
                {
                    RDFXoneConstraint xoneConstraint = new RDFXoneConstraint();
                    RDFCollection     xoneColl       = RDFModelUtilities.DeserializeCollectionFromGraph(graph, (RDFResource)reifSubj, RDFModelEnums.RDFTripleFlavors.SPO);
                    xoneColl.Items.ForEach(item => {
                        xoneConstraint.AddShape((RDFResource)item);
                    });
                    shape.AddConstraint(xoneConstraint);
                }
            }
        }