package org.eclipse.rdf4j;

import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.repository.sail.SailRepository;
import org.eclipse.rdf4j.repository.sail.SailRepositoryConnection;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.sail.memory.MemoryStore;
import org.eclipse.rdf4j.validation.SHACLSail;
import org.eclipse.rdf4j.validation.SHACLSailConnection;
import org.eclipse.rdf4j.validation.ShaclViolationListener;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * Created by heshanjayasinghe on 4/30/17.
 */
public class Main {

    public static final String SH = "http://www.w3.org/ns/shacl#";

    public static void main(String[] args) {

        SailRepository shaclRules = new SailRepository(new MemoryStore());

        shaclRules.initialize();
        ValueFactory vf = shaclRules.getValueFactory();

        try (SailRepositoryConnection connection = shaclRules.getConnection()) {
            connection.begin();
            connection.add(new FileInputStream("shacl.ttl"), "", RDFFormat.TURTLE);
            connection.commit();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        SHACLSail shaclSail = new SHACLSail();

        shaclSail.setShaclRules(shaclRules);

        SHACLSailConnection connection = (SHACLSailConnection) shaclSail.getConnection();

        connection.addShaclViolationListener(new ShaclViolationListener() {
            @Override
            public void violation(String errror) {
                System.out.println(errror);
            }
        });

        connection.begin();

        connection.commit();

    }
}

@@ -52,28 +52,79 @@
 j.model.
-ValueFactory
+Statement;%0Aimport org.eclipse.rdf4j.repository.RepositoryResult
 ;%0Aimport
@@ -382,125 +382,36 @@
 il;%0A
+%0A
 import 
-org.eclipse.rdf4j.validation.SHACLSailConnection;%0Aimport org.eclipse.rdf4j.validation.ShaclViolationListener;%0A
+java.io.IOException;
 %0Aimp
@@ -422,20 +422,16 @@
 java.io.
-File
 InputStr
@@ -438,74 +438,8 @@
 eam;
-%0Aimport java.io.FileNotFoundException;%0Aimport java.io.IOException;
 %0A%0A/*
@@ -618,24 +618,25 @@
 %5B%5D args) %7B%0A%0A
+%0A
         Sail
@@ -651,21 +651,20 @@
 ry shacl
-Rules
+Sail
  = new S
@@ -681,16 +681,30 @@
 ory(new 
+SHACLSail(new 
 MemorySt
@@ -709,18 +709,18 @@
 Store())
+)
 ;
-%0A
 %0A       
@@ -725,21 +725,20 @@
    shacl
-Rules
+Sail
 .initial
@@ -747,64 +747,8 @@
 e();
-%0A        ValueFactory vf = shaclRules.getValueFactory();
 %0A%0A  
@@ -791,22 +791,16 @@
 conn
-ection
  = shacl
 Rule
@@ -795,21 +795,20 @@
  = shacl
-Rules
+Sail
 .getConn
@@ -835,219 +835,266 @@
     
-connection.begin();%0A            connection.add(new FileInputStream(%22shacl.ttl%22), %22%22, RDFFormat.TURTLE);%0A            connection.commit();%0A        %7D catch (FileNotFoundException e) %7B%0A            e.printStackTrace(
+String filename = %22shacl.ttl%22;%0A            try (InputStream input = SHACLSail.class.getResourceAsStream(%22/%22 + filename)) %7B%0A                // add the RDF data from the inputstream directly to our database%0A                conn.add(input, %22%22, RDFFormat.TURTLE 
 );%0A 
@@ -1100,16 +1100,20 @@
         
+    
 %7D catch 
@@ -1126,24 +1126,28 @@
 eption e) %7B%0A
+    
             
@@ -1175,16 +1175,20 @@
         
+    
 %7D%0A%0A     
@@ -1194,462 +1194,422 @@
     
-SHACLSail shaclSail = new SHACLSail();%0A%0A        shaclSail.setShaclRules(shaclRules);%0A%0A        SHACLSailConnection connection = (SHACLSailConnection) shaclSail.getConnection();%0A%0A        connection.addShaclViolationListener(new ShaclViolationListener() %7B%0A            @Override%0A            public void violation(String errror) %7B%0A                System.out.println(errror);%0A            %7D%0A        %7D);%0A%0A        connection.begin();%0A%0A        connection.commit();
+    // let's check that our data is actually in the database%0A            try (RepositoryResult%3CStatement%3E result = conn.getStatements(null, null, null)) %7B%0A                while (result.hasNext()) %7B%0A                    Statement st = result.next();%0A                    System.out.println(%22db contains: %22 + st);%0A                %7D%0A            %7D%0A        %7D%0A        finally %7B%0A            shaclSail.shutDown();%0A        %7D%0A
 %0A%0A  

print current statements using main class