/// <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 node shape
            RDFNodeShape nodeShape = shapesGraph.SelectShape(this.NodeShapeUri.ToString()) as RDFNodeShape;

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

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

            return(report);
        }
Exemple #2
0
        private static RDFShape ParseShapeType(DataRow shapesRow)
        {
            RDFShape shape = null;

            //sh:NodeShape
            if (!shapesRow.IsNull("?NSHAPE"))
            {
                shape = new RDFNodeShape(new RDFResource(shapesRow.Field <string>("?NSHAPE")));
            }

            //sh:PropertyShape
            else if (!shapesRow.IsNull("?PSHAPE") && !shapesRow.IsNull("?PATH"))
            {
                shape = new RDFPropertyShape(new RDFResource(shapesRow.Field <string>("?PSHAPE")), new RDFResource(shapesRow.Field <string>("?PATH")));

                //sh:description
                if (!shapesRow.IsNull("?DESCRIPTION"))
                {
                    RDFPatternMember description = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?DESCRIPTION"));
                    if (description is RDFLiteral)
                    {
                        ((RDFPropertyShape)shape).AddDescription((RDFLiteral)description);
                    }
                }

                //sh:name
                if (!shapesRow.IsNull("?NAME"))
                {
                    RDFPatternMember name = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?NAME"));
                    if (name is RDFLiteral)
                    {
                        ((RDFPropertyShape)shape).AddName((RDFLiteral)name);
                    }
                }

                //sh:group
                if (!shapesRow.IsNull("?GROUP"))
                {
                    RDFPatternMember group = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?GROUP"));
                    if (group is RDFResource)
                    {
                        ((RDFPropertyShape)shape).SetGroup((RDFResource)group);
                    }
                }

                //sh:order
                if (!shapesRow.IsNull("?ORDER"))
                {
                    RDFPatternMember order = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?ORDER"));
                    if (order is RDFTypedLiteral && ((RDFTypedLiteral)order).Datatype.Equals(RDFModelEnums.RDFDatatypes.XSD_INTEGER))
                    {
                        ((RDFPropertyShape)shape).SetOrder(int.Parse(((RDFTypedLiteral)order).Value));
                    }
                }
            }

            return(shape);
        }
        /// <summary>
        /// Detects the typed instances of shacl:NodeShape and populates the shapes graph with their definition
        /// </summary>
        private static void DetectTypedNodeShapes(RDFGraph graph, RDFShapesGraph shapesGraph)
        {
            RDFGraph declaredNodeShapes = graph.SelectTriplesByPredicate(RDFVocabulary.RDF.TYPE)
                                          .SelectTriplesByObject(RDFVocabulary.SHACL.NODE_SHAPE);

            foreach (RDFTriple declaredNodeShape in declaredNodeShapes)
            {
                RDFNodeShape nodeShape = new RDFNodeShape((RDFResource)declaredNodeShape.Subject);

                DetectShapeTargets(graph, nodeShape);
                DetectShapeAttributes(graph, nodeShape);
                DetectShapeConstraints(graph, nodeShape);

                shapesGraph.AddShape(nodeShape);
            }
        }