Beispiel #1
0
        private static void ParseShapeTargets(DataRow shapesRow, RDFShape shape)
        {
            //sh:targetClass
            if (!shapesRow.IsNull("?TARGETCLASS"))
            {
                shape.AddTarget(new RDFTargetClass(new RDFResource(shapesRow.Field <string>("?TARGETCLASS"))));
            }

            //sh:targetNode
            if (!shapesRow.IsNull("?TARGETNODE"))
            {
                shape.AddTarget(new RDFTargetNode(new RDFResource(shapesRow.Field <string>("?TARGETNODE"))));
            }

            //sh:targetSubjectsOf
            if (!shapesRow.IsNull("?TARGETSUBJECTSOF"))
            {
                shape.AddTarget(new RDFTargetSubjectsOf(new RDFResource(shapesRow.Field <string>("?TARGETSUBJECTSOF"))));
            }

            //sh:targetObjectsOf
            if (!shapesRow.IsNull("?TARGETOBJECTSOF"))
            {
                shape.AddTarget(new RDFTargetObjectsOf(new RDFResource(shapesRow.Field <string>("?TARGETOBJECTSOF"))));
            }
        }
        /// <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);
        }
Beispiel #3
0
        internal static RDFShapesGraph FromRDFGraph(RDFGraph graph)
        {
            if (graph != null)
            {
                RDFShapesGraph       result       = new RDFShapesGraph(new RDFResource(graph.Context.ToString()));
                RDFSelectQueryResult shapesResult = GetShapeQuery().ApplyToGraph(graph);
                foreach (DataRow shapesRow in shapesResult.SelectResults.AsEnumerable())
                {
                    RDFShape shape = ParseShapeType(shapesRow);
                    if (shape == null)
                    {
                        continue;
                    }

                    //Targets
                    ParseShapeTargets(shapesRow, shape);

                    //Attributes
                    ParseShapeAttributes(shapesRow, shape);

                    //Constraints
                    ParseShapeConstraints(shapesRow, graph, shape);

                    //Merge
                    MergeShape(result, shape);
                }
                return(result);
            }
            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// Gets a graph representation of this constraint
        /// </summary>
        internal override RDFGraph ToRDFGraph(RDFShape shape)
        {
            RDFGraph result = new RDFGraph();

            if (shape != null)
            {
                //Get collection from inValues
                RDFCollection inValues = new RDFCollection(this.ItemType)
                {
                    InternalReificationSubject = this
                };
                foreach (RDFPatternMember inValue in this.InValues.Values)
                {
                    if (this.ItemType == RDFModelEnums.RDFItemTypes.Literal)
                    {
                        inValues.AddItem((RDFLiteral)inValue);
                    }
                    else
                    {
                        inValues.AddItem((RDFResource)inValue);
                    }
                }
                result.AddCollection(inValues);

                //sh:in
                result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.IN, inValues.ReificationSubject));
            }
            return(result);
        }
        /// <summary>
        /// Gets a graph representation of this constraint
        /// </summary>
        internal override RDFGraph ToRDFGraph(RDFShape shape)
        {
            RDFGraph result = new RDFGraph();

            if (shape != null)
            {
                //sh:closed
                result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.CLOSED, new RDFTypedLiteral(this.Closed.ToString(), RDFModelEnums.RDFDatatypes.XSD_BOOLEAN)));

                //Get collection from ignored properties
                RDFCollection ignoredProperties = new RDFCollection(RDFModelEnums.RDFItemTypes.Resource)
                {
                    InternalReificationSubject = this
                };
                foreach (RDFResource ignoredProperty in this.IgnoredProperties.Values)
                {
                    ignoredProperties.AddItem(ignoredProperty);
                }
                result.AddCollection(ignoredProperties);

                //sh:ignoredProperties
                result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.IGNORED_PROPERTIES, ignoredProperties.ReificationSubject));
            }
            return(result);
        }
        /// <summary>
        /// Gets a graph representation of this constraint
        /// </summary>
        internal override RDFGraph ToRDFGraph(RDFShape shape)
        {
            RDFGraph result = new RDFGraph();

            if (shape != null)
            {
                //sh:pattern
                result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.PATTERN, new RDFTypedLiteral(this.RegEx.ToString(), RDFModelEnums.RDFDatatypes.XSD_STRING)));

                //sh:flags
                StringBuilder regexFlags = new StringBuilder();
                if (this.RegEx.Options.HasFlag(RegexOptions.IgnoreCase))
                {
                    regexFlags.Append("i");
                }
                if (this.RegEx.Options.HasFlag(RegexOptions.Singleline))
                {
                    regexFlags.Append("s");
                }
                if (this.RegEx.Options.HasFlag(RegexOptions.Multiline))
                {
                    regexFlags.Append("m");
                }
                if (this.RegEx.Options.HasFlag(RegexOptions.IgnorePatternWhitespace))
                {
                    regexFlags.Append("x");
                }
                if (regexFlags.ToString() != string.Empty)
                {
                    result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.FLAGS, new RDFTypedLiteral(regexFlags.ToString(), RDFModelEnums.RDFDatatypes.XSD_STRING)));
                }
            }
            return(result);
        }
Beispiel #7
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>
        /// Gets a graph representation of this constraint
        /// </summary>
        internal override RDFGraph ToRDFGraph(RDFShape shape)
        {
            RDFGraph result = new RDFGraph();

            if (shape != null)
            {
                //sh:disjoint
                result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.DISJOINT, this.DisjointPredicate));
            }
            return(result);
        }
Beispiel #9
0
        /// <summary>
        /// Gets a graph representation of this constraint
        /// </summary>
        internal override RDFGraph ToRDFGraph(RDFShape shape)
        {
            RDFGraph result = new RDFGraph();

            if (shape != null)
            {
                //sh:equals
                result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.EQUALS, this.EqualsPredicate));
            }
            return(result);
        }
Beispiel #10
0
        /// <summary>
        /// Gets a graph representation of this constraint
        /// </summary>
        internal override RDFGraph ToRDFGraph(RDFShape shape)
        {
            RDFGraph result = new RDFGraph();

            if (shape != null)
            {
                //sh:uniqueLang
                result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.UNIQUE_LANG, this.UniqueLang ? RDFTypedLiteral.True : RDFTypedLiteral.False));
            }
            return(result);
        }
Beispiel #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 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>
        /// Gets a graph representation of this constraint
        /// </summary>
        internal override RDFGraph ToRDFGraph(RDFShape shape)
        {
            RDFGraph result = new RDFGraph();

            if (shape != null)
            {
                //sh:datatype
                result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.DATATYPE, new RDFResource(RDFModelUtilities.GetDatatypeFromEnum(this.Datatype))));
            }
            return(result);
        }
Beispiel #13
0
        /// <summary>
        /// Gets a graph representation of this constraint
        /// </summary>
        internal override RDFGraph ToRDFGraph(RDFShape shape)
        {
            RDFGraph result = new RDFGraph();

            if (shape != null)
            {
                //sh:uniqueLang
                result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.UNIQUE_LANG, new RDFTypedLiteral(this.UniqueLang.ToString(), RDFModelEnums.RDFDatatypes.XSD_BOOLEAN)));
            }
            return(result);
        }
        /// <summary>
        /// Gets a graph representation of this constraint
        /// </summary>
        internal override RDFGraph ToRDFGraph(RDFShape shape)
        {
            RDFGraph result = new RDFGraph();

            if (shape != null)
            {
                //sh:property
                result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.PROPERTY, this.PropertyShapeUri));
            }
            return(result);
        }
Beispiel #15
0
        /// <summary>
        /// Gets a graph representation of this constraint
        /// </summary>
        internal override RDFGraph ToRDFGraph(RDFShape shape)
        {
            RDFGraph result = new RDFGraph();

            if (shape != null)
            {
                //sh:maxCount
                result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.MAX_COUNT, new RDFTypedLiteral(this.MaxCount.ToString(), RDFModelEnums.RDFDatatypes.XSD_INTEGER)));
            }
            return(result);
        }
Beispiel #16
0
        /// <summary>
        /// Gets a graph representation of this constraint
        /// </summary>
        internal override RDFGraph ToRDFGraph(RDFShape shape)
        {
            RDFGraph result = new RDFGraph();

            if (shape != null)
            {
                //sh:lessThan
                result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.LESS_THAN, this.LessThanPredicate));
            }
            return(result);
        }
Beispiel #17
0
        /// <summary>
        /// Gets a graph representation of this constraint
        /// </summary>
        internal override RDFGraph ToRDFGraph(RDFShape shape)
        {
            RDFGraph result = new RDFGraph();

            if (shape != null)
            {
                //sh:class
                result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.CLASS, this.ClassType));
            }
            return(result);
        }
Beispiel #18
0
        /// <summary>
        /// Gets a graph representation of this constraint
        /// </summary>
        internal override RDFGraph ToRDFGraph(RDFShape shape)
        {
            RDFGraph result = new RDFGraph();

            if (shape != null)
            {
                //sh:node
                result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.NODE, this.NodeShapeUri));
            }
            return(result);
        }
        /// <summary>
        /// Gets a graph representation of this constraint
        /// </summary>
        internal override RDFGraph ToRDFGraph(RDFShape shape)
        {
            RDFGraph result = new RDFGraph();
            if (shape != null) {

                //sh:hasValue
                if (this.Value is RDFResource)
                    result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.HAS_VALUE, (RDFResource)this.Value));
                else
                    result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.HAS_VALUE, (RDFLiteral)this.Value));

            }
            return result;
        }
Beispiel #20
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 and shapes
            List <RDFShape> andShapes = new List <RDFShape>();

            foreach (RDFResource andShapeUri in this.AndShapes.Values)
            {
                RDFShape andShape = shapesGraph.SelectShape(andShapeUri.ToString());
                if (andShape != null)
                {
                    andShapes.Add(andShape);
                }
            }

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

                if (!valueNodeConforms)
                {
                    report.AddResult(new RDFValidationResult(shape,
                                                             RDFVocabulary.SHACL.AND_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();

            //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)
            {
                int 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);
        }
Beispiel #22
0
        /// <summary>
        /// Gets a graph representation of this constraint
        /// </summary>
        internal override RDFGraph ToRDFGraph(RDFShape shape)
        {
            RDFGraph result = new RDFGraph();

            if (shape != null)
            {
                //sh:maxExclusive
                if (this.Value is RDFResource)
                {
                    result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.MAX_EXCLUSIVE, (RDFResource)this.Value));
                }
                else
                {
                    result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.MAX_EXCLUSIVE, (RDFLiteral)this.Value));
                }
            }
            return(result);
        }
        /// <summary>
        /// Gets a graph representation of this constraint
        /// </summary>
        internal override RDFGraph ToRDFGraph(RDFShape shape)
        {
            RDFGraph result = new RDFGraph();

            if (shape != null)
            {
                //Get collection from language tags
                RDFCollection languageTags = new RDFCollection(RDFModelEnums.RDFItemTypes.Literal)
                {
                    InternalReificationSubject = this
                };
                foreach (string languageTag in this.LanguageTags)
                {
                    languageTags.AddItem(new RDFPlainLiteral(languageTag));
                }
                result.AddCollection(languageTags);

                //sh:languageIn
                result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.LANGUAGE_IN, languageTags.ReificationSubject));
            }
            return(result);
        }
        /// <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);
            }
        }
        /// <summary>
        /// Gets a graph representation of this constraint
        /// </summary>
        internal override RDFGraph ToRDFGraph(RDFShape shape)
        {
            RDFGraph result = new RDFGraph();

            if (shape != null)
            {
                //Get collection from xoneShapes
                RDFCollection xoneShapes = new RDFCollection(RDFModelEnums.RDFItemTypes.Resource)
                {
                    InternalReificationSubject = this
                };
                foreach (RDFResource xoneShape in this.XoneShapes.Values)
                {
                    xoneShapes.AddItem(xoneShape);
                }
                result.AddCollection(xoneShapes);

                //sh:xone
                result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.XONE, xoneShapes.ReificationSubject));
            }
            return(result);
        }
Beispiel #26
0
        private static void MergeShape(RDFShapesGraph result, RDFShape shape)
        {
            RDFShape existingShape = result.SelectShape(shape.ToString());

            if (existingShape == null)
            {
                result.AddShape(shape);
            }
            else
            {
                existingShape.Targets.AddRange(shape.Targets);
                existingShape.Constraints.AddRange(shape.Constraints);
                existingShape.Messages.AddRange(shape.Messages);
                if (existingShape is RDFPropertyShape && shape is RDFPropertyShape)
                {
                    ((RDFPropertyShape)existingShape).Descriptions.AddRange(((RDFPropertyShape)shape).Descriptions);
                    ((RDFPropertyShape)existingShape).Names.AddRange(((RDFPropertyShape)shape).Names);
                }
                result.RemoveShape(existingShape);
                result.AddShape(existingShape);
            }
        }
Beispiel #27
0
        /// <summary>
        /// Gets a graph representation of this constraint
        /// </summary>
        internal override RDFGraph ToRDFGraph(RDFShape shape)
        {
            RDFGraph result = new RDFGraph();

            if (shape != null)
            {
                //sh:qualifiedValueShape
                result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.QUALIFIED_VALUE_SHAPE, this.QualifiedValueShapeUri));

                //sh:qualifiedMinCount
                if (this.QualifiedValueMinCount.HasValue)
                {
                    result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.QUALIFIED_MIN_COUNT, new RDFTypedLiteral(this.QualifiedValueMinCount.ToString(), RDFModelEnums.RDFDatatypes.XSD_INTEGER)));
                }

                //sh:qualifiedMaxCount
                if (this.QualifiedValueMaxCount.HasValue)
                {
                    result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.QUALIFIED_MAX_COUNT, new RDFTypedLiteral(this.QualifiedValueMaxCount.ToString(), RDFModelEnums.RDFDatatypes.XSD_INTEGER)));
                }
            }
            return(result);
        }
Beispiel #28
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);
                }
            }
        }
        /// <summary>
        /// Detects the targets of the given shape
        /// </summary>
        private static void DetectShapeTargets(RDFGraph graph, RDFShape shape)
        {
            RDFGraph shapeDefinition = graph.SelectTriplesBySubject(shape);

            //sh:TargetClass (accepted occurrences: N)
            RDFGraph targetClasses = shapeDefinition.SelectTriplesByPredicate(RDFVocabulary.SHACL.TARGET_CLASS);

            foreach (RDFTriple targetClass in targetClasses.Where(t => t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPO))
            {
                shape.AddTarget(new RDFTargetClass((RDFResource)targetClass.Object));
            }

            //sh:TargetNode (accepted occurrences: N)
            RDFGraph targetNodes = shapeDefinition.SelectTriplesByPredicate(RDFVocabulary.SHACL.TARGET_NODE);

            foreach (RDFTriple targetNode in targetNodes.Where(t => t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPO))
            {
                shape.AddTarget(new RDFTargetNode((RDFResource)targetNode.Object));
            }

            //sh:TargetSubjectsOf (accepted occurrences: N)
            RDFGraph targetSubjectsOf = shapeDefinition.SelectTriplesByPredicate(RDFVocabulary.SHACL.TARGET_SUBJECTS_OF);

            foreach (RDFTriple targetSubjectOf in targetSubjectsOf.Where(t => t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPO))
            {
                shape.AddTarget(new RDFTargetSubjectsOf((RDFResource)targetSubjectOf.Object));
            }

            //sh:TargetObjectsOf (accepted occurrences: N)
            RDFGraph targetObjectsOf = shapeDefinition.SelectTriplesByPredicate(RDFVocabulary.SHACL.TARGET_OBJECTS_OF);

            foreach (RDFTriple targetObjectOf in targetObjectsOf.Where(t => t.TripleFlavor == RDFModelEnums.RDFTripleFlavors.SPO))
            {
                shape.AddTarget(new RDFTargetObjectsOf((RDFResource)targetObjectOf.Object));
            }
        }
Beispiel #30
0
        /// <summary>
        /// Gets a graph representation of this constraint
        /// </summary>
        internal override RDFGraph ToRDFGraph(RDFShape shape)
        {
            RDFGraph result = new RDFGraph();

            if (shape != null)
            {
                //sh:nodeKind
                switch (this.NodeKind)
                {
                case RDFValidationEnums.RDFNodeKinds.BlankNode:
                    result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.NODE_KIND, RDFVocabulary.SHACL.BLANK_NODE));
                    break;

                case RDFValidationEnums.RDFNodeKinds.BlankNodeOrIRI:
                    result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.NODE_KIND, RDFVocabulary.SHACL.BLANK_NODE_OR_IRI));
                    break;

                case RDFValidationEnums.RDFNodeKinds.BlankNodeOrLiteral:
                    result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.NODE_KIND, RDFVocabulary.SHACL.BLANK_NODE_OR_LITERAL));
                    break;

                case RDFValidationEnums.RDFNodeKinds.IRI:
                    result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.NODE_KIND, RDFVocabulary.SHACL.IRI));
                    break;

                case RDFValidationEnums.RDFNodeKinds.IRIOrLiteral:
                    result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.NODE_KIND, RDFVocabulary.SHACL.IRI_OR_LITERAL));
                    break;

                case RDFValidationEnums.RDFNodeKinds.Literal:
                    result.AddTriple(new RDFTriple(shape, RDFVocabulary.SHACL.NODE_KIND, RDFVocabulary.SHACL.LITERAL));
                    break;
                }
            }
            return(result);
        }