Пример #1
0
        /// <summary>
        /// Valida un RDF
        /// </summary>
        /// <param name="pRdfFileContent">XML RDF</param>
        /// <param name="pShapesConfig">Lista de Shapes de validación</param>
        /// <returns>Lista de triples</returns>
        public static ShapeReport ValidateRDF(string pRdfFileContent, List <ShapeConfig> pShapesConfig)
        {
            //Cargamos la ontología
            RohGraph ontologyGraph = new RohGraph();

            ontologyGraph.LoadFromFile("Config/Ontology/roh-v2.owl");

            //Cargamos datos a validar
            RohGraph dataGraph = new RohGraph();

            dataGraph.LoadFromString(pRdfFileContent, new RdfXmlParser());

            //Aplicamos inferencias de la ontologia
            RohRdfsReasoner reasoner = new RohRdfsReasoner();

            reasoner.Initialise(ontologyGraph);
            reasoner.Apply(dataGraph);

            ShapeReport response = new ShapeReport();

            response.conforms = true;
            response.results  = new List <ShapeReport.Result>();
            foreach (ShapeConfig shape in pShapesConfig)
            {
                IGraph shapeGraph = new Graph();
                shapeGraph.LoadFromString(shape.Shape);
                ShapesGraph shapesGraph = new ShapesGraph(shapeGraph);

                Report report = shapesGraph.Validate(dataGraph);
                if (!report.Conforms)
                {
                    response.conforms = false;
                    response.results.AddRange(report.Results.ToList().Select(x => new ShapeReport.Result()
                    {
                        severity    = (x.Severity != null) ? x.Severity.ToString() : null,
                        focusNode   = (x.FocusNode != null) ? x.FocusNode.ToString() : null,
                        resultValue = (x.ResultValue != null) ? x.ResultValue.ToString() : null,
                        message     = (x.Message != null) ? x.Message.ToString() : null,
                        resultPath  = (x.ResultPath != null) ? x.ResultPath.ToString() : null,
                        shapeID     = shape.ShapeConfigID,
                        shapeName   = shape.Name,
                        sourceShape = (x.SourceShape != null) ? x.SourceShape.ToString() : null,
                    }).ToList());
                }
            }

            if (response.results.Exists(x => x.severity == "http://www.w3.org/ns/shacl#Violation"))
            {
                response.severity = "http://www.w3.org/ns/shacl#Violation";
            }
            else if (response.results.Exists(x => x.severity == "http://www.w3.org/ns/shacl#Warning"))
            {
                response.severity = "http://www.w3.org/ns/shacl#Warning";
            }
            else if (response.results.Exists(x => x.severity == "http://www.w3.org/ns/shacl#Info"))
            {
                response.severity = "http://www.w3.org/ns/shacl#Info";
            }
            return(response);
        }
Пример #2
0
        public async Task <ValidationResult> ValidateEntity(Entity entity, IList <MetadataProperty> metadataProperties)
        {
            var resourceGraph = GetResourceGraph(entity, metadataProperties);
            var shapesGraph   = GetShapesGraph();

            var processor = new ShapesGraph(shapesGraph);
            var report    = processor.Validate(resourceGraph);

            var validationResult = CreateValidationResult(report);

            return(await Task.FromResult(validationResult));
        }
Пример #3
0
        private IActionResult Validate(IGraph data, IGraph shapes, Parameters parameters)
        {
            var report = new ShapesGraph(shapes).Validate(data).Normalised;

            switch (this.GetResponseContentType(parameters.Format))
            {
            case "text/html":
                return(this.View((parameters, Report.Parse(report))));

            default:
                return(this.Ok(report));
            }
        }
Пример #4
0
        private IActionResult Conforms(IGraph data, IGraph shapes, Parameters parameters)
        {
            var conforms = new ShapesGraph(shapes).Conforms(data);

            switch (this.GetResponseContentType(parameters.Format))
            {
            case "text/html":
                return(this.View((parameters, (bool?)conforms)));

            default:
                return(this.Ok(conforms));
            }
        }
Пример #5
0
        /// <summary>
        /// has side effects! updates triplestore
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="metadataProperties"></param>
        /// <returns></returns>
        public async Task <ValidationResult> ValidateEntity(Entity entity, IList <MetadataProperty> metadataProperties)
        {
            var resourceGraph = GetResourceGraph(entity, metadataProperties);
            var shapesGraph   = GetShapesGraph();

            var processor = new ShapesGraph(shapesGraph);
            var report    = processor.Validate(resourceGraph);

            var            validationResult  = CreateValidationResult(report);
            NTriplesWriter rdfNTriplesWriter = new NTriplesWriter();

            validationResult.Triples = VDS.RDF.Writing.StringWriter.Write(resourceGraph, rdfNTriplesWriter);
            return(await Task.FromResult(validationResult));
        }