예제 #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 void TestEquivalenceDiscover()
        {
            //Cargamos el RDF sobre el que aplicar el reconocimiento de enlaces
            RohGraph dataGraph = new RohGraph();

            dataGraph.LoadFromString(System.IO.File.ReadAllText("rdfFiles/rdfFile.rdf"), new RdfXmlParser());

            //TODO cargar ejemplo
            //Cargamos el RDF que simula la BBDD de Unidata
            //Si se quiere ejecutar sobre la BBDD no habría que modificar discoverUtility.mSparqlUtility y sería necesario especificar los datos del SPARQL endpoint
            RohGraph dataGraphBBDD = new RohGraph();

            dataGraphBBDD.LoadFromString(System.IO.File.ReadAllText("rdfFiles/rdfFile.rdf"), new RdfXmlParser());

            //Cargamos el RDF de la ontología
            RohGraph ontologyGraph = new RohGraph();

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

            //Cargamos configuraciones necesarias
            ConfigService ConfigService = new ConfigService();
            float         maxScore      = ConfigService.GetMaxScore();
            float         minScore      = ConfigService.GetMinScore();
            string        unidataDomain = ConfigService.GetUnidataDomain();

            DiscoverUtility discoverUtility = new DiscoverUtility();

            discoverUtility.mSparqlUtility = new SparqlUtilityMock(dataGraphBBDD);
            discoverUtility.test           = true;

            //Aplicamos el descubrimiento de equivalencias
            //Los datos de configuración de SPARQL se mandan vacíos porque utilizamos el MOCK
            discoverUtility.ApplyEquivalenceDiscover(ref dataGraph, ontologyGraph, out Dictionary <string, Dictionary <string, float> > reconciliationEntitiesProbability, unidataDomain, minScore, maxScore, "", "", "", "", "");
        }
예제 #3
0
        public void TestReconciliation()
        {
            //Cargamos el RDF sobre el que aplicar la reconciliación
            RohGraph dataGraph = new RohGraph();

            dataGraph.LoadFromString(System.IO.File.ReadAllText("rdfFiles/rdfFileRecon.rdf"), new RdfXmlParser());

            //Cargamos el RDF de la ontología
            RohGraph ontologyGraph = new RohGraph();

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

            //Cargamos el RDF que simula la BBDD
            RohGraph dataGraphBBDD = new RohGraph();

            dataGraph.LoadFromString(System.IO.File.ReadAllText("rdfFiles/rdfFile.rdf"), new RdfXmlParser());

            //Cargamos configuraciones necesarias
            ConfigService ConfigService = new ConfigService();
            float         maxScore      = ConfigService.GetMaxScore();
            float         minScore      = ConfigService.GetMinScore();

            //Construimos el objeto DiscoverUtility
            DiscoverUtility discoverUtility = new DiscoverUtility();

            //Sustituimos mSparqlUtility por un MOCK en el que cargamos el grafo en memoria 'dataGraphBBDD'
            //Si se quiere ejecutar sobre la BBDD no habría que modificar discoverUtility.mSparqlUtility y sería necesario especificar los datos del SPARQL endpoint
            discoverUtility.mSparqlUtility = new SparqlUtilityMock(dataGraphBBDD);
            discoverUtility.test           = true;

            //Aplicamos la reconciliación
            //Los datos de configuración de SPARQL se mandan vacíos porque utilizamos el MOCK
            ReconciliationData reconciliationData = discoverUtility.ApplyReconciliation(ref dataGraph, ontologyGraph, "", "", "", "", "", minScore, maxScore, out Dictionary <string, Dictionary <string, float> > reconciliationEntitiesProbability);

            //En 'reconciliationData' estarán los datos que se han modificado fruto de la reconciliación
            //En 'dataGraph' estará el grafo modificado tras la reconciliación
            //En 'reconciliationEntitiesProbability' estarán las entidades para las que ha habido problemas de desambiguación
        }
예제 #4
0
        public void TestDiscoverLinks()
        {
            //Cargamos el RDF sobre el que aplicar el reconocimiento de enlaces
            RohGraph dataGraph = new RohGraph();

            dataGraph.LoadFromString(System.IO.File.ReadAllText("rdfFiles/rdfFile.rdf"), new RdfXmlParser());

            //Cargamos el RDF de la ontología
            RohGraph ontologyGraph = new RohGraph();

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

            DiscoverUtility discoverUtility = new DiscoverUtility();

            discoverUtility.test = true;

            CallUrisFactoryApiMockService callUrisFactoryApiMockService = new CallUrisFactoryApiMockService();
            //Aplicamos el descubrimiento de enlaces
            Dictionary <string, List <DiscoverLinkData.PropertyData> > discoverLinks = discoverUtility.ApplyDiscoverLinks(ref dataGraph, ontologyGraph, 0.7f, 0.9f, "", "", "HerculesASIO-University-of-Murcia (https://github.com/HerculesCRUE/GnossDeustoBackend; mailto:<mail>) AsioBot", "Basic czAzNjkuZmVjeXQuZXM6VTQ5RDhSWU40d3Mh", callUrisFactoryApiMockService);

            //En 'discoverLinks' estarán los datos que se han recuperado de las integraciones externas junto con su provenance
            //En 'dataGraph' estará el grafo modificado tras el descubrimiento de enlaces
        }