CodeFerret

ShaclName_validateGraphJS.java

May 29th, 2020
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.29 KB | None | 0 0
  1. import org.apache.jena.graph.Graph;
  2. import org.apache.jena.rdf.model.Literal;
  3. import org.apache.jena.rdf.model.Model;
  4. import org.apache.jena.rdf.model.ModelFactory;
  5. import org.apache.jena.rdf.model.Property;
  6. import org.apache.jena.rdf.model.RDFNode;
  7. import org.apache.jena.rdf.model.Resource;
  8. import org.apache.jena.rdf.model.ResourceFactory;
  9. import org.apache.jena.rdf.model.Statement;
  10. import org.apache.jena.rdf.model.StmtIterator;
  11. import org.apache.jena.riot.Lang;
  12. import org.apache.jena.riot.RDFDataMgr;
  13. import org.apache.jena.shacl.ShaclValidator;
  14. import org.apache.jena.shacl.Shapes;
  15. import org.apache.jena.shacl.ValidationReport;
  16. import org.apache.jena.shacl.validation.ShaclSimpleValidator;
  17. import org.slf4j.Logger;
  18. import org.slf4j.LoggerFactory;
  19. import org.topbraid.shacl.validation.ValidationEngineConfiguration;
  20. import org.topbraid.shacl.validation.ValidationUtil;
  21.  
  22. public class ShaclName_validateGraphJS {
  23.    
  24.     public static Logger logger = LoggerFactory.getLogger(ShaclName_validateGraphJS.class);
  25.    
  26.     static final String BDR = "http://purl.bdrc.io/resource/";
  27.     static final String SHAPES = "ShapeName_01.ttl";
  28.     static final String DATA = "DATA_P707.ttl";
  29.    
  30.     static ShaclValidator sv;
  31.     static Graph dataGraph;
  32.     static Graph shapesGraph;
  33.     static Shapes shapes;
  34.    
  35.     static void initSV() {
  36.         sv = new ShaclSimpleValidator();
  37.     }
  38.  
  39.     static {
  40.         dataGraph = RDFDataMgr.loadGraph(DATA);
  41.         shapesGraph = RDFDataMgr.loadGraph(SHAPES);
  42.         shapes = Shapes.parse(shapesGraph);
  43.         initSV();
  44.     }
  45.    
  46.     static void process(Resource focus) {
  47.         logger.info("Validating Node {} with {}", focus.getLocalName(), SHAPES);
  48.         ValidationReport report = sv.validate(shapes, dataGraph, focus.asNode());
  49.         RDFDataMgr.write(System.out, report.getModel(), Lang.TTL);
  50.     }
  51.    
  52.     public static void main(String ...args) {
  53.         process(ResourceFactory.createResource(BDR+"P707"));
  54.         initSV();
  55.         process(ResourceFactory.createResource(BDR+"NMC2A097019ABA499F"));
  56.         initSV();
  57.         process(ResourceFactory.createResource(BDR+"NM0895CB6787E8AC6E"));
  58.         initSV();
  59.         process(ResourceFactory.createResource(BDR+"NM2463D933BA1F9A38"));
  60.         initSV();
  61.         process(ResourceFactory.createResource(BDR+"NMEA2B380AF0BBFB1B"));        
  62.     }
  63. }
Add Comment
Please, Sign In to add comment