/// <summary> /// Detects the inline instances of shacl:PropertyShape and populates the shapes graph with their definition /// </summary> private static void DetectInlinePropertyShapes(RDFGraph graph, RDFShapesGraph shapesGraph) { RDFGraph inlinePropertyShapes = graph.SelectTriplesByPredicate(RDFVocabulary.SHACL.PROPERTY); foreach (RDFTriple inlinePropertyShape in inlinePropertyShapes) { //Inline property shapes are blank objects of "sh:property" constraints: //we wont find their explicit shape definition within the shapes graph. if (inlinePropertyShape.Object is RDFResource inlinePropertyShapeResource && inlinePropertyShapeResource.IsBlank && shapesGraph.SelectShape(inlinePropertyShapeResource.ToString()) == null) { RDFTriple inlinePropertyShapePath = graph.SelectTriplesBySubject(inlinePropertyShapeResource) .SelectTriplesByPredicate(RDFVocabulary.SHACL.PATH) .FirstOrDefault(); if (inlinePropertyShapePath != null && inlinePropertyShapePath.Object is RDFResource) { RDFPropertyShape propertyShape = new RDFPropertyShape(inlinePropertyShapeResource, (RDFResource)inlinePropertyShapePath.Object); DetectShapeTargets(graph, propertyShape); DetectShapeAttributes(graph, propertyShape); DetectShapeNonValidatingAttributes(graph, propertyShape); DetectShapeConstraints(graph, propertyShape); shapesGraph.AddShape(propertyShape); } } } }
/// <summary> /// Detects the typed instances of shacl:PropertyShape and populates the shapes graph with their definition /// </summary> private static void DetectTypedPropertyShapes(RDFGraph graph, RDFShapesGraph shapesGraph) { RDFGraph declaredPropertyShapes = graph.SelectTriplesByPredicate(RDFVocabulary.RDF.TYPE) .SelectTriplesByObject(RDFVocabulary.SHACL.PROPERTY_SHAPE); foreach (RDFTriple declaredPropertyShape in declaredPropertyShapes) { RDFTriple declaredPropertyShapePath = graph.SelectTriplesBySubject((RDFResource)declaredPropertyShape.Subject) .SelectTriplesByPredicate(RDFVocabulary.SHACL.PATH) .FirstOrDefault(); if (declaredPropertyShapePath != null && declaredPropertyShapePath.Object is RDFResource) { RDFPropertyShape propertyShape = new RDFPropertyShape((RDFResource)declaredPropertyShape.Subject, (RDFResource)declaredPropertyShapePath.Object); DetectShapeTargets(graph, propertyShape); DetectShapeAttributes(graph, propertyShape); DetectShapeNonValidatingAttributes(graph, propertyShape); DetectShapeConstraints(graph, propertyShape); shapesGraph.AddShape(propertyShape); } } }
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); } }
/// <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); } }