/// <summary>
        /// Detects the attributes of the given shape
        /// </summary>
        private static void DetectShapeAttributes(RDFGraph graph, RDFShape shape)
        {
            RDFGraph shapeDefinition = graph.SelectTriplesBySubject(shape);

            //sh:severity (accepted occurrences: 1)
            RDFTriple shapeSeverity = shapeDefinition.SelectTriplesByPredicate(RDFVocabulary.SHACL.SEVERITY_PROPERTY).FirstOrDefault();

            if (shapeSeverity != null)
            {
                if (shapeSeverity.Object.Equals(RDFVocabulary.SHACL.INFO))
                {
                    shape.SetSeverity(RDFValidationEnums.RDFShapeSeverity.Info);
                }
                else if (shapeSeverity.Object.Equals(RDFVocabulary.SHACL.WARNING))
                {
                    shape.SetSeverity(RDFValidationEnums.RDFShapeSeverity.Warning);
                }
            }

            //sh:deactivated (accepted occurrences: 1)
            RDFTriple shapeDeactivated = shapeDefinition.SelectTriplesByPredicate(RDFVocabulary.SHACL.DEACTIVATED).FirstOrDefault();

            if (shapeDeactivated != null)
            {
                if (shapeDeactivated.Object is RDFTypedLiteral shapeDeactivatedLiteral &&
                    shapeDeactivatedLiteral.HasBooleanDatatype() && bool.Parse(shapeDeactivatedLiteral.Value))
                {
                    shape.Deactivate();
                }
            }

            //sh:message (accepted occurrences: N)
            RDFGraph shapeMessages = shapeDefinition.SelectTriplesByPredicate(RDFVocabulary.SHACL.MESSAGE);

            foreach (RDFTriple shapeMessage in shapeMessages.Where(t => t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPL))
            {
                shape.AddMessage((RDFLiteral)shapeMessage.Object);
            }
        }
Example #2
0
        private static void ParseShapeAttributes(DataRow shapesRow, RDFShape shape)
        {
            //sh:severity
            if (!shapesRow.IsNull("?SEVERITY"))
            {
                if (shapesRow.Field <string>("?SEVERITY").Equals(RDFVocabulary.SHACL.INFO.ToString()))
                {
                    shape.SetSeverity(RDFValidationEnums.RDFShapeSeverity.Info);
                }
                else if (shapesRow.Field <string>("?SEVERITY").Equals(RDFVocabulary.SHACL.WARNING.ToString()))
                {
                    shape.SetSeverity(RDFValidationEnums.RDFShapeSeverity.Warning);
                }
            }

            //sh:deactivated
            if (!shapesRow.IsNull("?DEACTIVATED"))
            {
                RDFPatternMember deactivated = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?DEACTIVATED"));
                if (deactivated is RDFTypedLiteral &&
                    ((RDFTypedLiteral)deactivated).HasBooleanDatatype() &&
                    Boolean.Parse(((RDFTypedLiteral)deactivated).Value))
                {
                    shape.Deactivate();
                }
            }

            //sh:message
            if (!shapesRow.IsNull("?MESSAGE"))
            {
                RDFPatternMember message = RDFQueryUtilities.ParseRDFPatternMember(shapesRow.Field <string>("?MESSAGE"));
                if (message is RDFLiteral)
                {
                    shape.AddMessage((RDFLiteral)message);
                }
            }
        }