コード例 #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"))));
            }
        }
コード例 #2
0
        /// <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));
            }
        }