Skip to content
Snippets Groups Projects

Resolve "Implement function to validate data against a scheme"

Merged mbrodhu requested to merge 7-implement-function-to-validate-data-against-a-scheme into main
4 files
+ 207
105
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 58
0
package org.subGoettingen.dev;
import org.apache.jena.graph.Graph;
import org.apache.jena.riot.Lang;
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.shacl.ShaclValidator;
import org.apache.jena.shacl.Shapes;
import org.apache.jena.shacl.ValidationReport;
import org.apache.jena.shacl.lib.ShLib;
/*******************************************************************************
* This software is copyright (c) 2021 by
*
* State and University Library Goettingen
*
* This is free software. You can redistribute it and/or modify it under the terms described in the
* GNU Lesser General Public License v3 of which you should have received a copy. Otherwise you can
* download it from
*
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* @copyright State and University Library Goettingen
* @license GNU Lesser General Public License v3 (http://www.gnu.org/licenses/lgpl-3.0.txt)
* @author Maximilian Behnert-Brodhun (behnert-brodhun@sub.uni-goettingen.de)
******************************************************************************/
/**
* Class to collect all SHACL specific functions
*
* @author Maximilian Behnert-Brodhun SUB Goettingen
* @version 1.0.0
*
*/
public class SHACL {
/**
* Takes a schema file and data file and checks if the data file is valid against the provided schema
*
* @param shapesGraph contains the schema file
* @param dataGraph contains the data file
*
* @return boolean if the data file is valid against the provided schema
*/
public boolean validateDataAgainstGraph(Graph shapesGraph, Graph dataGraph) {
Shapes shapes = Shapes.parse(shapesGraph);
ShaclValidator.get().parse(dataGraph);
ValidationReport report = ShaclValidator.get().validate(shapes, dataGraph);
//ShLib.printReport(report);
//System.out.println();
//RDFDataMgr.write(System.out, report.getModel(), Lang.TTL);
return report.conforms();
}
}
Loading